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/LittleDoctorActivityViewModel.java | 263 ++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 240 insertions(+), 23 deletions(-)
diff --git a/app/src/main/java/com/application/zhangshi_app_android/ui/function/LittleDoctorActivityViewModel.java b/app/src/main/java/com/application/zhangshi_app_android/ui/function/LittleDoctorActivityViewModel.java
index 5be8866..5114513 100644
--- a/app/src/main/java/com/application/zhangshi_app_android/ui/function/LittleDoctorActivityViewModel.java
+++ b/app/src/main/java/com/application/zhangshi_app_android/ui/function/LittleDoctorActivityViewModel.java
@@ -12,22 +12,21 @@
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.FamilyMemorabiliaRequestBean;
-import com.application.zhangshi_app_android.bean.FamilyMemorabiliaResponseBean;
-import com.application.zhangshi_app_android.bean.HomeDevicesResponseBean;
-import com.application.zhangshi_app_android.bean.HonorCollectionBean;
-import com.application.zhangshi_app_android.bean.HonorCollectionResponseBean;
+import com.application.zhangshi_app_android.bean.FamilyMemorabiliaBean;
import com.application.zhangshi_app_android.bean.LittleDoctorBean;
import com.application.zhangshi_app_android.bean.LittleDoctorRequestBean;
-import com.application.zhangshi_app_android.bean.LittleDoctorResponseBean;
+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.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
@@ -36,9 +35,13 @@
*/
public class LittleDoctorActivityViewModel extends BaseViewModel<DataRepository> {
- private MutableLiveData<List<LittleDoctorBean>> dataListLiveData;
+ private MutableLiveData<List<LittleDoctorBean>> dataListLiveData;//鑾峰彇鐨勬暟鎹�
+ private MutableLiveData<List<LittleDoctorBean>> checkListLiveData;//閫変腑鐨勬暟鎹�
+ private MutableLiveData<List<LittleDoctorBean>> moreListLiveData;//涓嬫媺鍔犺浇鏁版嵁
+ private MutableLiveData<LittleDoctorRequestBean> requestBeanLiveData;//璇锋眰鍙傛暟
+ private MutableLiveData<List<LittleDoctorBean>> finishDeleteListLiveData;//宸茬粡瀹屾垚鍒犻櫎鐨勬暟鎹紝鐢ㄤ簬adapter鐨剅emove鎿嶄綔
- private LittleDoctorRequestBean requestBean = new LittleDoctorRequestBean();
+ private MutableLiveData<Integer> operateTypeLiveData;//鎿嶄綔绫诲瀷 0 閫夋嫨鎿嶄綔 1.瀹屾垚 2.鍒犻櫎
public LittleDoctorActivityViewModel(@NonNull Application application) {
super(application);
@@ -48,29 +51,25 @@
protected DataRepository initModel() {
return DataRepository.getInstance();
}
-
- public MutableLiveData<List<LittleDoctorBean>> getDataListLiveData() {
- if (dataListLiveData == null){
- dataListLiveData = new MutableLiveData<>();
- }
- return dataListLiveData;
- }
-
- public void setDataListLiveData(MutableLiveData<List<LittleDoctorBean>> dataListLiveData) {
- this.dataListLiveData = dataListLiveData;
- }
-
+
+ /**
+ * 鑾峰彇鏁版嵁
+ */
public void getLittleDoctors() {
- model.getLittleDoctors(requestBean.toMap())
+ if (getRequestBeanLiveData().getValue() == null){
+ getRequestBeanLiveData().setValue(new LittleDoctorRequestBean());
+ }
+ getRequestBeanLiveData().getValue().setPageNum(1);
+ model.getLittleDoctors(getRequestBeanLiveData().getValue().toMap())
.compose(RxUtils.schedulersTransformer())
- .subscribe(new Observer<ResultData<LittleDoctorResponseBean>>() {
+ .subscribe(new Observer<ResultData<PageResponseBean<LittleDoctorBean>>>() {
@Override
public void onSubscribe(Disposable d) {
addSubscribe(d);
}
@Override
- public void onNext(ResultData<LittleDoctorResponseBean> data) {
+ public void onNext(ResultData<PageResponseBean<LittleDoctorBean>> data) {
if (data.getCode() == CODE_SUCCESS){
if (data.getData().getData().isEmpty()){
changeStateView(StateViewEnum.DATA_NULL);
@@ -94,6 +93,224 @@
}
});
}
+ /**
+ * 鍔犺浇鏇村
+ */
+ public void getMoreLittleDoctors() {
+ if (getRequestBeanLiveData().getValue() == null){
+ getRequestBeanLiveData().setValue(new LittleDoctorRequestBean());
+ }
+ getRequestBeanLiveData().getValue().setPageNum(getRequestBeanLiveData().getValue().getPageNum() + 1);
+ model.getLittleDoctors(getRequestBeanLiveData().getValue().toMap())
+ .compose(RxUtils.schedulersTransformer())
+ .doFinally(new Action() {
+ @Override
+ public void run() throws Exception {
+ changeStateView(StateViewEnum.DATA_FINISH);
+ }
+ })
+ .subscribe(new Observer<ResultData<PageResponseBean<LittleDoctorBean>>>() {
+ @Override
+ public void onSubscribe(Disposable d) {
+ addSubscribe(d);
+ }
+ @Override
+ public void onNext(ResultData<PageResponseBean<LittleDoctorBean>> 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 deleteCheckList() {
+ List<LittleDoctorBean> deleteList = getCheckListLiveData().getValue();
+ if (deleteList == null){
+ return;
+ }
+ StringBuffer sb = new StringBuffer();
+ deleteList.forEach(LittleDoctorBean -> sb.append(LittleDoctorBean.getId()).append(","));
+ sb.deleteCharAt(sb.length()-1);
+ model.deleteLittleDoctors(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){
+ finishDeleteListLiveData.postValue(checkListLiveData.getValue());
+ 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 void deleteItem(LittleDoctorBean littleDoctorBean) {
+ model.deleteLittleDoctors(String.valueOf(littleDoctorBean.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<LittleDoctorBean> list = new ArrayList<>();
+ list.add(littleDoctorBean);
+ finishDeleteListLiveData.postValue(list);
+ messageLiveData.postValue("鍒犻櫎鎴愬姛");
+ }else {
+ messageLiveData.postValue(stringResultData.getMsg());
+ }
+ }
+
+ @Override
+ public void onError(Throwable e) {
+ messageLiveData.postValue(e.getMessage());
+ }
+
+ @Override
+ public void onComplete() {
+
+ }
+ });
+ }
+
+ public MutableLiveData<List<LittleDoctorBean>> 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<LittleDoctorBean>> checkListLiveData) {
+ this.checkListLiveData = checkListLiveData;
+ }
+
+ @NonNull
+ public MutableLiveData<LittleDoctorRequestBean> getRequestBeanLiveData() {
+ if (requestBeanLiveData == null){
+ requestBeanLiveData = new MutableLiveData<>();
+ }
+ if (requestBeanLiveData.getValue() == null){
+ requestBeanLiveData.setValue(new LittleDoctorRequestBean());
+ }
+ return requestBeanLiveData;
+ }
+
+ public void setRequestBeanLiveData(MutableLiveData<LittleDoctorRequestBean> requestBeanLiveData) {
+ this.requestBeanLiveData = requestBeanLiveData;
+ }
+
+ public MutableLiveData<List<LittleDoctorBean>> getDataListLiveData() {
+ if (dataListLiveData == null){
+ dataListLiveData = new MutableLiveData<>();
+ }
+ return dataListLiveData;
+ }
+
+ public void setDataListLiveData(MutableLiveData<List<LittleDoctorBean>> dataListLiveData) {
+ this.dataListLiveData = dataListLiveData;
+ }
+
+ @NonNull
+ public MutableLiveData<List<LittleDoctorBean>> getMoreListLiveData() {
+ if (moreListLiveData == null){
+ moreListLiveData = new MutableLiveData<>();
+ }
+ return moreListLiveData;
+ }
+
+ public void setMoreListLiveData(MutableLiveData<List<LittleDoctorBean>> 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<LittleDoctorBean>> getFinishDeleteListLiveData() {
+ if (finishDeleteListLiveData == null){
+ finishDeleteListLiveData = new MutableLiveData<>();
+ }
+ return finishDeleteListLiveData;
+ }
+
+ public void setFinishDeleteListLiveData(MutableLiveData<List<LittleDoctorBean>> finishDeleteListLiveData) {
+ this.finishDeleteListLiveData = finishDeleteListLiveData;
+ }
+
+ /**
+ * 鏈鏁版嵁 缃《
+ */
+ public void ownTop(){
+ List<LittleDoctorBean> 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