From 31b7700b976a46901f67c5d7a00281ca4745fc9f Mon Sep 17 00:00:00 2001 From: Linjiajia <319408893@qq.com> Date: 星期六, 07 十月 2023 21:44:35 +0800 Subject: [PATCH] 调整旅游模块功能 --- app/src/main/java/com/application/zhangshi_app_android/ui/function/PersonalNotepadActivityViewModel.java | 319 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 302 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/application/zhangshi_app_android/ui/function/PersonalNotepadActivityViewModel.java b/app/src/main/java/com/application/zhangshi_app_android/ui/function/PersonalNotepadActivityViewModel.java index 3d5fe9f..1132b4f 100644 --- a/app/src/main/java/com/application/zhangshi_app_android/ui/function/PersonalNotepadActivityViewModel.java +++ b/app/src/main/java/com/application/zhangshi_app_android/ui/function/PersonalNotepadActivityViewModel.java @@ -1,17 +1,31 @@ package com.application.zhangshi_app_android.ui.function; +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.PersonalNotepadRequestBean; +import com.application.zhangshi_app_android.bean.PageResponseBean; import com.application.zhangshi_app_android.bean.PersonalNotepadBean; -import com.application.zhangshi_app_android.bean.PrivacyBean; import com.application.zhangshi_app_android.data.DataRepository; import java.util.ArrayList; +import java.util.Date; import java.util.List; + +import io.reactivex.Observer; +import io.reactivex.disposables.Disposable; +import io.reactivex.functions.Action; /** * @author Ljj @@ -20,7 +34,12 @@ */ public class PersonalNotepadActivityViewModel extends BaseViewModel<DataRepository> { private MutableLiveData<List<PersonalNotepadBean>> dataListLiveData; + private MutableLiveData<List<PersonalNotepadBean>> checkListLiveData;//閫変腑鐨勬暟鎹� + private MutableLiveData<List<PersonalNotepadBean>> moreListLiveData;//涓嬫媺鍔犺浇鏁版嵁 + private MutableLiveData<PersonalNotepadRequestBean> requestBeanLiveData;//璇锋眰鍙傛暟 + private MutableLiveData<List<PersonalNotepadBean>> finishDeleteListLiveData;//宸茬粡瀹屾垚鍒犻櫎鐨勬暟鎹紝鐢ㄤ簬adapter鐨剅emove鎿嶄綔 + private MutableLiveData<Integer> operateTypeLiveData;//鎿嶄綔绫诲瀷 0 閫夋嫨鎿嶄綔 1.瀹屾垚 2.鍒犻櫎 public PersonalNotepadActivityViewModel(@NonNull Application application) { super(application); } @@ -30,8 +49,203 @@ return DataRepository.getInstance(); } + /** + * 鑾峰彇鏁版嵁 + */ + public void getPersonalNotepads() { + if (getRequestBeanLiveData().getValue() == null){ + getRequestBeanLiveData().setValue(new PersonalNotepadRequestBean()); + } + getRequestBeanLiveData().getValue().setPageNum(1); + model.getPersonalNotepad(getRequestBeanLiveData().getValue().toMap()) + .compose(RxUtils.schedulersTransformer()) + .subscribe(new Observer<ResultData<PageResponseBean<PersonalNotepadBean>>>() { + @Override + public void onSubscribe(Disposable d) { + addSubscribe(d); + } + + @Override + public void onNext(ResultData<PageResponseBean<PersonalNotepadBean>> 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 getMorePersonalNotepads() { + if (getRequestBeanLiveData().getValue() == null){ + getRequestBeanLiveData().setValue(new PersonalNotepadRequestBean()); + } + getRequestBeanLiveData().getValue().setPageNum(getRequestBeanLiveData().getValue().getPageNum() + 1); + model.getPersonalNotepad(getRequestBeanLiveData().getValue().toMap()) + .compose(RxUtils.schedulersTransformer()) + .doFinally(new Action() { + @Override + public void run() throws Exception { + changeStateView(StateViewEnum.DATA_FINISH); + } + }) + .subscribe(new Observer<ResultData<PageResponseBean<PersonalNotepadBean>>>() { + @Override + public void onSubscribe(Disposable d) { + addSubscribe(d); + } + + @Override + public void onNext(ResultData<PageResponseBean<PersonalNotepadBean>> 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<PersonalNotepadBean> deleteList = getCheckListLiveData().getValue(); + if (deleteList == null){ + return; + } + StringBuffer sb = new StringBuffer(); + deleteList.forEach(PersonalNotepadBean -> sb.append(PersonalNotepadBean.getId()).append(",")); + sb.deleteCharAt(sb.length()-1); + model.deletePersonalNotepad(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(PersonalNotepadBean PersonalNotepadBean) { + model.deletePersonalNotepad(String.valueOf(PersonalNotepadBean.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<PersonalNotepadBean> list = new ArrayList<>(); + list.add(PersonalNotepadBean); + 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<PersonalNotepadBean>> 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<PersonalNotepadBean>> checkListLiveData) { + this.checkListLiveData = checkListLiveData; + } + + @NonNull + public MutableLiveData<PersonalNotepadRequestBean> getRequestBeanLiveData() { + if (requestBeanLiveData == null){ + requestBeanLiveData = new MutableLiveData<>(); + } + if (requestBeanLiveData.getValue() == null){ + requestBeanLiveData.setValue(new PersonalNotepadRequestBean()); + } + return requestBeanLiveData; + } + + public void setRequestBeanLiveData(MutableLiveData<PersonalNotepadRequestBean> requestBeanLiveData) { + this.requestBeanLiveData = requestBeanLiveData; + } + public MutableLiveData<List<PersonalNotepadBean>> getDataListLiveData() { - if (dataListLiveData == null) { + if (dataListLiveData == null){ dataListLiveData = new MutableLiveData<>(); } return dataListLiveData; @@ -41,21 +255,92 @@ this.dataListLiveData = dataListLiveData; } - /** - * 鑾峰彇涓汉璁颁簨鏈垪琛� - */ - public void getPersonalNotepads() { - List<PersonalNotepadBean> beans = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - PersonalNotepadBean bean = new PersonalNotepadBean(); - bean.setId(i); - bean.setTitle("鏍囬"+i); - bean.setPerson("寮犱笁"+i); - bean.setTime("2020-05-14 20:00:00"); - bean.setPlace("鍖椾含甯傛捣娣�鍖�"+i); - bean.setRemark("澶囨敞"+i); - beans.add(bean); + @NonNull + public MutableLiveData<List<PersonalNotepadBean>> getMoreListLiveData() { + if (moreListLiveData == null){ + moreListLiveData = new MutableLiveData<>(); } - dataListLiveData.setValue(beans); + return moreListLiveData; + } + + public void setMoreListLiveData(MutableLiveData<List<PersonalNotepadBean>> 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<PersonalNotepadBean>> getFinishDeleteListLiveData() { + if (finishDeleteListLiveData == null){ + finishDeleteListLiveData = new MutableLiveData<>(); + } + return finishDeleteListLiveData; + } + + public void setFinishDeleteListLiveData(MutableLiveData<List<PersonalNotepadBean>> finishDeleteListLiveData) { + this.finishDeleteListLiveData = finishDeleteListLiveData; + } + + /** + * 鏀瑰彉鎺掑簭 + * @param b true 闄嶅簭 false 鍗囧簭 + */ + public void changeOrder(boolean b) { + List<PersonalNotepadBean> 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 { + // 浠庢棫鍒版柊锛宯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().setValue(list); } } -- Gitblit v1.9.1