| | |
| | | private MutableLiveData<List<TourismBean>> moreListLiveData;//下拉加载数据 |
| | | private MutableLiveData<List<TourismBean>> finishDeleteListLiveData;//已经完成删除的数据,用于adapter的remove操作 |
| | | |
| | | |
| | | private MutableLiveData<TourismBean> beanLiveData;// 根据id获取的bean,用于更新数据 |
| | | public TourismActivityViewModel(@NonNull Application application) { |
| | | super(application); |
| | | } |
| | |
| | | @Override |
| | | protected DataRepository initModel() { |
| | | return DataRepository.getInstance(); |
| | | } |
| | | |
| | | /** |
| | | * 根据 id 获取 |
| | | */ |
| | | public void getTourismById(String id) { |
| | | model.getTourismById(id) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new Observer<ResultData<TourismBean>>() { |
| | | @Override |
| | | public void onSubscribe(Disposable d) { |
| | | addSubscribe(d); |
| | | } |
| | | |
| | | @Override |
| | | public void onNext(ResultData<TourismBean> data) { |
| | | if (data.getCode() == CODE_SUCCESS) { |
| | | beanLiveData.postValue(data.getData()); |
| | | } else { |
| | | messageLiveData.postValue(data.getMsg()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(Throwable e) { |
| | | messageLiveData.postValue(e.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | |
| | | this.finishDeleteListLiveData = finishDeleteListLiveData; |
| | | } |
| | | |
| | | public MutableLiveData<TourismBean> getBeanLiveData() { |
| | | if (beanLiveData == null){ |
| | | beanLiveData = new MutableLiveData<>(); |
| | | } |
| | | return beanLiveData; |
| | | } |
| | | |
| | | /** |
| | | * 改变排序 |
| | | * @param b true 降序 false 升序 |