Linjiajia
2023-09-12 efafbbf142c81c233c71de636a2d3ce9dc2124f0
app/src/main/java/com/application/zhangshi_app_android/ui/function/PropertyDetailActivityViewModel.java
@@ -1,14 +1,25 @@
package com.application.zhangshi_app_android.ui.function;
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.BaseConfig;
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.CleanStorageBean;
import com.application.zhangshi_app_android.bean.MemoBean;
import com.application.zhangshi_app_android.bean.PropertyBean;
import com.application.zhangshi_app_android.data.DataRepository;
import java.util.List;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
/**
 * @author Ljj
@@ -18,6 +29,7 @@
public class PropertyDetailActivityViewModel extends BaseViewModel<DataRepository> {
    private MutableLiveData<PropertyBean> beanLiveData;
    private MutableLiveData<List<MemoBean>> memoListLiveData;
    public PropertyDetailActivityViewModel(@NonNull Application application) {
        super(application);
@@ -28,7 +40,41 @@
        return DataRepository.getInstance();
    }
    /**
     * 获取备忘录
     */
    public void getMemos() {
        if (beanLiveData.getValue() == null) {
            return;
        }
        model.getMemos(BaseConfig.MEMO_FID_PROPERTY+"", String.valueOf(beanLiveData.getValue().getId()))
                .compose(RxUtils.schedulersTransformer())
                .subscribe(new Observer<ResultData<List<MemoBean>>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        addSubscribe(d);
                    }
                    @Override
                    public void onNext(ResultData<List<MemoBean>> data) {
                        if (data.getCode() == CODE_SUCCESS){
                            memoListLiveData.postValue(data.getData());
                        }else {
                            messageLiveData.postValue(data.getMsg());
                        }
                    }
                    @Override
                    public void onError(Throwable e) {
                        messageLiveData.postValue(e.getMessage());
                    }
                    @Override
                    public void onComplete() {
                    }
                });
    }
    public MutableLiveData<PropertyBean> getBeanLiveData() {
        if (beanLiveData == null) {
            beanLiveData = new MutableLiveData<>();
@@ -39,4 +85,15 @@
    public void setBeanLiveData(MutableLiveData<PropertyBean> beanLiveData) {
        this.beanLiveData = beanLiveData;
    }
    public MutableLiveData<List<MemoBean>> getMemoListLiveData() {
        if (memoListLiveData == null){
            memoListLiveData = new MutableLiveData<>();
        }
        return memoListLiveData;
    }
    public void setMemoListLiveData(MutableLiveData<List<MemoBean>> memoListLiveData) {
        this.memoListLiveData = memoListLiveData;
    }
}