From 991bc1f6a7ce6f76bd191ba776edfd3655af1eff Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Thu, 16 Apr 2020 15:48:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8B=B1=E6=96=87=E5=9E=83?= =?UTF-8?q?=E5=9C=BE=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/adapter/GarbageSortingAdpter.java | 18 ++++++++++++++---- .../pocket/data/model/GarbageSorting.java | 10 ++++++++++ .../sorting/GarbageSortingFragment.java | 13 ++++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/community/pocket/data/adapter/GarbageSortingAdpter.java b/app/src/main/java/com/community/pocket/data/adapter/GarbageSortingAdpter.java index d8af950..eac3954 100644 --- a/app/src/main/java/com/community/pocket/data/adapter/GarbageSortingAdpter.java +++ b/app/src/main/java/com/community/pocket/data/adapter/GarbageSortingAdpter.java @@ -4,6 +4,8 @@ import android.content.Context; import android.widget.ArrayAdapter; 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.HashMap; @@ -15,7 +17,6 @@ import java.util.Map; */ public class GarbageSortingAdpter extends ArrayAdapter { - private List dataList; private List list = new ArrayList<>(); private Map map = new HashMap<>(); @@ -26,12 +27,21 @@ public class GarbageSortingAdpter extends ArrayAdapter { } public void addAll(List dataList) { - this.dataList = dataList; this.list.clear(); this.map.clear(); for (GarbageSorting garbageSorting : dataList) { - this.list.add(garbageSorting.getName()); - this.map.put(garbageSorting.getName(), garbageSorting); + String name; + 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(); addAll(this.list); diff --git a/app/src/main/java/com/community/pocket/data/model/GarbageSorting.java b/app/src/main/java/com/community/pocket/data/model/GarbageSorting.java index fc37034..360cc01 100644 --- a/app/src/main/java/com/community/pocket/data/model/GarbageSorting.java +++ b/app/src/main/java/com/community/pocket/data/model/GarbageSorting.java @@ -6,6 +6,8 @@ public class GarbageSorting { private String name; //分类 private Integer category; + //垃圾英文名 + private String englishName; //垃圾图片 private String image; @@ -32,4 +34,12 @@ public class GarbageSorting { public void setImage(String image) { this.image = image; } + + public String getEnglishName() { + return englishName; + } + + public void setEnglishName(String englishName) { + this.englishName = englishName; + } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java index a7a2b80..7b8996e 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java @@ -19,6 +19,8 @@ import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.listener.MyTextChange; import com.community.pocket.ui.main.ui.share.MyAutoCompleteTextView; 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.ViewInject; @@ -92,7 +94,16 @@ public class GarbageSortingFragment extends BaseFragment { * @param 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; switch (garbageSorting.getCategory()){ case 1:resId=R.string.garbage_category_1;break;