| | |
| | | package com.application.zhangshi_app_android.ui.home; |
| | | |
| | | import static com.android.app_base.base.BaseConfig.CODE_SUCCESS; |
| | | |
| | | import android.app.Application; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | 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.AnnualHealthStatusBean; |
| | | import com.application.zhangshi_app_android.bean.HomeRootBean; |
| | | import com.application.zhangshi_app_android.bean.PageResponseBean; |
| | | import com.application.zhangshi_app_android.data.DataRepository; |
| | | |
| | | import java.util.List; |
| | | |
| | | import io.reactivex.Observer; |
| | | import io.reactivex.disposables.Disposable; |
| | | import io.reactivex.functions.Action; |
| | | |
| | | /** |
| | | * @author Ljj |
| | |
| | | * @desc 首页 Fragment的 ViewModel |
| | | */ |
| | | public class HomeFragmentViewModel extends BaseViewModel<DataRepository> { |
| | | private MutableLiveData<List<HomeRootBean>> homeRootBeanLiveData;//家根网成员列表 |
| | | |
| | | |
| | | public HomeFragmentViewModel(@NonNull Application application) { |
| | | super(application); |
| | |
| | | protected DataRepository initModel() { |
| | | return DataRepository.getInstance(); |
| | | } |
| | | |
| | | |
| | | public void getHomeRootBeanList() { |
| | | model.getHomeRoot("1000") |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .doFinally(new Action() { |
| | | @Override |
| | | public void run() throws Exception { |
| | | changeStateView(StateViewEnum.DATA_FINISH); |
| | | } |
| | | }) |
| | | .subscribe(new Observer<ResultData<List<HomeRootBean>>>() { |
| | | @Override |
| | | public void onSubscribe(Disposable d) { |
| | | addSubscribe(d); |
| | | } |
| | | |
| | | @Override |
| | | public void onNext(ResultData<List<HomeRootBean>> data) { |
| | | if (data.getCode() == CODE_SUCCESS){ |
| | | homeRootBeanLiveData.postValue(data.getData()); |
| | | }else { |
| | | getMessageLivaData().postValue(data.getMsg()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(Throwable e) { |
| | | getMessageLivaData().postValue(e.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | public MutableLiveData<List<HomeRootBean>> getHomeRootBeanLiveData() { |
| | | if (homeRootBeanLiveData == null) { |
| | | homeRootBeanLiveData = new MutableLiveData<>(); |
| | | } |
| | | return homeRootBeanLiveData; |
| | | } |
| | | |
| | | public void setHomeRootBeanLiveData(MutableLiveData<List<HomeRootBean>> homeRootBeanLiveData) { |
| | | this.homeRootBeanLiveData = homeRootBeanLiveData; |
| | | } |
| | | } |