guoshen
2024-07-06 cf2204a85fa951dd9ce2698378101d822e6edbc8
app/src/main/java/com/application/zhangshi_app_android/ui/function/TourismActivityViewModel.java
@@ -40,7 +40,7 @@
    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);
    }
@@ -48,6 +48,39 @@
    @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() {
                    }
                });
    }
    /**
@@ -292,6 +325,13 @@
        this.finishDeleteListLiveData = finishDeleteListLiveData;
    }
    public MutableLiveData<TourismBean> getBeanLiveData() {
        if (beanLiveData == null){
            beanLiveData = new MutableLiveData<>();
        }
        return beanLiveData;
    }
    /**
     * 改变排序
     * @param b true 降序 false 升序