From e6014ef123350d5c0cadabe9c18e26b3d5a3c729 Mon Sep 17 00:00:00 2001
From: guoshen <3129367635@qq.com>
Date: 星期六, 29 六月 2024 15:41:25 +0800
Subject: [PATCH] Revert "Initial commit"
---
app/src/main/java/com/application/zhangshi_app_android/ui/function/HonorCollectionActivityViewModel.java | 189 +++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 175 insertions(+), 14 deletions(-)
diff --git a/app/src/main/java/com/application/zhangshi_app_android/ui/function/HonorCollectionActivityViewModel.java b/app/src/main/java/com/application/zhangshi_app_android/ui/function/HonorCollectionActivityViewModel.java
index d12ded7..f7a84d1 100644
--- a/app/src/main/java/com/application/zhangshi_app_android/ui/function/HonorCollectionActivityViewModel.java
+++ b/app/src/main/java/com/application/zhangshi_app_android/ui/function/HonorCollectionActivityViewModel.java
@@ -3,6 +3,7 @@
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;
@@ -12,18 +13,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.HomeDevicesResponseBean;
+import com.android.app_base.utils.Utils;
+import com.application.zhangshi_app_android.bean.FamilyMemorabiliaBean;
import com.application.zhangshi_app_android.bean.HonorCollectionBean;
import com.application.zhangshi_app_android.bean.HonorCollectionRequestBean;
import com.application.zhangshi_app_android.bean.HonorCollectionResponseBean;
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 io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
+import io.reactivex.functions.Action;
/**
* @author Ljj
@@ -31,9 +39,10 @@
* @desc 鑽h獕鏀惰棌 ViewModel
*/
public class HonorCollectionActivityViewModel extends BaseViewModel<DataRepository> {
+ private MutableLiveData<List<HonorCollectionBean>> dataListLiveData;//鎵�鏈夋暟鎹�
+ private MutableLiveData<List<HonorCollectionBean>> moreListLiveData;//鍔犺浇鏇村鏁版嵁
- private MutableLiveData<List<HonorCollectionBean>> dataListLiveData;
- private HonorCollectionRequestBean requestBean = new HonorCollectionRequestBean();
+ private MutableLiveData<HonorCollectionRequestBean> requestBeanLiveData;//璇锋眰鍙傛暟
public HonorCollectionActivityViewModel(@NonNull Application application) {
super(application);
@@ -44,19 +53,16 @@
return DataRepository.getInstance();
}
- public MutableLiveData<List<HonorCollectionBean>> getDataListLiveData() {
- if (dataListLiveData == null){
- dataListLiveData = new MutableLiveData<>();
- }
- return dataListLiveData;
- }
- public void setDataListLiveData(MutableLiveData<List<HonorCollectionBean>> dataListLiveData) {
- this.dataListLiveData = dataListLiveData;
- }
-
+ /**
+ * 鑾峰彇鑽h獕鏀惰棌
+ */
public void getHonorCollections() {
- model.getHonorCollections(requestBean.toMap())
+ if (getRequestBeanLiveData().getValue() == null){
+ getRequestBeanLiveData().setValue(new HonorCollectionRequestBean());
+ }
+ getRequestBeanLiveData().getValue().setPageNum(1);
+ model.getHonorCollections(getRequestBeanLiveData().getValue().toMap())
.compose(RxUtils.schedulersTransformer())
.subscribe(new Observer<ResultData<HonorCollectionResponseBean>>() {
@Override
@@ -89,4 +95,159 @@
}
});
}
+ /**
+ * 鍔犺浇鏇村
+ */
+ public void loadMoreHonorCollections(){
+ if (getRequestBeanLiveData().getValue() == null){
+ getRequestBeanLiveData().setValue(new HonorCollectionRequestBean());
+ }
+ getRequestBeanLiveData().getValue().setPageNum(getRequestBeanLiveData().getValue().getPageNum() + 1);
+ model.getHonorCollections(getRequestBeanLiveData().getValue().toMap())
+ .compose(RxUtils.schedulersTransformer())
+ .doFinally(new Action() {
+ @Override
+ public void run() throws Exception {
+ changeStateView(StateViewEnum.DATA_FINISH);
+ }
+ })
+ .subscribe(new Observer<ResultData<HonorCollectionResponseBean>>() {
+ @Override
+ public void onSubscribe(Disposable d) {
+ addSubscribe(d);
+ }
+
+ @Override
+ public void onNext(ResultData<HonorCollectionResponseBean> 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 MutableLiveData<List<HonorCollectionBean>> getDataListLiveData() {
+ if (dataListLiveData == null){
+ dataListLiveData = new MutableLiveData<>();
+ }
+ return dataListLiveData;
+ }
+ public void setDataListLiveData(MutableLiveData<List<HonorCollectionBean>> dataListLiveData) {
+ this.dataListLiveData = dataListLiveData;
+ }
+ public MutableLiveData<HonorCollectionRequestBean> getRequestBeanLiveData() {
+ if (requestBeanLiveData == null){
+ requestBeanLiveData = new MutableLiveData<>();
+ }
+ if (requestBeanLiveData.getValue() == null){
+ requestBeanLiveData.setValue(new HonorCollectionRequestBean());
+ }
+ return requestBeanLiveData;
+ }
+
+ public void setRequestBeanLiveData(MutableLiveData<HonorCollectionRequestBean> requestBeanLiveData) {
+ this.requestBeanLiveData = requestBeanLiveData;
+ }
+
+
+
+ public MutableLiveData<List<HonorCollectionBean>> getMoreListLiveData() {
+ if (moreListLiveData == null){
+ moreListLiveData = new MutableLiveData<>();
+ }
+ return moreListLiveData;
+ }
+
+ public void setMoreListLiveData(MutableLiveData<List<HonorCollectionBean>> moreListLiveData) {
+ this.moreListLiveData = moreListLiveData;
+ }
+
+ /**
+ * 鎺掑簭
+ * @param type 0 浠庢柊鍒版棫 1 浠庢棫鍒版柊
+ */
+ public void sortDataList(int type){
+ List<HonorCollectionBean> list = dataListLiveData.getValue();
+ if (list == null || list.isEmpty()){
+ return;
+ }
+ if (type == 0) {
+ // 浠庢柊鍒版棫锛宯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 if (type == 1) {
+ // 浠庢棫鍒版柊锛宯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;
+ }
+ });
+ }
+ dataListLiveData.setValue(list);
+ }
+
+ /**
+ * 鏈鏁版嵁 缃《
+ */
+ public void ownTop(){
+ List<HonorCollectionBean> 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