From f21e1ae4b858b6a329b717eaf420d4a1e79d9509 Mon Sep 17 00:00:00 2001 From: Guo_shaoshan <2055829622@qq.com> Date: 星期一, 24 四月 2023 15:53:47 +0800 Subject: [PATCH] 自传和通讯录界面(未完成未修改) --- app/src/main/java/com/application/zhangshi_app_android/ui/function/GrowthExperienceActivityViewModel.java | 330 +++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 262 insertions(+), 68 deletions(-) diff --git a/app/src/main/java/com/application/zhangshi_app_android/ui/function/GrowthExperienceActivityViewModel.java b/app/src/main/java/com/application/zhangshi_app_android/ui/function/GrowthExperienceActivityViewModel.java index 0fcbc9f..5aa4277 100644 --- a/app/src/main/java/com/application/zhangshi_app_android/ui/function/GrowthExperienceActivityViewModel.java +++ b/app/src/main/java/com/application/zhangshi_app_android/ui/function/GrowthExperienceActivityViewModel.java @@ -3,30 +3,19 @@ import android.app.Application; import androidx.annotation.NonNull; -import androidx.databinding.DataBindingUtil; -import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModelProvider; -import com.android.app_base.base.StateViewEnum; import com.android.app_base.http.ResultData; -import com.android.app_base.manager.AppManager; import com.android.app_base.utils.RxUtils; -import com.android.app_base.utils.ToastUtils; import com.android.app_base.base.viewmodel.BaseViewModel; -import com.application.zhangshi_app_android.R; -import com.application.zhangshi_app_android.bean.FamilyAssetsBean; -import com.application.zhangshi_app_android.bean.FamilyAssetsResponseBean; -import com.application.zhangshi_app_android.bean.FamilyMemorabiliaBean; +import com.application.zhangshi_app_android.bean.GrowthExperienceAbroadConditionBean; +import com.application.zhangshi_app_android.bean.GrowthExperienceAutobiographyBean; import com.application.zhangshi_app_android.bean.GrowthExperienceBean; -import com.application.zhangshi_app_android.bean.GrowthExperienceResponseBean; -import com.application.zhangshi_app_android.bean.HomeDevicesBean; +import com.application.zhangshi_app_android.bean.GrowthExperienceHolderConditionBean; +import com.application.zhangshi_app_android.bean.GrowthExperienceInformationBean; +import com.application.zhangshi_app_android.bean.GrowthExperienceRelationshipBean; import com.application.zhangshi_app_android.data.DataRepository; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Comparator; -import java.util.Date; import java.util.HashMap; import java.util.List; @@ -38,8 +27,12 @@ * @desc 鎴愰暱缁忓巻 viewModel */ public class GrowthExperienceActivityViewModel extends BaseViewModel<DataRepository> { - private MutableLiveData<List<GrowthExperienceBean>> dataListLiveData;//鏁版嵁 - + private MutableLiveData<List<GrowthExperienceBean>> primaryLiveData;//鏁版嵁 + private MutableLiveData<GrowthExperienceInformationBean> infoLiveData; + private MutableLiveData<List<GrowthExperienceAutobiographyBean>> autobiographyLiveData; + private MutableLiveData<List<GrowthExperienceRelationshipBean>> relationLiveData; + private MutableLiveData<List<GrowthExperienceHolderConditionBean>> holderLiveData; + private MutableLiveData<List<GrowthExperienceAbroadConditionBean>> abroadLiveData; public GrowthExperienceActivityViewModel(@NonNull Application application) { super(application); } @@ -47,24 +40,164 @@ protected DataRepository initModel() { return DataRepository.getInstance(); } - public void getGrowthExperience(){ - model.getGrowthExperience(new HashMap<>()) - .compose(RxUtils.schedulersTransformer()) - .subscribe(new Observer<ResultData<GrowthExperienceResponseBean>>() { - @Override + + + /** + * 鑾峰彇鎴愰暱缁忓巻 + */ + public void getGrowthExperience(){ + model.getGrowthExperience() + .compose(RxUtils.schedulersTransformer()) + .subscribe(new Observer<ResultData<List<GrowthExperienceBean>>>() { + @Override + public void onSubscribe(Disposable d) { + addSubscribe(d); + } + + @Override + public void onNext(ResultData<List<GrowthExperienceBean>> data) { + if (data.getCode() == CODE_SUCCESS){ + primaryLiveData.postValue(data.getData()); + }else { + messageLiveData.postValue(data.getMsg()); + } + } + + + @Override + public void onError(Throwable e) { + messageLiveData.postValue(e.getMessage()); + } + + @Override + public void onComplete() { + + } + }); + + } + + /** + * 鑾峰彇涓汉淇℃伅 + */ + public void getInfo(){ + model.getGrowthExperienceInformation() + .compose(RxUtils.schedulersTransformer()) + .subscribe(new Observer<ResultData<GrowthExperienceInformationBean>>() { + @Override public void onSubscribe(Disposable d) { addSubscribe(d); } @Override - public void onNext(ResultData<GrowthExperienceResponseBean> data) { + public void onNext(ResultData<GrowthExperienceInformationBean> data) { if (data.getCode() == CODE_SUCCESS){ - if (data.getData().getData().isEmpty()){ - changeStateView(StateViewEnum.DATA_NULL); - }else { - changeStateView(StateViewEnum.HIDE); - dataListLiveData.postValue(data.getData().getData()); + infoLiveData.postValue(data.getData()); + }else { + messageLiveData.postValue(data.getMsg()); + } + } + + + @Override + public void onError(Throwable e) { + messageLiveData.postValue(e.getMessage()); + } + + @Override + public void onComplete() { + + } + }); + } + /** + * 鑾峰彇鑷紶 + */ + public void getGrowthExperienceAutobiography(){ + model.getGrowthExperienceAutobiography() + .compose(RxUtils.schedulersTransformer()) + .subscribe(new Observer<ResultData<List<GrowthExperienceAutobiographyBean>>>() { + @Override + public void onSubscribe(Disposable d) { + addSubscribe(d); + } + @Override + public void onNext(ResultData<List<GrowthExperienceAutobiographyBean>> data) { + if (data.getCode() == CODE_SUCCESS) { + if (autobiographyLiveData != null) { + //杩欎竴鐪嬪氨鏄凡缁忚幏鍙栧埌鏁版嵁浜嗭紝娌℃硶鏄剧ず灏辨槸浣犲啓鐨勪唬鐮侀棶棰橈紝鑷繁鎵鹃棶棰樺晩 + //灏辩粰livedata璁剧疆鏁版嵁锛岀劧鍚庡憿锛屽畠鐨勬暟鎹敼鍙樺悗锛岃皝鏉ュ彂鐢焨i鍙樺寲锛岃瀵熻�呭憿锛燂紵锛熻皝鏄瀵熻�� + autobiographyLiveData.postValue(data.getData()); } + } else { + if (messageLiveData != null) { + messageLiveData.postValue(data.getMsg()); + } + } + } + + + @Override + public void onError(Throwable e) { + messageLiveData.postValue(e.getMessage()); + } + + @Override + public void onComplete() { + + } + }); + } + + /** + * 鑾峰彇鍏崇郴鎯呭喌 + */ + public void getRelation(){ + model.getGrowthExperienceRelationship() + .compose(RxUtils.schedulersTransformer()) + .subscribe(new Observer<ResultData<List<GrowthExperienceRelationshipBean>>>() { + @Override + public void onSubscribe(Disposable d) { + addSubscribe(d); + } + + @Override + public void onNext(ResultData<List<GrowthExperienceRelationshipBean>> data) { + if (data.getCode() == CODE_SUCCESS){ + relationLiveData.postValue(data.getData()); + }else { + messageLiveData.postValue(data.getMsg()); + } + } + + + @Override + public void onError(Throwable e) { + messageLiveData.postValue(e.getMessage()); + } + + @Override + public void onComplete() { + + } + }); + } + /** + * 鑾峰彇鎸佹湁鍑哄叆澧冭瘉浠舵儏鍐� + */ + public void getHolder(){ + model.getGrowthExperienceHolderCondition() + .compose(RxUtils.schedulersTransformer()) + .subscribe(new Observer<ResultData<List<GrowthExperienceHolderConditionBean>>>() { + @Override + public void onSubscribe(Disposable d) { + addSubscribe(d); + } + + @Override + public void onNext(ResultData<List<GrowthExperienceHolderConditionBean>> data) { + if (data.getCode() == CODE_SUCCESS){ + holderLiveData.postValue(data.getData()); }else { messageLiveData.postValue(data.getMsg()); } @@ -84,45 +217,106 @@ } - public MutableLiveData<List<GrowthExperienceBean>> getDataListLiveData() { - if (dataListLiveData == null){ - dataListLiveData = new MutableLiveData<>(); - } - return dataListLiveData; - } - - public void setDataListLiveData(MutableLiveData<List<GrowthExperienceBean>> dataListLiveData) { - this.dataListLiveData = dataListLiveData; - } - - public void sortDataList(int type){ - List<GrowthExperienceBean> list = dataListLiveData.getValue(); - if (list == null || list.isEmpty()){ - return; - } - - list.sort(new Comparator<GrowthExperienceBean>() { - @Override - public int compare(GrowthExperienceBean o1, GrowthExperienceBean o2) { - SimpleDateFormat format = new SimpleDateFormat("yyyy-yyyy", java.util.Locale.getDefault()); - Date date1 = null; - Date date2 = null; - try { - date1 = format.parse(o1.getDuringYear()); - date2 = format.parse(o2.getDuringYear()); - } catch (ParseException e) { - throw new RuntimeException(e); - } - if (date1 != null && date2 != null) { - if (type == 0){ - return date2.compareTo(date1); - }else { - return date1.compareTo(date2); + /** + * 鑾峰彇鍑哄浗澧冩儏鍐� + */ + public void getAbroad(){ + model.getGrowthExperienceAbroadCondition() + .compose(RxUtils.schedulersTransformer()) + .subscribe(new Observer<ResultData<List<GrowthExperienceAbroadConditionBean>>>() { + @Override + public void onSubscribe(Disposable d) { + addSubscribe(d); } - } - return 0; - } - }); - dataListLiveData.postValue(list); + + @Override + public void onNext(ResultData<List<GrowthExperienceAbroadConditionBean>> data) { + if (data.getCode() == CODE_SUCCESS){ + abroadLiveData.postValue(data.getData()); + }else { + messageLiveData.postValue(data.getMsg()); + } + } + + + @Override + public void onError(Throwable e) { + messageLiveData.postValue(e.getMessage()); + } + + @Override + public void onComplete() { + + } + }); + } + + + + public MutableLiveData<List<GrowthExperienceBean>> getPrimaryLiveData() { + if (primaryLiveData == null){ + primaryLiveData = new MutableLiveData<>(); + } + return primaryLiveData; + } + + public void setPrimaryLiveData(MutableLiveData<List<GrowthExperienceBean>> primaryLiveData) { + this.primaryLiveData = primaryLiveData; + } + + public MutableLiveData<List<GrowthExperienceRelationshipBean>> getRelationLiveData() { + if (relationLiveData == null){ + relationLiveData = new MutableLiveData<>(); + } + return relationLiveData; + } + + public void setRelationLiveData(MutableLiveData<List<GrowthExperienceRelationshipBean>> relationLiveData) { + this.relationLiveData = relationLiveData; + } + + public MutableLiveData<GrowthExperienceInformationBean> getInfoLiveData() { + if (infoLiveData == null){ + infoLiveData = new MutableLiveData<>(); + } + return infoLiveData; + } + + public void setInfoLiveData(MutableLiveData<GrowthExperienceInformationBean> infoLiveData) { + this.infoLiveData = infoLiveData; + } + public void setHolderLiveData(MutableLiveData<List<GrowthExperienceHolderConditionBean>> holderLiveData) { + this.holderLiveData = holderLiveData; + } + + public MutableLiveData<List<GrowthExperienceHolderConditionBean>> getHolderLiveData() { + if (holderLiveData == null){ + holderLiveData = new MutableLiveData<>(); + } + return holderLiveData; + } + + public void setAbroadLiveData(MutableLiveData<List<GrowthExperienceAbroadConditionBean>> abroadLiveData) { + this.abroadLiveData = abroadLiveData; + } + + public MutableLiveData<List<GrowthExperienceAbroadConditionBean>> getAbroadLiveData() { + if (abroadLiveData == null){ + abroadLiveData = new MutableLiveData<>(); + } + return abroadLiveData; + } + + + + public MutableLiveData<List<GrowthExperienceAutobiographyBean>> getAutobiographyLiveData() { + if (autobiographyLiveData == null){ + autobiographyLiveData = new MutableLiveData<>(); + } + return autobiographyLiveData; + } + + public void setAutobiographyLiveData(MutableLiveData<List<GrowthExperienceAutobiographyBean>> autobiographyLiveData) { + this.autobiographyLiveData = autobiographyLiveData; } } -- Gitblit v1.9.1