From fcdddf8b9b34f9930bec454b5fffe41c0e33ba3c Mon Sep 17 00:00:00 2001
From: Linjiajia <319408893@qq.com>
Date: 星期一, 24 四月 2023 21:17:05 +0800
Subject: [PATCH] 功能模块大部分

---
 app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivityViewModel.java |  166 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 122 insertions(+), 44 deletions(-)

diff --git a/app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivityViewModel.java b/app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivityViewModel.java
index c8c606b..b363acd 100644
--- a/app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivityViewModel.java
+++ b/app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivityViewModel.java
@@ -11,19 +11,25 @@
 import com.android.app_base.base.viewmodel.BaseViewModel;
 import com.android.app_base.http.ResultData;
 import com.android.app_base.utils.RxUtils;
+import com.application.zhangshi_app_android.bean.FamilyAssetsBean;
 import com.application.zhangshi_app_android.bean.FamilyMemorabiliaBean;
+import com.application.zhangshi_app_android.bean.FamilyMemorabiliaRequestBean;
 import com.application.zhangshi_app_android.bean.FamilyMemorabiliaResponseBean;
 import com.application.zhangshi_app_android.data.DataRepository;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import io.reactivex.Observer;
 import io.reactivex.disposables.Disposable;
+import io.reactivex.functions.Action;
 
 /**
  * @author Ljj
@@ -32,9 +38,12 @@
  */
 public class FamilyMemorabiliaActivityViewModel extends BaseViewModel<DataRepository> {
 
-    private MutableLiveData<List<FamilyMemorabiliaBean>> checkListLiveData;
-    private MutableLiveData<List<FamilyMemorabiliaBean>> dataListLiveData;
-    private MutableLiveData<String> stringMutableLiveData;
+    private MutableLiveData<List<FamilyMemorabiliaBean>> checkListLiveData;//閫変腑鐨勬暟鎹�
+    private MutableLiveData<List<FamilyMemorabiliaBean>> dataListLiveData;//鎵�鏈夋暟鎹�
+    private MutableLiveData<Integer> operateTypeLiveData;//鎿嶄綔绫诲瀷 0 閫夋嫨鎿嶄綔 1.瀹屾垚 2.鍒犻櫎
+
+    private MutableLiveData<FamilyMemorabiliaRequestBean> requestBeanMutableLiveData;//璇锋眰鍙傛暟
+    private MutableLiveData<List<FamilyMemorabiliaBean>> moreListLiveData;//涓嬫媺鍔犺浇鏁版嵁
     public FamilyMemorabiliaActivityViewModel(@NonNull Application application) {
         super(application);
     }
@@ -46,24 +55,9 @@
     /**
      * 鑾峰彇瀹跺ぇ浜嬭
      */
-    public void getFamilyMemorabilia(int searchType) {
-        Map<String, Object> queryMap = new HashMap<>();
-        queryMap.put("pageNum",1);
-        queryMap.put("pageSize",20);
-        if (searchType == 1){
-            queryMap.put("remark",stringMutableLiveData.getValue());
-        } else if (searchType == 2) {
-            queryMap.put("title",stringMutableLiveData.getValue());
-        }else if (searchType == 3) {
-            queryMap.put("people",stringMutableLiveData.getValue());
-        }
-        else if (searchType == 4) {
-            queryMap.put("createTime",stringMutableLiveData.getValue());
-        }
-        else if (searchType == 5) {
-            queryMap.put("address",stringMutableLiveData.getValue());
-        }
-        model.getFamilyMemorabilia(queryMap)
+    public void getFamilyMemorabilia() {
+        System.out.println(getRequestBeanMutableLiveData().getValue());
+        model.getFamilyMemorabilia(getRequestBeanMutableLiveData().getValue().getMap())
                 .compose(RxUtils.schedulersTransformer())
                 .subscribe(new Observer<ResultData<FamilyMemorabiliaResponseBean>>() {
                     @Override
@@ -77,7 +71,52 @@
                             if (data.getData().getData().isEmpty()){
                                 changeStateView(StateViewEnum.DATA_NULL);
                             }else {
+                                changeStateView(StateViewEnum.HIDE);
                                 dataListLiveData.postValue(data.getData().getData());
+                            }
+                        }else {
+                            messageLiveData.postValue(data.getMsg());
+                        }
+                    }
+
+                    @Override
+                    public void onError(Throwable e) {
+                        messageLiveData.postValue(e.getMessage());
+                    }
+
+                    @Override
+                    public void onComplete() {
+
+                    }
+                });
+    }
+    /**
+     * 鑾峰彇瀹跺ぇ浜嬭 鍔犺浇鏇村
+     */
+    public void getMoreFamilyMemorabilia() {
+        requestBeanMutableLiveData.getValue().setPageNum(requestBeanMutableLiveData.getValue().getPageNum() + 1);
+        model.getFamilyMemorabilia(getRequestBeanMutableLiveData().getValue().getMap())
+                .compose(RxUtils.schedulersTransformer())
+                .doFinally(new Action() {
+                    @Override
+                    public void run() throws Exception {
+                        changeStateView(StateViewEnum.DATA_FINISH);
+                    }
+                })
+                .subscribe(new Observer<ResultData<FamilyMemorabiliaResponseBean>>() {
+                    @Override
+                    public void onSubscribe(Disposable d) {
+                        addSubscribe(d);
+                    }
+
+                    @Override
+                    public void onNext(ResultData<FamilyMemorabiliaResponseBean> data) {
+                        if (data.getCode() == CODE_SUCCESS){
+                            if (data.getData().getData().isEmpty()){
+                                messageLiveData.postValue("娌℃湁鏇村鏁版嵁浜�");
+                            }else {
+                                changeStateView(StateViewEnum.HIDE);
+                                moreListLiveData.postValue(data.getData().getData());
                             }
                         }else {
                             messageLiveData.postValue(data.getMsg());
@@ -157,6 +196,20 @@
         this.checkListLiveData = checkListLiveData;
     }
 
+    public MutableLiveData<FamilyMemorabiliaRequestBean> getRequestBeanMutableLiveData() {
+        if (requestBeanMutableLiveData == null){
+            requestBeanMutableLiveData = new MutableLiveData<>();
+        }
+        if (requestBeanMutableLiveData.getValue() == null){
+            requestBeanMutableLiveData.setValue(new FamilyMemorabiliaRequestBean());
+        }
+        return requestBeanMutableLiveData;
+    }
+
+    public void setRequestBeanMutableLiveData(MutableLiveData<FamilyMemorabiliaRequestBean> requestBeanMutableLiveData) {
+        this.requestBeanMutableLiveData = requestBeanMutableLiveData;
+    }
+
     public MutableLiveData<List<FamilyMemorabiliaBean>> getDataListLiveData() {
         if (dataListLiveData == null){
             dataListLiveData = new MutableLiveData<>();
@@ -168,35 +221,60 @@
         this.dataListLiveData = dataListLiveData;
     }
 
-    public MutableLiveData<String> getStringMutableLiveData() {
-        if (stringMutableLiveData == null){
-            stringMutableLiveData = new MutableLiveData<>();
+    public MutableLiveData<List<FamilyMemorabiliaBean>> getMoreListLiveData() {
+        if (moreListLiveData == null){
+            moreListLiveData = new MutableLiveData<>();
         }
-        return stringMutableLiveData;
+        return moreListLiveData;
     }
 
-    public void setStringMutableLiveData(MutableLiveData<String> stringMutableLiveData) {
-        this.stringMutableLiveData = stringMutableLiveData;
+    public void setMoreListLiveData(MutableLiveData<List<FamilyMemorabiliaBean>> moreListLiveData) {
+        this.moreListLiveData = moreListLiveData;
     }
 
+    public MutableLiveData<Integer> getOperateTypeLiveData() {
+        if (operateTypeLiveData == null){
+            operateTypeLiveData = new MutableLiveData<>();
+            operateTypeLiveData.setValue(0);
+        }
+        return operateTypeLiveData;
+    }
+
+    public void setOperateTypeLiveData(MutableLiveData<Integer> operateTypeLiveData) {
+        this.operateTypeLiveData = operateTypeLiveData;
+    }
+
+    /**
+     * 鏀瑰彉鎺掑簭
+     * @param b true 闄嶅簭 false 鍗囧簭
+     */
     public void changeOrder(boolean b) {
-        List<FamilyMemorabiliaBean> dataList = getDataListLiveData().getValue();
-        if (dataList == null) return;
-        if (b){
-            dataList.sort(new Comparator<FamilyMemorabiliaBean>() {
-                @Override
-                public int compare(FamilyMemorabiliaBean o1, FamilyMemorabiliaBean o2) {
-                    return (int) (o1.getId() - o2.getId());
-                }
-            });
-        }else {
-            dataList.sort(new Comparator<FamilyMemorabiliaBean>() {
-                @Override
-                public int compare(FamilyMemorabiliaBean o1, FamilyMemorabiliaBean o2) {
-                    return (int) (o2.getId() - o1.getId());
-                }
-            });
+        List<FamilyMemorabiliaBean> list = getDataListLiveData().getValue();
+        if (list == null || list.isEmpty()){
+            return;
         }
-        getDataListLiveData().postValue(dataList);
+        list.sort(new Comparator<FamilyMemorabiliaBean>() {
+            @Override
+            public int compare(FamilyMemorabiliaBean o1, FamilyMemorabiliaBean o2) {
+                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", java.util.Locale.getDefault());
+                Date date1 = null;
+                Date date2 = null;
+                try {
+                    date1 = format.parse(o1.getCreateTime());
+                    date2 = format.parse(o2.getCreateTime());
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+                if (date1 != null && date2 != null) {
+                    if (b){
+                        return date2.compareTo(date1);
+                    }else {
+                        return date1.compareTo(date2);
+                    }
+                }
+                return 0;
+            }
+        });
+        getDataListLiveData().postValue(list);
     }
 }

--
Gitblit v1.9.1