Browse Source

刷新选项卡标题数值

ychk 3 months ago
parent
commit
97e88386d7

+ 64 - 3
app/src/main/java/com/tofly/yxpc/ui/activity/DataCorrectionActivity.java

@@ -4,17 +4,30 @@ import androidx.fragment.app.Fragment;
 
 import com.tofly.latte_core.base.LatteActivity;
 import com.tofly.latte_core.base.LatteContract;
+import com.tofly.latte_core.utils.AccountManager;
 import com.tofly.yxpc.databinding.ActivityDataCorrectionBinding;
+import com.tofly.yxpc.entity.DataCorrectionBean;
+import com.tofly.yxpc.entity.DataCorrectionPeopleBean;
+import com.tofly.yxpc.entity.PageInfo;
 import com.tofly.yxpc.ui.adapter.ListPageAdapter;
 import com.tofly.yxpc.ui.fragment.MyDataCorrectionFragment;
 import com.tofly.yxpc.ui.fragment.WholeDataCorrectionFragment;
+import com.tofly.yxpc.ui.impl.DataCorrectionImpl;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+/**
+ * @author 76486
+ */
 public class DataCorrectionActivity extends LatteActivity {
 
     private ActivityDataCorrectionBinding binding;
+    private final List<String> titles = new ArrayList<>();
+    private ListPageAdapter listPageAdapter;
 
     @Override
     public Object setLayout() {
@@ -24,7 +37,7 @@ public class DataCorrectionActivity extends LatteActivity {
 
     @Override
     protected LatteContract.LattePresenter createPresenter() {
-        return null;
+        return new DataCorrectionImpl();
     }
 
     @Override
@@ -34,13 +47,14 @@ public class DataCorrectionActivity extends LatteActivity {
     }
 
     private void initTabLayout() {
-        String[] strings = {"待我整改 0", "全部待整改 0"};
+        titles.add("待我整改");
+        titles.add("全部待整改");
         List<Fragment> fragmentList = new ArrayList<>();
         MyDataCorrectionFragment myDataCorrectionFragment = new MyDataCorrectionFragment();
         WholeDataCorrectionFragment wholeDataCorrectionFragment = new WholeDataCorrectionFragment();
         fragmentList.add(myDataCorrectionFragment);
         fragmentList.add(wholeDataCorrectionFragment);
-        ListPageAdapter listPageAdapter = new ListPageAdapter(getSupportFragmentManager(), strings, null, fragmentList);
+        listPageAdapter = new ListPageAdapter(getSupportFragmentManager(), titles, null, fragmentList);
         binding.viewPager.setAdapter(listPageAdapter);
         binding.viewPager.setOffscreenPageLimit(2);
         binding.tabLayout.setupWithViewPager(binding.viewPager);
@@ -50,4 +64,51 @@ public class DataCorrectionActivity extends LatteActivity {
 
         binding.viewPager.setCurrentItem(0);
     }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        Map<String, Object> map = new HashMap<>();
+        map.put("correctionStatus", "待整改");
+        map.put("inspectUser", AccountManager.getUserId());
+        map.put("size", 1);
+        map.put("current", 1);
+        mPresenter.getResultOne(this, map);
+        mPresenter.getResultTwo(this, null);
+    }
+
+    @Override
+    public <T> void getResultOne(T response) {
+        if (response != null) {
+            PageInfo<DataCorrectionBean> pageInfo = (PageInfo<DataCorrectionBean>) response;
+            if (pageInfo.getTotal() > 0) {
+                titles.set(0, "待我整改 " + pageInfo.getTotal());
+            } else {
+                titles.set(0, "待我整改");
+            }
+        } else {
+            titles.set(0, "待我整改");
+        }
+        listPageAdapter.notifyDataSetChanged();
+    }
+
+    @Override
+    public <T> void getResultTwo(T response) {
+        super.getResultTwo(response);
+        List<DataCorrectionPeopleBean> peopleList = new ArrayList<>();
+        if (response != null) {
+            peopleList.addAll((Collection<? extends DataCorrectionPeopleBean>) response);
+        }
+        int size = 0;
+        for (DataCorrectionPeopleBean bean : peopleList) {
+            size = size + bean.getCounts();
+        }
+        if (size > 0) {
+            titles.set(1, "全部待整改 " + size);
+        } else {
+            titles.set(1, "全部待整改");
+        }
+        listPageAdapter.notifyDataSetChanged();
+    }
+
 }

+ 7 - 3
app/src/main/java/com/tofly/yxpc/ui/activity/DataCorrectionDetailActivity.java

@@ -15,9 +15,13 @@ import com.tofly.yxpc.ui.fragment.UnCalibrateCorrectionFragment;
 import com.tofly.yxpc.ui.fragment.WaterCheckCorrectionFragment;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 
+/**
+ * @author 76486
+ */
 public class DataCorrectionDetailActivity extends LatteActivity {
 
     private ActivityDataCorrectionDetailBinding binding;
@@ -47,17 +51,17 @@ public class DataCorrectionDetailActivity extends LatteActivity {
     }
 
     private void initTabLayout() {
-        String[] strings;
+        List<String> strings;
         List<Fragment> fragmentList = new ArrayList<>();
         Bundle bundle = new Bundle();
         bundle.putString("data", JSON.toJSONString(waterMeterEntity));
         if ("无法标定水表".equals(waterMeterEntity.getQtType())) {
-            strings = new String[]{"无法标定"};
+            strings = Collections.singletonList("无法标定");
             UnCalibrateCorrectionFragment unCalibrateFragment = new UnCalibrateCorrectionFragment();
             unCalibrateFragment.setArguments(bundle);
             fragmentList.add(unCalibrateFragment);
         } else {
-            strings = new String[]{"稽查"};
+            strings = Collections.singletonList("稽查");
             WaterCheckCorrectionFragment waterCheckFragment = new WaterCheckCorrectionFragment();
             waterCheckFragment.setArguments(bundle);
             fragmentList.add(waterCheckFragment);

+ 3 - 2
app/src/main/java/com/tofly/yxpc/ui/activity/TaskDetailActivity.java

@@ -21,6 +21,7 @@ import com.tofly.yxpc.ui.fragment.WaterCheckFragment;
 import com.tofly.yxpc.utils.db.DaoUtilsStore;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -65,8 +66,8 @@ public class TaskDetailActivity extends LatteActivity {
     }
 
     private void initTabLayout() {
-        String[] strings = {"稽查", "无法标定"};
-        int[] ints = {R.mipmap.icon_jc, R.mipmap.icon_wf};
+        List<String> strings = Arrays.asList("稽查", "无法标定");
+        List<Integer> ints = Arrays.asList(R.mipmap.icon_jc, R.mipmap.icon_wf);
         List<Fragment> fragmentList = new ArrayList<>();
         waterCheckFragment = new WaterCheckFragment();
         unCalibrateFragment = new UnCalibrateFragment();

+ 10 - 6
app/src/main/java/com/tofly/yxpc/ui/activity/WorkCheckActivity.java

@@ -16,9 +16,13 @@ import com.tofly.yxpc.ui.fragment.UnCalibrateWorkFragment;
 import com.tofly.yxpc.ui.fragment.WaterCheckWorkFragment;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 
+/**
+ * @author 76486
+ */
 public class WorkCheckActivity extends LatteActivity {
 
     private ActivityWorkCheckBinding binding;
@@ -51,20 +55,20 @@ public class WorkCheckActivity extends LatteActivity {
     }
 
     private void initTabLayout() {
-        String[] strings;
-        int[] ints;
+        List<String> strings;
+        List<Integer> ints;
         List<Fragment> fragmentList = new ArrayList<>();
         Bundle bundle = new Bundle();
         bundle.putString("data", JSON.toJSONString(waterMeterEntity));
         if (waterMeterEntity.getTaskState() == 2) {
-            strings = new String[]{"无法标定"};
-            ints = new int[]{R.mipmap.icon_wf};
+            strings = Collections.singletonList("无法标定");
+            ints = Collections.singletonList(R.mipmap.icon_wf);
             UnCalibrateWorkFragment unCalibrateFragment = new UnCalibrateWorkFragment();
             unCalibrateFragment.setArguments(bundle);
             fragmentList.add(unCalibrateFragment);
         } else {
-            strings = new String[]{"稽查"};
-            ints = new int[]{R.mipmap.icon_jc};
+            strings = Collections.singletonList("稽查");
+            ints = Collections.singletonList(R.mipmap.icon_jc);
             WaterCheckWorkFragment waterCheckFragment = new WaterCheckWorkFragment();
             waterCheckFragment.setArguments(bundle);
             fragmentList.add(waterCheckFragment);

+ 8 - 6
app/src/main/java/com/tofly/yxpc/ui/adapter/ListPageAdapter.java

@@ -13,6 +13,8 @@ import androidx.fragment.app.FragmentPagerAdapter;
 
 import com.tofly.yxpc.R;
 
+import org.greenrobot.greendao.annotation.NotNull;
+
 import java.util.List;
 
 /**
@@ -21,10 +23,10 @@ import java.util.List;
 public class ListPageAdapter extends FragmentPagerAdapter {
 
     private final List<Fragment> fragments;
-    private final String[] titles;
-    private final int[] ints;
+    private final List<String> titles;
+    private final List<Integer> ints;
 
-    public ListPageAdapter(FragmentManager fm, String[] titles, int[] ints, List<Fragment> fragments) {
+    public ListPageAdapter(FragmentManager fm, @NotNull List<String> titles, List<Integer> ints, List<Fragment> fragments) {
         super(fm);
         this.fragments = fragments;
         this.titles = titles;
@@ -44,16 +46,16 @@ public class ListPageAdapter extends FragmentPagerAdapter {
     @Nullable
     @Override
     public CharSequence getPageTitle(int position) {
-        return titles[position];
+        return titles.get(position);
     }
 
     public View getTabView(int position, Context context) {
         View view = LayoutInflater.from(context).inflate(R.layout.item_title, null);
         ImageView iv = view.findViewById(R.id.img_title);
         TextView tv = view.findViewById(R.id.tv_title);
-        tv.setText(titles[position]);
+        tv.setText(titles.get(position));
         if (ints != null) {
-            iv.setBackgroundResource(ints[position]);
+            iv.setBackgroundResource(ints.get(position));
         }
         return view;
     }

+ 3 - 0
app/src/main/java/com/tofly/yxpc/ui/fragment/WholeDataCorrectionFragment.java

@@ -27,6 +27,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * @author 76486
+ */
 public class WholeDataCorrectionFragment extends LatteDelegate {
 
     private FragmentWholeDataCorrectionBinding binding;

+ 3 - 0
app/src/main/java/com/tofly/yxpc/ui/impl/DataCorrectionImpl.java

@@ -19,6 +19,9 @@ import com.tofly.yxpc.utils.RequestBodyUtils;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * @author 76486
+ */
 public class DataCorrectionImpl extends LattePresenterImpl {
 
     @Override