| | |
| | | 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.http.ResultData; |
| | | import com.android.app_base.manager.AppManager; |
| | | import com.android.app_base.manager.UserManager; |
| | | 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.FamilyMemorabiliaBean; |
| | | import com.android.app_base.utils.rxbus.MessageEvent; |
| | | import com.android.app_base.utils.rxbus.RxBus; |
| | | 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.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.util.List; |
| | |
| | | * @desc 成长经历 viewModel |
| | | */ |
| | | public class GrowthExperienceActivityViewModel extends BaseViewModel<DataRepository> { |
| | | private MutableLiveData<List<GrowthExperienceBean>> experienceListLiveData;//成长经历列表 |
| | | private MutableLiveData<GrowthExperienceInformationBean> infoLiveData;//个人信息 |
| | | private MutableLiveData<List<GrowthExperienceAutobiographyBean>> autobiographyLiveData;//自传列表 |
| | | private MutableLiveData<List<GrowthExperienceRelationshipBean>> relationLiveData;//关系列表 |
| | | private MutableLiveData<List<GrowthExperienceHolderConditionBean>> holderLiveData;//持证情况列表 |
| | | private MutableLiveData<List<GrowthExperienceAbroadConditionBean>> abroadLiveData;//出国情况列表 |
| | | private MutableLiveData<Boolean> isExperienceExpendedLiveData;//成长经历是否展开 |
| | | private MutableLiveData<Boolean> isRelationExpendedLiveData;//关系是否展开 |
| | | private MutableLiveData<Boolean> isHolderExpendedLiveData;//持证情况是否展开 |
| | | private MutableLiveData<Boolean> isAbroadExpendedLiveData;//出国情况是否展开 |
| | | |
| | | public GrowthExperienceActivityViewModel(@NonNull Application application) { |
| | | super(application); |
| | |
| | | return DataRepository.getInstance(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取成长经历 |
| | | */ |
| | | 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){ |
| | | experienceListLiveData.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<GrowthExperienceInformationBean> data) { |
| | | if (data.getCode() == CODE_SUCCESS){ |
| | | GrowthExperienceInformationBean informationBean = data.getData(); |
| | | infoLiveData.postValue(informationBean); |
| | | if(informationBean != null){ |
| | | UserManager.getInstance().setUserName(informationBean.getNickName()); |
| | | UserManager.getInstance().setUserAvatar(informationBean.getImg()); |
| | | RxBus.getInstance().post(new MessageEvent(MessageEvent.EVENT_UPDATE_USER_INFO,informationBean)); |
| | | } |
| | | }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) { |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onError(Throwable e) { |
| | | messageLiveData.postValue(e.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取出国境情况 |
| | | */ |
| | | public void getAbroad(){ |
| | | model.getGrowthExperienceAbroadCondition() |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new Observer<ResultData<List<GrowthExperienceAbroadConditionBean>>>() { |
| | | @Override |
| | | public void onSubscribe(Disposable d) { |
| | | addSubscribe(d); |
| | | } |
| | | |
| | | @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>> getExperienceListLiveData() { |
| | | if (experienceListLiveData == null){ |
| | | experienceListLiveData = new MutableLiveData<>(); |
| | | } |
| | | return experienceListLiveData; |
| | | } |
| | | |
| | | public void setExperienceListLiveData(MutableLiveData<List<GrowthExperienceBean>> experienceListLiveData) { |
| | | this.experienceListLiveData = experienceListLiveData; |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | public MutableLiveData<Boolean> getIsExperienceExpendedLiveData() { |
| | | if (isExperienceExpendedLiveData == null){ |
| | | isExperienceExpendedLiveData = new MutableLiveData<>(); |
| | | isExperienceExpendedLiveData.setValue(false); |
| | | } |
| | | return isExperienceExpendedLiveData; |
| | | } |
| | | |
| | | public void setIsExperienceExpendedLiveData(MutableLiveData<Boolean> isExperienceExpendedLiveData) { |
| | | this.isExperienceExpendedLiveData = isExperienceExpendedLiveData; |
| | | } |
| | | |
| | | public MutableLiveData<Boolean> getIsRelationExpendedLiveData() { |
| | | if (isRelationExpendedLiveData == null){ |
| | | isRelationExpendedLiveData = new MutableLiveData<>(); |
| | | isRelationExpendedLiveData.setValue(false); |
| | | } |
| | | return isRelationExpendedLiveData; |
| | | } |
| | | |
| | | public void setIsRelationExpendedLiveData(MutableLiveData<Boolean> isRelationExpendedLiveData) { |
| | | this.isRelationExpendedLiveData = isRelationExpendedLiveData; |
| | | } |
| | | |
| | | public MutableLiveData<Boolean> getIsHolderExpendedLiveData() { |
| | | if (isHolderExpendedLiveData == null){ |
| | | isHolderExpendedLiveData = new MutableLiveData<>(); |
| | | isHolderExpendedLiveData.setValue(false); |
| | | } |
| | | return isHolderExpendedLiveData; |
| | | } |
| | | |
| | | public void setIsHolderExpendedLiveData(MutableLiveData<Boolean> isHolderExpendedLiveData) { |
| | | this.isHolderExpendedLiveData = isHolderExpendedLiveData; |
| | | } |
| | | |
| | | public MutableLiveData<Boolean> getIsAbroadExpendedLiveData() { |
| | | if (isAbroadExpendedLiveData == null){ |
| | | isAbroadExpendedLiveData = new MutableLiveData<>(); |
| | | isAbroadExpendedLiveData.setValue(false); |
| | | } |
| | | return isAbroadExpendedLiveData; |
| | | } |
| | | |
| | | public void setIsAbroadExpendedLiveData(MutableLiveData<Boolean> isAbroadExpendedLiveData) { |
| | | this.isAbroadExpendedLiveData = isAbroadExpendedLiveData; |
| | | } |
| | | } |