| | |
| | | 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.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.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.HashMap; |
| | | import java.util.List; |
| | | |
| | | import io.reactivex.Observer; |
| | |
| | | * @desc 成长经历 viewModel |
| | | */ |
| | | public class GrowthExperienceActivityViewModel extends BaseViewModel<DataRepository> { |
| | | private MutableLiveData<GrowthExperienceBean> beanMutableLiveData; |
| | | private MutableLiveData<List<GrowthExperienceBean>> checkListLiveData; |
| | | private MutableLiveData<List<GrowthExperienceBean>> dataListLiveData; |
| | | private MutableLiveData<String> stringMutableLiveData; |
| | | |
| | | |
| | | |
| | | |
| | | 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); |
| | | } |
| | |
| | | return DataRepository.getInstance(); |
| | | } |
| | | |
| | | @Override |
| | | public void onCreate(@NonNull LifecycleOwner owner) { |
| | | super.onCreate(owner); |
| | | GrowthExperienceActivityViewModel viewModel=new ViewModelProvider(this).get(GrowthExperienceActivityViewModel.class); |
| | | DataBindingUtil.setContentView(this, R.layout.activity_growth_experience).setViewModel(viewModel); |
| | | |
| | | /** |
| | | * 获取成长经历 |
| | | */ |
| | | 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<GrowthExperienceInformationBean> data) { |
| | | if (data.getCode() == CODE_SUCCESS){ |
| | | 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设置数据,然后呢,它的数据改变后,谁来发生ui变化,观察者呢???谁是观察者 |
| | | 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>> 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; |
| | | } |
| | | } |