From 5325e22a184b53aadcc5e9552cb1ec54f9c8ad81 Mon Sep 17 00:00:00 2001
From: guoshen <3129367635@qq.com>
Date: 星期六, 29 六月 2024 16:33:11 +0800
Subject: [PATCH] 加入了直播、会议功能

---
 app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivityViewModel.java |  306 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 251 insertions(+), 55 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..af5a6a6 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
@@ -3,27 +3,29 @@
 import static com.android.app_base.base.BaseConfig.CODE_SUCCESS;
 
 import android.app.Application;
+import android.text.TextUtils;
 
 import androidx.annotation.NonNull;
+import androidx.lifecycle.LiveData;
 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.android.app_base.utils.Utils;
 import com.application.zhangshi_app_android.bean.FamilyMemorabiliaBean;
-import com.application.zhangshi_app_android.bean.FamilyMemorabiliaResponseBean;
+import com.application.zhangshi_app_android.bean.FamilyMemorabiliaRequestBean;
+import com.application.zhangshi_app_android.bean.PageResponseBean;
 import com.application.zhangshi_app_android.data.DataRepository;
 
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
+import java.util.Date;
 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,13 +34,21 @@
  */
 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> requestBeanLiveData;//璇锋眰鍙傛暟
+    private MutableLiveData<List<FamilyMemorabiliaBean>> moreListLiveData;//涓嬫媺鍔犺浇鏁版嵁
+    private MutableLiveData<List<FamilyMemorabiliaBean>> finishDeleteListLiveData;//宸茬粡瀹屾垚鍒犻櫎鐨勬暟鎹紝鐢ㄤ簬adapter鐨剅emove鎿嶄綔
+
+    //鍒涘缓骞跺垵濮嬪寲ViewModel
     public FamilyMemorabiliaActivityViewModel(@NonNull Application application) {
         super(application);
     }
 
+
+    //DataRepository 鏄竴涓暟鎹粨搴撶被锛岃礋璐g鐞嗘暟鎹殑鑾峰彇鍜屽瓨鍌紝
+    // 璇ユ柟娉曢�氳繃璋冪敤 DataRepository.getInstance() 鏉ヨ幏鍙� DataRepository 鐨勫崟渚嬪疄渚嬶紝骞跺皢鍏惰繑鍥瀖odel銆�
     @Override
     protected DataRepository initModel() {
         return DataRepository.getInstance();
@@ -46,38 +56,100 @@
     /**
      * 鑾峰彇瀹跺ぇ浜嬭
      */
-    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());
+
+
+
+    //getRequestBeanLiveData().getValue() 妫�鏌ヨ姹傛暟鎹殑 LiveData 鏄惁涓虹┖銆�
+    // 濡傛灉涓虹┖锛屽垯鍒涘缓涓�涓柊鐨� FamilyMemorabiliaRequestBean 瀵硅薄锛屽苟灏嗗叾璁剧疆涓� LiveData 鐨勫�硷紝浠ョ‘淇濊姹傛暟鎹笉涓� null銆�
+    public void getFamilyMemorabilia() {
+        if (getRequestBeanLiveData().getValue() == null){
+            getRequestBeanLiveData().setValue(new FamilyMemorabiliaRequestBean());
         }
-        else if (searchType == 4) {
-            queryMap.put("createTime",stringMutableLiveData.getValue());
-        }
-        else if (searchType == 5) {
-            queryMap.put("address",stringMutableLiveData.getValue());
-        }
-        model.getFamilyMemorabilia(queryMap)
+        //璁剧疆璇锋眰鏁版嵁瀵硅薄鐨勯〉鐮佷负 1锛岃〃绀鸿鑾峰彇绗竴椤电殑鏁版嵁銆�
+        getRequestBeanLiveData().getValue().setPageNum(1);
+
+        //閫氳繃model(ViewModel 涓殑鏁版嵁浠撳簱瀵硅薄)鍙戣捣缃戠粶璇锋眰锛屽苟灏嗚姹傛暟鎹浆鎹负 Map 绫诲瀷锛屼互渚垮彂閫佺粰鏈嶅姟鍣ㄣ��
+        model.getFamilyMemorabilia(getRequestBeanLiveData().getValue().toMap())
+
+                //搴旂敤绾跨▼璋冨害鍣紝纭繚瑙傚療鑰呭湪姝g‘鐨勭嚎绋嬩笂杩愯銆�
                 .compose(RxUtils.schedulersTransformer())
-                .subscribe(new Observer<ResultData<FamilyMemorabiliaResponseBean>>() {
+
+                //璁㈤槄杩欎釜缃戠粶璇锋眰鐨勭粨鏋�
+                .subscribe(new Observer<ResultData<PageResponseBean<FamilyMemorabiliaBean>>>() {
+                    @Override
+
+                    //灏嗚闃呭璞℃坊鍔犲埌 addSubscribe() 涓紝浠ヤ究鍦ㄤ笉鍐嶉渶瑕佹椂鍙栨秷璁㈤槄銆�
+                    //鍒涘缓 Disposable 瀵硅薄鏉ョ鐞嗚闃�
+                    // 浣跨敤 Disposable锛屽彲浠ユ湁鏁堝湴绠$悊寮傛鎿嶄綔鐨勭敓鍛藉懆鏈燂紝纭繚璧勬簮鍦ㄤ笉鍐嶉渶瑕佹椂琚纭噴鏀俱��
+
+                    public void onSubscribe(Disposable d) {
+                        addSubscribe(d);
+                    }
+
+
+
+                    @Override
+                    //onNext()澶勭悊鎴愬姛鑾峰彇鏁版嵁鐨勬儏鍐�
+                    public void onNext(ResultData<PageResponseBean<FamilyMemorabiliaBean>> data) {
+                        if (data.getCode() == CODE_SUCCESS){
+                            if (data.getData().getData().isEmpty()){
+
+                                //鏇存柊鐣岄潰鐘舵�佷负 StateViewEnum.DATA_NULL
+                                changeStateView(StateViewEnum.DATA_NULL);
+                            }else {
+                                //闅愯棌鐘舵�佽鍥惧苟灏嗘暟鎹垪琛ㄥ彂甯冨埌 dataListLiveData
+                                changeStateView(StateViewEnum.HIDE);
+                                dataListLiveData.postValue(data.getData().getData());
+                            }
+
+                            //濡傛灉杩斿洖鐨勬暟鎹笉鎴愬姛锛屽垯灏嗘湇鍔″櫒杩斿洖鐨勬秷鎭彂甯冨埌 messageLiveData锛屼互渚块�氱煡鐢ㄦ埛銆�
+                        }else {
+                            messageLiveData.postValue(data.getMsg());
+                        }
+                    }
+
+                    @Override
+                    //onError()澶勭悊鍙戠敓閿欒鐨勬儏鍐碉紝灏嗛敊璇秷鎭彂甯冨埌 messageLiveData銆�
+                    public void onError(Throwable e) {
+                        messageLiveData.postValue(e.getMessage());
+                    }
+
+                    @Override
+                    public void onComplete() {
+
+                    }
+                });
+    }
+    /**
+     * 鍔犺浇鏇村
+     */
+    public void getMoreFamilyMemorabilia() {
+        if (getRequestBeanLiveData().getValue() == null){
+            getRequestBeanLiveData().setValue(new FamilyMemorabiliaRequestBean());
+        }
+        getRequestBeanLiveData().getValue().setPageNum(getRequestBeanLiveData().getValue().getPageNum() + 1);
+        model.getFamilyMemorabilia(getRequestBeanLiveData().getValue().toMap())
+                .compose(RxUtils.schedulersTransformer())
+                .doFinally(new Action() {
+                    @Override
+                    public void run() throws Exception {
+                        changeStateView(StateViewEnum.DATA_FINISH);
+                    }
+                })
+                .subscribe(new Observer<ResultData<PageResponseBean<FamilyMemorabiliaBean>>>() {
                     @Override
                     public void onSubscribe(Disposable d) {
                         addSubscribe(d);
                     }
 
                     @Override
-                    public void onNext(ResultData<FamilyMemorabiliaResponseBean> data) {
+                    public void onNext(ResultData<PageResponseBean<FamilyMemorabiliaBean>> data) {
                         if (data.getCode() == CODE_SUCCESS){
                             if (data.getData().getData().isEmpty()){
-                                changeStateView(StateViewEnum.DATA_NULL);
+                                messageLiveData.postValue("娌℃湁鏇村鏁版嵁浜�");
                             }else {
-                                dataListLiveData.postValue(data.getData().getData());
+                                changeStateView(StateViewEnum.HIDE);
+                                moreListLiveData.postValue(data.getData().getData());
                             }
                         }else {
                             messageLiveData.postValue(data.getMsg());
@@ -98,7 +170,7 @@
     /**
      * 鍒犻櫎瀹跺ぇ浜嬭
      */
-    public void delete() {
+    public void deleteCheckList() {
         List<FamilyMemorabiliaBean> deleteList = getCheckListLiveData().getValue();
         if (deleteList == null){
             return;
@@ -106,7 +178,6 @@
         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>>() {
@@ -118,13 +189,44 @@
                     @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("鍒犻櫎鎴愬姛");
+                            finishDeleteListLiveData.postValue(checkListLiveData.getValue());
                             getCheckListLiveData().postValue(new ArrayList<>());
+                        }else {
+                            messageLiveData.postValue(stringResultData.getMsg());
+                        }
+                    }
+
+                    @Override
+                    public void onError(Throwable e) {
+                        messageLiveData.postValue(e.getMessage());
+                    }
+
+                    @Override
+                    public void onComplete() {
+
+                    }
+                });
+    }
+    /**
+     * 鍒犻櫎鍗曚釜鏁版嵁
+     */
+    public void deleteItem(FamilyMemorabiliaBean bean) {
+        model.deleteFamilyMemorabilia(String.valueOf(bean.getId()))
+                .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 = new ArrayList<>();
+                            list.add(bean);
+                            finishDeleteListLiveData.postValue(list);
+                            messageLiveData.postValue("鍒犻櫎鎴愬姛");
                         }else {
                             messageLiveData.postValue(stringResultData.getMsg());
                         }
@@ -157,6 +259,23 @@
         this.checkListLiveData = checkListLiveData;
     }
 
+    @NonNull    //NonNull 鐢ㄤ簬鏍囪鏂规硶鍙傛暟銆佽繑鍥炲�笺�佸瓧娈垫垨鏂规硶鐨勮繑鍥炵被鍨嬩笉鍏佽涓� null
+
+    //getRequestBeanLiveData() 鑾峰彇涓�涓寘鍚� FamilyMemorabiliaRequestBean 鏁版嵁鐨� MutableLiveData 瀵硅薄銆�
+    public MutableLiveData<FamilyMemorabiliaRequestBean> getRequestBeanLiveData() {
+        if (requestBeanLiveData == null){
+            requestBeanLiveData = new MutableLiveData<>();
+        }
+        if (requestBeanLiveData.getValue() == null){
+            requestBeanLiveData.setValue(new FamilyMemorabiliaRequestBean());
+        }
+        return requestBeanLiveData;
+    }
+
+    public void setRequestBeanLiveData(MutableLiveData<FamilyMemorabiliaRequestBean> requestBeanLiveData) {
+        this.requestBeanLiveData = requestBeanLiveData;
+    }
+
     public MutableLiveData<List<FamilyMemorabiliaBean>> getDataListLiveData() {
         if (dataListLiveData == null){
             dataListLiveData = new MutableLiveData<>();
@@ -168,35 +287,112 @@
         this.dataListLiveData = dataListLiveData;
     }
 
-    public MutableLiveData<String> getStringMutableLiveData() {
-        if (stringMutableLiveData == null){
-            stringMutableLiveData = new MutableLiveData<>();
+    @NonNull
+    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;
     }
 
+    @NonNull
+    public MutableLiveData<Integer> getOperateTypeLiveData() {
+        if (operateTypeLiveData == null){
+            operateTypeLiveData = new MutableLiveData<>();
+            operateTypeLiveData.setValue(0);
+        }
+        return operateTypeLiveData;
+    }
+
+    public void setOperateTypeLiveData(MutableLiveData<Integer> operateTypeLiveData) {
+        this.operateTypeLiveData = operateTypeLiveData;
+    }
+
+    public LiveData<List<FamilyMemorabiliaBean>> getFinishDeleteListLiveData() {
+        if (finishDeleteListLiveData == null){
+            finishDeleteListLiveData = new MutableLiveData<>();
+        }
+        return finishDeleteListLiveData;
+    }
+
+    public void setFinishDeleteListLiveData(MutableLiveData<List<FamilyMemorabiliaBean>> finishDeleteListLiveData) {
+        this.finishDeleteListLiveData = finishDeleteListLiveData;
+    }
+
+    /**
+     * 鏀瑰彉鎺掑簭
+     * @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());
+        List<FamilyMemorabiliaBean> list = getDataListLiveData().getValue();
+        if (list == null || list.isEmpty()){
+            return;
+        }
+        if (b) {
+            // 浠庢柊鍒版棫锛宯ull鎺掓渶鍚�
+            list.sort((o1, o2) -> {
+                String happenTime1 = o1.getHappenTime();
+                String happenTime2 = o2.getHappenTime();
+                if (TextUtils.isEmpty(happenTime1) && TextUtils.isEmpty(happenTime2)) {
+                    return 0;
+                } else if (TextUtils.isEmpty(happenTime1)) {
+                    return 1;
+                } else if (TextUtils.isEmpty(happenTime2)) {
+                    return -1;
+                } else {
+                    Date date1 = Utils.parseDate(happenTime1);
+                    Date date2 = Utils.parseDate(happenTime2);
+                    if (date1 != null && date2 != null) {
+                        return date2.compareTo(date1);
+                    }
+                    return 0;
                 }
             });
-        }else {
-            dataList.sort(new Comparator<FamilyMemorabiliaBean>() {
-                @Override
-                public int compare(FamilyMemorabiliaBean o1, FamilyMemorabiliaBean o2) {
-                    return (int) (o2.getId() - o1.getId());
+        } else  {
+            // 浠庢棫鍒版柊锛宯ull鎺掓渶鍓�
+            list.sort((o1, o2) -> {
+                String happenTime1 = o1.getHappenTime();
+                String happenTime2 = o2.getHappenTime();
+                if (TextUtils.isEmpty(happenTime1) && TextUtils.isEmpty(happenTime2)) {
+                    return 0;
+                } else if (TextUtils.isEmpty(happenTime1)) {
+                    return -1;
+                } else if (TextUtils.isEmpty(happenTime2)) {
+                    return 1;
+                } else {
+                    Date date1 = Utils.parseDate(happenTime1);
+                    Date date2 = Utils.parseDate(happenTime2);
+                    if (date1 != null && date2 != null) {
+                        return date1.compareTo(date2);
+                    }
+                    return 0;
                 }
             });
         }
-        getDataListLiveData().postValue(dataList);
+        getDataListLiveData().setValue(list);
+    }
+
+    /**
+     * 鏈鏁版嵁 缃《
+     */
+    public void ownTop(){
+        List<FamilyMemorabiliaBean> list = getDataListLiveData().getValue();
+        if (list == null || list.isEmpty()){
+            return;
+        }
+        //鏍规嵁ownData鍊间负1鐨� 鏀惧埌鍓嶉潰
+        list.sort((o1, o2) -> {
+            if (o1.getOwnData() == 1 && o2.getOwnData() == 0) {
+                return -1;
+            } else if (o1.getOwnData() == 0 && o2.getOwnData() == 1) {
+                return 1;
+            }
+            return 0;
+        });
+        getDataListLiveData().setValue(list);
     }
 }

--
Gitblit v1.9.1