From f836df523b919dfc935060d28e3baca3fa2c0332 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Sun, 5 Apr 2020 06:08:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BA=9F=E5=93=81=E5=9B=9E?= =?UTF-8?q?=E6=94=B6UI=E4=BB=A5=E5=8F=8A=E6=95=B0=E6=8D=AE=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/adapter/ForumSearchAdapter.java | 3 + ...eAdpter.java => GarbageSortingAdpter.java} | 7 +- .../data/adapter/GarbageWasteAdpter.java | 49 +++++ .../pocket/data/adapter/LocaleAdapter.java | 3 + .../pocket/data/adapter/VisitorAdpter.java | 3 + .../main/garbage/GarbageSortingRequest.java | 2 +- .../main/garbage/GarbageWasteRequest.java | 72 +++++++ .../pocket/data/model/GarbageWaste.java | 40 ++++ .../pocket/data/model/GarbageWasteManage.java | 25 +++ .../pocket/data/model/GarbageWastePrice.java | 25 +++ .../pocket/ui/main/TestMainFragment.java | 44 ----- .../ui/main/ui/garbage/GarbageViewModel.java | 19 -- .../main/ui/garbage/GarbageWasteFragment.java | 10 - .../{ => sorting}/GarbageSortingFragment.java | 18 +- .../{ => sorting}/GarbageSortingResponse.java | 2 +- .../GarbageSortingViewModel.java | 2 +- .../garbage/waste/GarbageWasteFragment.java | 182 ++++++++++++++++++ .../garbage/waste/GarbageWasteResponse.java | 7 + .../garbage/waste/GarbageWasteViewModel.java | 42 ++++ .../ui/main/ui/visitor/VisitorMyVisitor.java | 1 - .../main/layout/garbage/layout/garbage.xml | 8 +- .../layout/garbage/layout/garbage_sorting.xml | 79 ++++---- .../layout/garbage/layout/garbage_waste.xml | 63 +++++- .../main/layout/garbage/layout/waste_item.xml | 24 +++ .../main/layout/info/layout/info_fragment.xml | 3 +- .../res/navigation/garbage_navigation.xml | 4 +- app/src/main/res/values-en-rUS/strings.xml | 6 + app/src/main/res/values-zh-rCN/strings.xml | 6 + app/src/main/res/values/strings.xml | 6 + 29 files changed, 624 insertions(+), 131 deletions(-) rename app/src/main/java/com/community/pocket/data/adapter/{GarbageAdpter.java => GarbageSortingAdpter.java} (86%) create mode 100644 app/src/main/java/com/community/pocket/data/adapter/GarbageWasteAdpter.java create mode 100644 app/src/main/java/com/community/pocket/data/main/garbage/GarbageWasteRequest.java create mode 100644 app/src/main/java/com/community/pocket/data/model/GarbageWaste.java create mode 100644 app/src/main/java/com/community/pocket/data/model/GarbageWasteManage.java create mode 100644 app/src/main/java/com/community/pocket/data/model/GarbageWastePrice.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/TestMainFragment.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageViewModel.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageWasteFragment.java rename app/src/main/java/com/community/pocket/ui/main/ui/garbage/{ => sorting}/GarbageSortingFragment.java (84%) rename app/src/main/java/com/community/pocket/ui/main/ui/garbage/{ => sorting}/GarbageSortingResponse.java (79%) rename app/src/main/java/com/community/pocket/ui/main/ui/garbage/{ => sorting}/GarbageSortingViewModel.java (94%) create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteFragment.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteResponse.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteViewModel.java create mode 100644 app/src/main/res/layout/main/layout/garbage/layout/waste_item.xml diff --git a/app/src/main/java/com/community/pocket/data/adapter/ForumSearchAdapter.java b/app/src/main/java/com/community/pocket/data/adapter/ForumSearchAdapter.java index 1078a9e..23cf92f 100644 --- a/app/src/main/java/com/community/pocket/data/adapter/ForumSearchAdapter.java +++ b/app/src/main/java/com/community/pocket/data/adapter/ForumSearchAdapter.java @@ -7,6 +7,9 @@ import androidx.annotation.NonNull; import java.util.List; +/** + * 投诉人适配器 + */ public class ForumSearchAdapter extends ArrayAdapter { private List data; diff --git a/app/src/main/java/com/community/pocket/data/adapter/GarbageAdpter.java b/app/src/main/java/com/community/pocket/data/adapter/GarbageSortingAdpter.java similarity index 86% rename from app/src/main/java/com/community/pocket/data/adapter/GarbageAdpter.java rename to app/src/main/java/com/community/pocket/data/adapter/GarbageSortingAdpter.java index faacc8b..d8af950 100644 --- a/app/src/main/java/com/community/pocket/data/adapter/GarbageAdpter.java +++ b/app/src/main/java/com/community/pocket/data/adapter/GarbageSortingAdpter.java @@ -10,14 +10,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class GarbageAdpter extends ArrayAdapter { +/** + * 垃圾分类数据适配器 + */ +public class GarbageSortingAdpter extends ArrayAdapter { private List dataList; private List list = new ArrayList<>(); private Map map = new HashMap<>(); - public GarbageAdpter(List dataList, Context context) { + public GarbageSortingAdpter(List dataList, Context context) { super(context, android.R.layout.simple_list_item_1); addAll(dataList); } diff --git a/app/src/main/java/com/community/pocket/data/adapter/GarbageWasteAdpter.java b/app/src/main/java/com/community/pocket/data/adapter/GarbageWasteAdpter.java new file mode 100644 index 0000000..7d71a0b --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/adapter/GarbageWasteAdpter.java @@ -0,0 +1,49 @@ +package com.community.pocket.data.adapter; + +import android.content.Context; +import android.widget.ArrayAdapter; + +import com.community.pocket.data.model.GarbageWastePrice; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 废品回收数据适配器 + */ +public class GarbageWasteAdpter extends ArrayAdapter { + private List dataList; + + private List list = new ArrayList<>(); + + private Map map = new HashMap<>(); + + public GarbageWasteAdpter(List dataList, Context context) { + super(context, android.R.layout.simple_list_item_1); + addAll(dataList); + } + + public void addAll(List dataList) { + this.dataList = dataList; + this.list.clear(); + this.map.clear(); + + for (GarbageWastePrice price : dataList) { + this.list.add(price.getName()); + this.map.put(price.getName(), price); + } + + clear(); + addAll(this.list); + } + + public GarbageWastePrice get(String name) { + return this.map.get(name); + } + + public boolean containsKey(String name) { + return this.list.contains(name); + } +} diff --git a/app/src/main/java/com/community/pocket/data/adapter/LocaleAdapter.java b/app/src/main/java/com/community/pocket/data/adapter/LocaleAdapter.java index e167188..4549969 100644 --- a/app/src/main/java/com/community/pocket/data/adapter/LocaleAdapter.java +++ b/app/src/main/java/com/community/pocket/data/adapter/LocaleAdapter.java @@ -14,6 +14,9 @@ import com.community.pocket.util.LocaleType; import org.xutils.view.annotation.ViewInject; import org.xutils.x; +/** + * 切换语言数据适配器 + */ public class LocaleAdapter extends BaseAdapter { private LayoutInflater inflater; diff --git a/app/src/main/java/com/community/pocket/data/adapter/VisitorAdpter.java b/app/src/main/java/com/community/pocket/data/adapter/VisitorAdpter.java index 01f3033..75eb5a1 100644 --- a/app/src/main/java/com/community/pocket/data/adapter/VisitorAdpter.java +++ b/app/src/main/java/com/community/pocket/data/adapter/VisitorAdpter.java @@ -7,6 +7,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +/** + * 访客信息数据适配器 + */ public class VisitorAdpter extends ArrayAdapter { private Map> map; diff --git a/app/src/main/java/com/community/pocket/data/main/garbage/GarbageSortingRequest.java b/app/src/main/java/com/community/pocket/data/main/garbage/GarbageSortingRequest.java index ffaac14..5bcd444 100644 --- a/app/src/main/java/com/community/pocket/data/main/garbage/GarbageSortingRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/garbage/GarbageSortingRequest.java @@ -3,7 +3,7 @@ package com.community.pocket.data.main.garbage; import com.community.pocket.R; import com.community.pocket.data.model.GarbageSorting; -import com.community.pocket.ui.main.ui.garbage.GarbageSortingResponse; +import com.community.pocket.ui.main.ui.garbage.sorting.GarbageSortingResponse; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/community/pocket/data/main/garbage/GarbageWasteRequest.java b/app/src/main/java/com/community/pocket/data/main/garbage/GarbageWasteRequest.java new file mode 100644 index 0000000..86a19e2 --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/main/garbage/GarbageWasteRequest.java @@ -0,0 +1,72 @@ +package com.community.pocket.data.main.garbage; + +import com.community.pocket.R; +import com.community.pocket.data.model.GarbageWaste; +import com.community.pocket.data.model.GarbageWasteManage; +import com.community.pocket.data.model.GarbageWastePrice; +import com.community.pocket.ui.main.ui.garbage.waste.GarbageWasteResponse; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * 废品回收接口 + * TODO 完善逻辑 + */ +public class GarbageWasteRequest { + private static volatile GarbageWasteRequest instance; + + private GarbageWasteRequest() { + } + + public static GarbageWasteRequest getInstance() { + if (instance == null) { + instance = new GarbageWasteRequest(); + } + return instance; + } + + //检索默认废品信息 + public GarbageWasteResponse searchDefault() { + GarbageWasteManage manage = new GarbageWasteManage(); + manage.setMobie("10086"); + manage.setName("Test"); + + List priceList = new ArrayList<>(); + for (int i = 0; i < 30; i++) { + GarbageWastePrice price = new GarbageWastePrice(); + price.setName("waste" + i); + price.setPrice(new Random().nextInt(10) * 1F); + priceList.add(price); + } + + GarbageWaste waste = new GarbageWaste(); + waste.setDefaultList(priceList); + waste.setGarbageWasteManage(manage); + + GarbageWasteResponse response = new GarbageWasteResponse(); + response.setSuccess(R.string.garbage_waste_search_ok); + response.setBody(waste); + return response; + } + + //检索废品 + public GarbageWasteResponse search(String name) { + List priceList = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + GarbageWastePrice price = new GarbageWastePrice(); + price.setName("waste" + i); + price.setPrice(new Random().nextInt(10) * 1F); + priceList.add(price); + } + + GarbageWaste waste = new GarbageWaste(); + waste.setSearchList(priceList); + GarbageWasteResponse response = new GarbageWasteResponse(); + response.setSuccess(R.string.garbage_waste_search_ok); + response.setBody(waste); + return response; + } + +} diff --git a/app/src/main/java/com/community/pocket/data/model/GarbageWaste.java b/app/src/main/java/com/community/pocket/data/model/GarbageWaste.java new file mode 100644 index 0000000..6c6c75f --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/GarbageWaste.java @@ -0,0 +1,40 @@ +package com.community.pocket.data.model; + +import java.util.List; + +//废品回收信息 +public class GarbageWaste { + + //默认价格信息 + private List defaultList; + + //检索价格信息 + private List searchList; + + //管理员信息 + private GarbageWasteManage garbageWasteManage; + + public List getDefaultList() { + return defaultList; + } + + public void setDefaultList(List defaultList) { + this.defaultList = defaultList; + } + + public List getSearchList() { + return searchList; + } + + public void setSearchList(List searchList) { + this.searchList = searchList; + } + + public GarbageWasteManage getGarbageWasteManage() { + return garbageWasteManage; + } + + public void setGarbageWasteManage(GarbageWasteManage garbageWasteManage) { + this.garbageWasteManage = garbageWasteManage; + } +} diff --git a/app/src/main/java/com/community/pocket/data/model/GarbageWasteManage.java b/app/src/main/java/com/community/pocket/data/model/GarbageWasteManage.java new file mode 100644 index 0000000..be35a03 --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/GarbageWasteManage.java @@ -0,0 +1,25 @@ +package com.community.pocket.data.model; + +//废品管理员信息 +public class GarbageWasteManage { + //管理员名 + private String name; + //联系电话 + private String mobie; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMobie() { + return mobie; + } + + public void setMobie(String mobie) { + this.mobie = mobie; + } +} diff --git a/app/src/main/java/com/community/pocket/data/model/GarbageWastePrice.java b/app/src/main/java/com/community/pocket/data/model/GarbageWastePrice.java new file mode 100644 index 0000000..85e518c --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/GarbageWastePrice.java @@ -0,0 +1,25 @@ +package com.community.pocket.data.model; + +//废品信息 +public class GarbageWastePrice { + //废品名 + private String name; + //废品价格 + private Float price; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Float getPrice() { + return price; + } + + public void setPrice(Float price) { + this.price = price; + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/TestMainFragment.java b/app/src/main/java/com/community/pocket/ui/main/TestMainFragment.java deleted file mode 100644 index 0b8fb26..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/TestMainFragment.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.community.pocket.ui.main; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.Observer; - -import com.community.pocket.ui.BaseFragment; - -import org.jetbrains.annotations.NotNull; - -/** - * 主界面框架 - */ -//TODO 测试类 -public abstract class TestMainFragment extends BaseFragment { - - @NotNull - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - - //文本框打印测试信息 - View root = super.onCreateView(inflater, container, savedInstanceState); - final TextView textView = root.findViewById(viewId()); - MutableLiveData mText = new MutableLiveData<>(); - mText.setValue("未完成界面!!!"); - mText.observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(@Nullable String s) { - textView.setText(s); - } - }); - - return root; - } - - protected abstract int viewId(); -} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageViewModel.java deleted file mode 100644 index 5baa1d5..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageViewModel.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.community.pocket.ui.main.ui.garbage; - -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; - -public class GarbageViewModel extends ViewModel { - - private MutableLiveData mText; - - public GarbageViewModel() { - mText = new MutableLiveData<>(); - mText.setValue("This is notifications fragment"); - } - - LiveData getText() { - return mText; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageWasteFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageWasteFragment.java deleted file mode 100644 index 0a75c17..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageWasteFragment.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.community.pocket.ui.main.ui.garbage; - -import com.community.pocket.R; -import com.community.pocket.ui.BaseFragment; - -import org.xutils.view.annotation.ContentView; - -@ContentView(R.layout.garbage_waste) -public class GarbageWasteFragment extends BaseFragment { -} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageSortingFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java similarity index 84% rename from app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageSortingFragment.java rename to app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java index 361e06d..1416f60 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageSortingFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java @@ -1,4 +1,4 @@ -package com.community.pocket.ui.main.ui.garbage; +package com.community.pocket.ui.main.ui.garbage.sorting; import android.os.Bundle; import android.text.Editable; @@ -14,7 +14,7 @@ import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; -import com.community.pocket.data.adapter.GarbageAdpter; +import com.community.pocket.data.adapter.GarbageSortingAdpter; import com.community.pocket.data.model.GarbageSorting; import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.listener.MyTextChange; @@ -45,7 +45,7 @@ public class GarbageSortingFragment extends BaseFragment { private MyAutoCompleteTextView myAutoCompleteTextView; - private GarbageAdpter garbageAdpter; + private GarbageSortingAdpter garbageSortingAdpter; @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { @@ -77,8 +77,8 @@ public class GarbageSortingFragment extends BaseFragment { searchSorting.addTextChangedListener(new MyTextChange() { @Override public void afterTextChanged(Editable s) { - if (garbageAdpter != null && garbageAdpter.containsKey(s.toString())) { - initView(garbageAdpter.get(s.toString())); + if (garbageSortingAdpter != null && garbageSortingAdpter.containsKey(s.toString())) { + initView(garbageSortingAdpter.get(s.toString())); } myAutoCompleteTextView.searchHandler(); @@ -104,12 +104,12 @@ public class GarbageSortingFragment extends BaseFragment { */ private void initSearch(List garbageSortings) { // 设置适配器 - if (garbageAdpter == null) { - garbageAdpter = new GarbageAdpter(garbageSortings, getContext()); + if (garbageSortingAdpter == null) { + garbageSortingAdpter = new GarbageSortingAdpter(garbageSortings, getContext()); // 将适配器与当前AutoCompleteTextView控件绑定 - searchSorting.setAdapter(garbageAdpter); + searchSorting.setAdapter(garbageSortingAdpter); } else { - garbageAdpter.addAll(garbageSortings); + garbageSortingAdpter.addAll(garbageSortings); } myAutoCompleteTextView.refreshDropList(); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageSortingResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingResponse.java similarity index 79% rename from app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageSortingResponse.java rename to app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingResponse.java index ff1db60..e164a90 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageSortingResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingResponse.java @@ -1,4 +1,4 @@ -package com.community.pocket.ui.main.ui.garbage; +package com.community.pocket.ui.main.ui.garbage.sorting; import com.community.pocket.data.model.GarbageSorting; import com.community.pocket.ui.main.ui.share.Response; diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageSortingViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java similarity index 94% rename from app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageSortingViewModel.java rename to app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java index bc340c8..2869b41 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageSortingViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java @@ -1,4 +1,4 @@ -package com.community.pocket.ui.main.ui.garbage; +package com.community.pocket.ui.main.ui.garbage.sorting; import androidx.lifecycle.MutableLiveData; diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteFragment.java new file mode 100644 index 0000000..21a75fa --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteFragment.java @@ -0,0 +1,182 @@ +package com.community.pocket.ui.main.ui.garbage.waste; + +import android.os.Bundle; +import android.text.Editable; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.View; +import android.widget.AutoCompleteTextView; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.gridlayout.widget.GridLayout; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; + +import com.community.pocket.R; +import com.community.pocket.data.adapter.GarbageWasteAdpter; +import com.community.pocket.data.model.GarbageWaste; +import com.community.pocket.data.model.GarbageWasteManage; +import com.community.pocket.data.model.GarbageWastePrice; +import com.community.pocket.ui.BaseFragment; +import com.community.pocket.ui.listener.MyTextChange; +import com.community.pocket.ui.main.ui.share.MyAutoCompleteTextView; + +import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.ViewInject; + +import java.util.List; + +@ContentView(R.layout.garbage_waste) +public class GarbageWasteFragment extends BaseFragment { + + //联系管理员 + @ViewInject(R.id.name) + private TextView name; + //联系电话 + @ViewInject(R.id.mobie) + private TextView mobie; + + //检索废品 + @ViewInject(R.id.search_price) + private AutoCompleteTextView searchPrice; + + @ViewInject(R.id.waste_layout) + private GridLayout layout; + + private MyAutoCompleteTextView myAutoCompleteTextView; + + private GarbageWasteAdpter garbageWasteAdpter; + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + final GarbageWasteViewModel viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(GarbageWasteViewModel.class); + + myAutoCompleteTextView = new MyAutoCompleteTextView(searchPrice, viewModel); + + viewModel.searchDefault(); + + //监听默认废品信息请求状态 + viewModel.getDefaultList().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(GarbageWasteResponse garbageWasteResponse) { + if (garbageWasteResponse == null) { + return; + } + + if (garbageWasteResponse.getSuccess() != null) { + initDefault(garbageWasteResponse.getBody()); + } + + if (garbageWasteResponse.getError() != null) { + Toast.makeText(getContext(), garbageWasteResponse.fail(getContext()), Toast.LENGTH_SHORT).show(); + } + } + }); + + //监听废品信息请求状态 + viewModel.getSearchList().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(GarbageWasteResponse garbageWasteResponse) { + if (garbageWasteResponse == null) { + return; + } + + if (garbageWasteResponse.getSuccess() != null) { + initSearch(garbageWasteResponse.getBody()); + } + + if (garbageWasteResponse.getError() != null) { + Toast.makeText(getContext(), garbageWasteResponse.fail(getContext()), Toast.LENGTH_SHORT).show(); + } + } + }); + //检索内容改变触发监听器 + searchPrice.addTextChangedListener(new MyTextChange() { + @Override + public void afterTextChanged(Editable s) { + if (garbageWasteAdpter != null && garbageWasteAdpter.containsKey(s.toString())) { + layout.removeAllViews(); + addHead(); + addItem(garbageWasteAdpter.get(s.toString())); + } + + if (s.length() == 0) { + viewModel.searchDefault(); + } else { + myAutoCompleteTextView.searchHandler(); + } + } + }); + } + + /** + * 检索默认废品信息 + * + * @param waste 废品信息 + */ + private void initDefault(GarbageWaste waste) { + GarbageWasteManage manage = waste.getGarbageWasteManage(); + name.setText(getString(R.string.garbage_waste_name, manage.getName())); + mobie.setText(getString(R.string.garbage_waste_mobie, manage.getMobie())); + + layout.removeAllViews(); + addHead(); + + List priceList = waste.getDefaultList(); + for (GarbageWastePrice price : priceList) { + addItem(price); + } + } + + private void addHead() { + createTextView(getString(R.string.garbage_table_name)); + createTextView(getString(R.string.garbage_table_price)); + } + + /** + * 添加一行数据 + * + * @param price 废品信息 + */ + private void addItem(GarbageWastePrice price) { + createTextView(price.getName()); + createTextView(String.valueOf(price.getPrice())); + } + + /** + * 创建单元格 + */ + private void createTextView(CharSequence text) { + TextView textView = new TextView(getContext()); + textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); + textView.setText(text); + textView.setBackground(getResources().getDrawable(R.drawable.border)); + textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24); + GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); + layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); + textView.setLayoutParams(layoutParams); + layout.addView(textView); + } + + /** + * 检索废品回收信息 + * + * @param waste 废品信息 + */ + private void initSearch(GarbageWaste waste) { + // 设置适配器 + if (garbageWasteAdpter == null) { + garbageWasteAdpter = new GarbageWasteAdpter(waste.getSearchList(), getContext()); + // 将适配器与当前AutoCompleteTextView控件绑定 + searchPrice.setAdapter(garbageWasteAdpter); + } else { + garbageWasteAdpter.addAll(waste.getSearchList()); + } + myAutoCompleteTextView.refreshDropList(); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteResponse.java new file mode 100644 index 0000000..e355cd8 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteResponse.java @@ -0,0 +1,7 @@ +package com.community.pocket.ui.main.ui.garbage.waste; + +import com.community.pocket.data.model.GarbageWaste; +import com.community.pocket.ui.main.ui.share.Response; + +public class GarbageWasteResponse extends Response { +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteViewModel.java new file mode 100644 index 0000000..e4a91ee --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteViewModel.java @@ -0,0 +1,42 @@ +package com.community.pocket.ui.main.ui.garbage.waste; + +import androidx.lifecycle.MutableLiveData; + +import com.community.pocket.data.main.garbage.GarbageWasteRequest; +import com.community.pocket.ui.main.ui.share.BaseViewModel; +import com.community.pocket.ui.main.ui.share.SearchViewModel; + +//废品信息UI管理 +public class GarbageWasteViewModel extends BaseViewModel implements SearchViewModel { + + //检索默认废品信息 + private MutableLiveData defaultList = new MutableLiveData<>(); + //检索废品信息 + private MutableLiveData searchList = new MutableLiveData<>(); + + MutableLiveData getDefaultList() { + return defaultList; + } + + MutableLiveData getSearchList() { + return searchList; + } + + @Override + protected GarbageWasteRequest getRequest() { + return GarbageWasteRequest.getInstance(); + } + + //检索默认废品请求状态 + void searchDefault() { + GarbageWasteResponse response = getRequest().searchDefault(); + defaultList.setValue(response); + } + + //检索废品请求状态 + @Override + public void search(String content) { + GarbageWasteResponse response = getRequest().search(content); + searchList.setValue(response); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java index 0e56338..5f68753 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java @@ -51,7 +51,6 @@ public abstract class VisitorMyVisitor extends BaseFragment { /** * 初始化数据 - * TODO 测试数据 */ protected void loadData(List visitors) { for (final Visitor visitor : visitors) { diff --git a/app/src/main/res/layout/main/layout/garbage/layout/garbage.xml b/app/src/main/res/layout/main/layout/garbage/layout/garbage.xml index e9827ef..27a7100 100644 --- a/app/src/main/res/layout/main/layout/garbage/layout/garbage.xml +++ b/app/src/main/res/layout/main/layout/garbage/layout/garbage.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@color/colorAccent" tools:context=".ui.main.ui.garbage.GarbageFragment"> + tools:layout_constraintTop_toBottomOf="@id/titlebar" /> \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/garbage/layout/garbage_sorting.xml b/app/src/main/res/layout/main/layout/garbage/layout/garbage_sorting.xml index acba582..7381fef 100644 --- a/app/src/main/res/layout/main/layout/garbage/layout/garbage_sorting.xml +++ b/app/src/main/res/layout/main/layout/garbage/layout/garbage_sorting.xml @@ -1,45 +1,52 @@ - + android:layout_height="match_parent" + tools:context=".ui.main.ui.garbage.sorting.GarbageSortingFragment"> - + android:layout_gravity="center_vertical"> - + - + + + - - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/garbage/layout/garbage_waste.xml b/app/src/main/res/layout/main/layout/garbage/layout/garbage_waste.xml index c3f8343..fa9de50 100644 --- a/app/src/main/res/layout/main/layout/garbage/layout/garbage_waste.xml +++ b/app/src/main/res/layout/main/layout/garbage/layout/garbage_waste.xml @@ -1,4 +1,63 @@ - \ No newline at end of file + android:layout_height="match_parent" + tools:context=".ui.main.ui.garbage.waste.GarbageWasteFragment"> + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/garbage/layout/waste_item.xml b/app/src/main/res/layout/main/layout/garbage/layout/waste_item.xml new file mode 100644 index 0000000..e0f6649 --- /dev/null +++ b/app/src/main/res/layout/main/layout/garbage/layout/waste_item.xml @@ -0,0 +1,24 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/info/layout/info_fragment.xml b/app/src/main/res/layout/main/layout/info/layout/info_fragment.xml index 8070fb0..724f0ca 100644 --- a/app/src/main/res/layout/main/layout/info/layout/info_fragment.xml +++ b/app/src/main/res/layout/main/layout/info/layout/info_fragment.xml @@ -9,7 +9,8 @@ + android:layout_height="match_parent" + android:background="@color/colorAccent"> \ No newline at end of file diff --git a/app/src/main/res/values-en-rUS/strings.xml b/app/src/main/res/values-en-rUS/strings.xml index 8f96d68..93f6e07 100644 --- a/app/src/main/res/values-en-rUS/strings.xml +++ b/app/src/main/res/values-en-rUS/strings.xml @@ -157,4 +157,10 @@ please input name grabage image search success + waste name:%1s + waste mobie:%1s + search name + search success + name + price \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 10c0325..0fa6636 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -157,4 +157,10 @@ 请输入垃圾名 垃圾图片 检索成功 + 废品回收管理员:%1s + 联系电话:%1s + 检索废品 + 检索废品成功 + 废品 + 价格 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 949ec50..f089793 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -158,6 +158,12 @@ please input name grabage image search success + waste name:%1s + waste mobie:%1s + search name + search success + name + price