增加英文垃圾支持

0515
panqihua 5 years ago
parent 43b5ed5358
commit 991bc1f6a7
  1. 18
      app/src/main/java/com/community/pocket/data/adapter/GarbageSortingAdpter.java
  2. 10
      app/src/main/java/com/community/pocket/data/model/GarbageSorting.java
  3. 13
      app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java

@ -4,6 +4,8 @@ import android.content.Context;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import com.community.pocket.data.model.GarbageSorting; import com.community.pocket.data.model.GarbageSorting;
import com.community.pocket.util.LocaleType;
import com.community.pocket.util.SPUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -15,7 +17,6 @@ import java.util.Map;
*/ */
public class GarbageSortingAdpter extends ArrayAdapter<String> { public class GarbageSortingAdpter extends ArrayAdapter<String> {
private List<GarbageSorting> dataList;
private List<String> list = new ArrayList<>(); private List<String> list = new ArrayList<>();
private Map<String, GarbageSorting> map = new HashMap<>(); private Map<String, GarbageSorting> map = new HashMap<>();
@ -26,12 +27,21 @@ public class GarbageSortingAdpter extends ArrayAdapter<String> {
} }
public void addAll(List<GarbageSorting> dataList) { public void addAll(List<GarbageSorting> dataList) {
this.dataList = dataList;
this.list.clear(); this.list.clear();
this.map.clear(); this.map.clear();
for (GarbageSorting garbageSorting : dataList) { for (GarbageSorting garbageSorting : dataList) {
this.list.add(garbageSorting.getName()); String name;
this.map.put(garbageSorting.getName(), garbageSorting); if (SPUtil.getInstance(getContext()).getSelectLanguage() == LocaleType.en.getType()) {
name = garbageSorting.getEnglishName();
if (name == null) {
name = garbageSorting.getName() + "(no english name)";
}
} else {
name = garbageSorting.getName();
}
this.map.put(name, garbageSorting);
this.list.add(name);
} }
clear(); clear();
addAll(this.list); addAll(this.list);

@ -6,6 +6,8 @@ public class GarbageSorting {
private String name; private String name;
//分类 //分类
private Integer category; private Integer category;
//垃圾英文名
private String englishName;
//垃圾图片 //垃圾图片
private String image; private String image;
@ -32,4 +34,12 @@ public class GarbageSorting {
public void setImage(String image) { public void setImage(String image) {
this.image = image; this.image = image;
} }
public String getEnglishName() {
return englishName;
}
public void setEnglishName(String englishName) {
this.englishName = englishName;
}
} }

@ -19,6 +19,8 @@ import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.listener.MyTextChange; import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.main.ui.share.MyAutoCompleteTextView; import com.community.pocket.ui.main.ui.share.MyAutoCompleteTextView;
import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.Response;
import com.community.pocket.util.LocaleType;
import com.community.pocket.util.SPUtil;
import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject; import org.xutils.view.annotation.ViewInject;
@ -92,7 +94,16 @@ public class GarbageSortingFragment extends BaseFragment {
* @param garbageSorting 垃圾分类 * @param garbageSorting 垃圾分类
*/ */
private void initView(GarbageSorting garbageSorting) { private void initView(GarbageSorting garbageSorting) {
name.setText(garbageSorting.getName()); String n;
if (SPUtil.getInstance(getContext()).getSelectLanguage() == LocaleType.en.getType()) {
n = garbageSorting.getEnglishName();
if (n == null) {
n = garbageSorting.getName() + "(no english name)";
}
} else {
n = garbageSorting.getName();
}
name.setText(n);
int resId=R.string.unknow_error; int resId=R.string.unknow_error;
switch (garbageSorting.getCategory()){ switch (garbageSorting.getCategory()){
case 1:resId=R.string.garbage_category_1;break; case 1:resId=R.string.garbage_category_1;break;

Loading…
Cancel
Save