From a0dc6be52293a64ebfe38b8c2391dc7d2ffe63ae Mon Sep 17 00:00:00 2001
From: Linjiajia <319408893@qq.com>
Date: 星期一, 15 五月 2023 20:05:27 +0800
Subject: [PATCH] 提交代码

---
 app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivityViewModel.java |  255 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 255 insertions(+), 0 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 1e180b5..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
@@ -1,11 +1,35 @@
 package com.application.zhangshi_app_android.ui.function;
 
+import static com.android.app_base.base.BaseConfig.CODE_SUCCESS;
+
 import android.app.Application;
 
 import androidx.annotation.NonNull;
+import androidx.lifecycle.MutableLiveData;
 
+import com.android.app_base.base.StateViewEnum;
 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
@@ -14,6 +38,12 @@
  */
 public class FamilyMemorabiliaActivityViewModel extends BaseViewModel<DataRepository> {
 
+    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);
     }
@@ -22,4 +52,229 @@
     protected DataRepository initModel() {
         return DataRepository.getInstance();
     }
+    /**
+     * 鑾峰彇瀹跺ぇ浜嬭
+     */
+    public void getFamilyMemorabilia() {
+        System.out.println(getRequestBeanMutableLiveData().getValue());
+        model.getFamilyMemorabilia(getRequestBeanMutableLiveData().getValue().getMap())
+                .compose(RxUtils.schedulersTransformer())
+                .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()){
+                                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());
+                        }
+                    }
+
+                    @Override
+                    public void onError(Throwable e) {
+                        messageLiveData.postValue(e.getMessage());
+                    }
+
+                    @Override
+                    public void onComplete() {
+
+                    }
+                });
+    }
+    /**
+     * 鍒犻櫎瀹跺ぇ浜嬭
+     */
+    public void delete() {
+        List<FamilyMemorabiliaBean> deleteList = getCheckListLiveData().getValue();
+        if (deleteList == null){
+            return;
+        }
+        StringBuffer sb = new StringBuffer();
+        deleteList.forEach(familyMemorabiliaBean -> sb.append(familyMemorabiliaBean.getId()).append(","));
+        sb.deleteCharAt(sb.length()-1);
+        System.out.println();
+        model.deleteFamilyMemorabilia(sb.toString())
+                .compose(RxUtils.schedulersTransformer())
+                .subscribe(new Observer<ResultData<String>>() {
+                    @Override
+                    public void onSubscribe(Disposable d) {
+                        addSubscribe(d);
+                    }
+
+                    @Override
+                    public void onNext(ResultData<String> stringResultData) {
+                        if (stringResultData.getCode() == CODE_SUCCESS){
+                            List<FamilyMemorabiliaBean> list = getDataListLiveData().getValue();
+                            if (list != null) {
+                                list.removeAll(getCheckListLiveData().getValue());
+                            }
+                            getDataListLiveData().postValue(list);
+                            messageLiveData.postValue("鍒犻櫎鎴愬姛");
+                            getCheckListLiveData().postValue(new ArrayList<>());
+                        }else {
+                            messageLiveData.postValue(stringResultData.getMsg());
+                        }
+                    }
+
+                    @Override
+                    public void onError(Throwable e) {
+                        messageLiveData.postValue(e.getMessage());
+                    }
+
+                    @Override
+                    public void onComplete() {
+
+                    }
+                });
+    }
+
+    public MutableLiveData<List<FamilyMemorabiliaBean>> getCheckListLiveData() {
+        if (checkListLiveData==null){
+            checkListLiveData = new MutableLiveData<>();
+            checkListLiveData.postValue(new ArrayList<>());
+        }
+        if (checkListLiveData.getValue() == null){
+            checkListLiveData.postValue(new ArrayList<>());
+        }
+        return checkListLiveData;
+    }
+
+    public void setCheckListLiveData(MutableLiveData<List<FamilyMemorabiliaBean>> checkListLiveData) {
+        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<>();
+        }
+        return dataListLiveData;
+    }
+
+    public void setDataListLiveData(MutableLiveData<List<FamilyMemorabiliaBean>> dataListLiveData) {
+        this.dataListLiveData = dataListLiveData;
+    }
+
+    public MutableLiveData<List<FamilyMemorabiliaBean>> getMoreListLiveData() {
+        if (moreListLiveData == null){
+            moreListLiveData = new MutableLiveData<>();
+        }
+        return moreListLiveData;
+    }
+
+    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> list = getDataListLiveData().getValue();
+        if (list == null || list.isEmpty()){
+            return;
+        }
+        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