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/HealthCareActivityViewModel.java | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 237 insertions(+), 2 deletions(-)
diff --git a/app/src/main/java/com/application/zhangshi_app_android/ui/function/HealthCareActivityViewModel.java b/app/src/main/java/com/application/zhangshi_app_android/ui/function/HealthCareActivityViewModel.java
index bf13299..08e2ff0 100644
--- a/app/src/main/java/com/application/zhangshi_app_android/ui/function/HealthCareActivityViewModel.java
+++ b/app/src/main/java/com/application/zhangshi_app_android/ui/function/HealthCareActivityViewModel.java
@@ -1,12 +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 androidx.annotation.NonNull;
+import androidx.databinding.Bindable;
+import androidx.databinding.InverseBindingAdapter;
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.HealthCareBaseInfoBean;
+import com.application.zhangshi_app_android.bean.HealthCareExistingProblemsBean;
+import com.application.zhangshi_app_android.bean.HealthCareLifeHabitsBean;
+import com.application.zhangshi_app_android.bean.HealthCareNotesContentBean;
+import com.application.zhangshi_app_android.bean.HealthCareNursingExaminationBean;
+import com.application.zhangshi_app_android.bean.HomeDevicesBean;
+import com.application.zhangshi_app_android.bean.PageResponseBean;
import com.application.zhangshi_app_android.data.DataRepository;
+
+import io.reactivex.Observable;
+import io.reactivex.Observer;
+import io.reactivex.disposables.Disposable;
+import io.reactivex.functions.Function5;
/**
* @author Ljj
@@ -15,11 +34,15 @@
*/
public class HealthCareActivityViewModel extends BaseViewModel<DataRepository> {
+ private MutableLiveData<Boolean> typeLiveData;//true:缂栬緫 false:鏌ョ湅
+ private MutableLiveData<HealthCareBaseInfoBean> healthCareBaseInfoBeanLiveData;//鍋ュ悍淇濆仴鍩烘湰淇℃伅
+ private MutableLiveData<HealthCareLifeHabitsBean> healthCareLifeHabitsBeanLiveData;//鍋ュ悍淇濆仴鐢熸椿涔犳儻
+ private MutableLiveData<HealthCareNursingExaminationBean> healthCareNursingExaminationBeanLiveData;//鍋ュ悍淇濆仴鎶ょ悊妫�鏌�
+ private MutableLiveData<HealthCareExistingProblemsBean> healthCareExistingProblemsBeanLiveData;//鍋ュ悍淇濆仴鐜板瓨闂
+ private MutableLiveData<HealthCareNotesContentBean> healthCareNotesContentBeanLiveData;//鍋ュ悍淇濆仴绗旇鍐呭
private MutableLiveData<Boolean> isLifeHabitsExpendedLiveData;
private MutableLiveData<Boolean> isNursingExpendedLiveData;
private MutableLiveData<Boolean> isHealthExpendedLiveData;
-
-
public HealthCareActivityViewModel(@NonNull Application application) {
super(application);
@@ -28,6 +51,144 @@
@Override
protected DataRepository initModel() {
return DataRepository.getInstance();
+ }
+
+ public <T> Observer<ResultData<T>> getObserver(MutableLiveData<T> resultData,T newBean) {
+ return new Observer<ResultData<T>>() {
+ @Override
+ public void onSubscribe(Disposable d) {
+ addSubscribe(d);
+ }
+
+ @Override
+ public void onNext(ResultData<T> data) {
+ if (data.getCode() == CODE_SUCCESS) {
+ if (data.getData() == null) {
+ changeStateView(StateViewEnum.DATA_NULL);
+ } else {
+ changeStateView(StateViewEnum.HIDE);
+ resultData.postValue(data.getData());
+ }
+ } else if (data.getCode() == 500) {//鐢ㄦ埛杩樻病鏈夊~鍐欏仴搴蜂繚鍋ヤ俊鎭紝鐩存帴缁欎釜鏂扮殑瀵硅薄灞曠ず渚涚敤鎴蜂慨鏀�
+ resultData.postValue(newBean);
+ } else {
+ messageLiveData.postValue(data.getMsg());
+ }
+ }
+
+ @Override
+ public void onError(Throwable e) {
+ messageLiveData.postValue(e.getMessage());
+ }
+
+ @Override
+ public void onComplete() {
+
+ }
+ };
+ }
+
+ /**
+ * 鑾峰彇鍋ュ悍淇濆仴鍩烘湰淇℃伅
+ */
+ public void getHealthCareBaseInfo() {
+ model.getHealthCareBaseInfo()
+ .compose(RxUtils.schedulersTransformer())
+ .doOnSubscribe(disposable -> changeStateView(StateViewEnum.DATA_LOADING))
+ .doFinally(() -> changeStateView(StateViewEnum.DATA_FINISH))
+ .subscribe(getObserver(getHealthCareBaseInfoBeanLiveData(),new HealthCareBaseInfoBean()));
+ }
+
+ /**
+ * 鑾峰彇鍋ュ悍淇濆仴鐢熸椿涔犳儻
+ */
+ public void getHealthCareLifeHabits() {
+ model.getHealthCareLifeHabits()
+ .compose(RxUtils.schedulersTransformer())
+ .doOnSubscribe(disposable -> changeStateView(StateViewEnum.DATA_LOADING))
+ .doFinally(() -> changeStateView(StateViewEnum.DATA_FINISH))
+ .subscribe(getObserver(getHealthCareLifeHabitsBeanLiveData(),new HealthCareLifeHabitsBean()));
+ }
+
+ /**
+ * 鑾峰彇鍋ュ悍淇濆仴鎶ょ悊鏌ヤ綋
+ */
+ public void getHealthCareNursingExamination() {
+ model.getHealthCareNursingExamination()
+ .compose(RxUtils.schedulersTransformer())
+ .doOnSubscribe(disposable -> changeStateView(StateViewEnum.DATA_LOADING))
+ .doFinally(() -> changeStateView(StateViewEnum.DATA_FINISH))
+ .subscribe(getObserver(getHealthCareNursingExaminationBeanLiveData(),new HealthCareNursingExaminationBean()));
+ }
+
+ /**
+ * 鑾峰彇鍋ュ悍淇濆仴鐜板瓨闂
+ */
+ public void getHealthCareExistingProblems() {
+ model.getHealthCareExistingProblems()
+ .compose(RxUtils.schedulersTransformer())
+ .doOnSubscribe(disposable -> changeStateView(StateViewEnum.DATA_LOADING))
+ .doFinally(() -> changeStateView(StateViewEnum.DATA_FINISH))
+ .subscribe(getObserver(getHealthCareExistingProblemsBeanLiveData(),new HealthCareExistingProblemsBean()));
+ }
+
+ /**
+ * 鑾峰彇鍋ュ悍淇濆仴绗旇鍐呭
+ */
+ public void getHealthCareNotesContent() {
+ model.getHealthCareNotesContent()
+ .compose(RxUtils.schedulersTransformer())
+ .doOnSubscribe(disposable -> changeStateView(StateViewEnum.DATA_LOADING))
+ .doFinally(() -> changeStateView(StateViewEnum.DATA_FINISH))
+ .subscribe(getObserver(getHealthCareNotesContentBeanLiveData(),new HealthCareNotesContentBean()));
+ }
+
+ /**
+ * 淇敼淇濆瓨
+ */
+ public void save(){
+ Observable.zip(
+ model.updateHealthCareBaseInfo(getHealthCareBaseInfoBeanLiveData().getValue()),
+ model.updateHealthCareLifeHabits(getHealthCareLifeHabitsBeanLiveData().getValue()),
+ model.updateHealthCareNursingExamination(getHealthCareNursingExaminationBeanLiveData().getValue()),
+ model.updateHealthCareExistingProblems(getHealthCareExistingProblemsBeanLiveData().getValue()),
+ model.updateHealthCareNotesContent(getHealthCareNotesContentBeanLiveData().getValue()),
+ new Function5<ResultData<String>, ResultData<String>, ResultData<String>, ResultData<String>, ResultData<String>, String>() {
+ @Override
+ public String apply(ResultData<String> stringResultData, ResultData<String> stringResultData2, ResultData<String> stringResultData3, ResultData<String> stringResultData4, ResultData<String> stringResultData5) throws Exception {
+ if (stringResultData.getCode() == CODE_SUCCESS
+ && stringResultData2.getCode() == CODE_SUCCESS
+ && stringResultData3.getCode() == CODE_SUCCESS
+ && stringResultData4.getCode() == CODE_SUCCESS
+ && stringResultData5.getCode() == CODE_SUCCESS) {
+ return "淇濆瓨鎴愬姛";
+ } else {
+ throw new Exception("淇濆瓨澶辫触");
+ }
+ }
+ }
+ ).compose(RxUtils.schedulersTransformer()).subscribe(new Observer<String>() {
+ @Override
+ public void onSubscribe(Disposable d) {
+ addSubscribe(d);
+ changeStateView(StateViewEnum.DATA_LOADING);
+ }
+
+ @Override
+ public void onNext(String s) {
+ messageLiveData.postValue(s);
+ }
+
+ @Override
+ public void onError(Throwable e) {
+ messageLiveData.postValue(e.getMessage());
+ }
+
+ @Override
+ public void onComplete() {
+ changeStateView(StateViewEnum.DATA_FINISH);
+ }
+ });
}
public MutableLiveData<Boolean> getIsLifeHabitsExpendedLiveData() {
@@ -65,4 +226,78 @@
public void setIsHealthExpendedLiveData(MutableLiveData<Boolean> isHealthExpendedLiveData) {
this.isHealthExpendedLiveData = isHealthExpendedLiveData;
}
+
+ public MutableLiveData<HealthCareBaseInfoBean> getHealthCareBaseInfoBeanLiveData() {
+ if (healthCareBaseInfoBeanLiveData == null){
+ healthCareBaseInfoBeanLiveData = new MutableLiveData<>();
+ }
+ return healthCareBaseInfoBeanLiveData;
+ }
+
+ public void setHealthCareBaseInfoBeanLiveData(MutableLiveData<HealthCareBaseInfoBean> healthCareBaseInfoBeanLiveData) {
+ this.healthCareBaseInfoBeanLiveData = healthCareBaseInfoBeanLiveData;
+ }
+
+ public MutableLiveData<HealthCareLifeHabitsBean> getHealthCareLifeHabitsBeanLiveData() {
+ if (healthCareLifeHabitsBeanLiveData == null){
+ healthCareLifeHabitsBeanLiveData = new MutableLiveData<>();
+ }
+ return healthCareLifeHabitsBeanLiveData;
+ }
+
+ public void setHealthCareLifeHabitsBeanLiveData(MutableLiveData<HealthCareLifeHabitsBean> healthCareLifeHabitsBeanLiveData) {
+ this.healthCareLifeHabitsBeanLiveData = healthCareLifeHabitsBeanLiveData;
+ }
+
+ public MutableLiveData<HealthCareNursingExaminationBean> getHealthCareNursingExaminationBeanLiveData() {
+ if (healthCareNursingExaminationBeanLiveData == null){
+ healthCareNursingExaminationBeanLiveData = new MutableLiveData<>();
+ }
+ return healthCareNursingExaminationBeanLiveData;
+ }
+
+ public void setHealthCareNursingExaminationBeanLiveData(MutableLiveData<HealthCareNursingExaminationBean> healthCareNursingExaminationBeanLiveData) {
+ this.healthCareNursingExaminationBeanLiveData = healthCareNursingExaminationBeanLiveData;
+ }
+
+ public MutableLiveData<HealthCareExistingProblemsBean> getHealthCareExistingProblemsBeanLiveData() {
+ if (healthCareExistingProblemsBeanLiveData == null){
+ healthCareExistingProblemsBeanLiveData = new MutableLiveData<>();
+ }
+ return healthCareExistingProblemsBeanLiveData;
+ }
+
+ public void setHealthCareExistingProblemsBeanLiveData(MutableLiveData<HealthCareExistingProblemsBean> healthCareExistingProblemsBeanLiveData) {
+ this.healthCareExistingProblemsBeanLiveData = healthCareExistingProblemsBeanLiveData;
+ }
+
+ public MutableLiveData<HealthCareNotesContentBean> getHealthCareNotesContentBeanLiveData() {
+ if (healthCareNotesContentBeanLiveData == null){
+ healthCareNotesContentBeanLiveData = new MutableLiveData<>();
+ }
+ return healthCareNotesContentBeanLiveData;
+ }
+
+ public void setHealthCareNotesContentBeanLiveData(MutableLiveData<HealthCareNotesContentBean> healthCareNotesContentBeanLiveData) {
+ this.healthCareNotesContentBeanLiveData = healthCareNotesContentBeanLiveData;
+ }
+
+ public MutableLiveData<Boolean> getTypeLiveData() {
+ if (typeLiveData == null){
+ typeLiveData = new MutableLiveData<>();
+ typeLiveData.setValue(false);
+ }
+ return typeLiveData;
+ }
+
+ public void setTypeLiveData(MutableLiveData<Boolean> typeLiveData) {
+ this.typeLiveData = typeLiveData;
+ }
+
+ public void setTypeLiveData(boolean type) {
+ if (typeLiveData == null){
+ typeLiveData = new MutableLiveData<>();
+ }
+ typeLiveData.setValue(type);
+ }
}
--
Gitblit v1.9.1