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.AnnualHealthStatusBean;
|
import com.application.zhangshi_app_android.bean.MemoBean;
|
import com.application.zhangshi_app_android.bean.PrivacyBean;
|
import com.application.zhangshi_app_android.data.DataRepository;
|
|
import java.util.List;
|
|
import io.reactivex.Observer;
|
import io.reactivex.disposables.Disposable;
|
|
/**
|
* @author Ljj
|
* @date 2023.04.28. 20:45
|
* @desc
|
*/
|
public class PrivacyDetailActivityViewModel extends BaseViewModel<DataRepository> {
|
|
private MutableLiveData<PrivacyBean> beanLiveData;
|
private MutableLiveData<List<MemoBean>> memoListLiveData;
|
|
public PrivacyDetailActivityViewModel(@NonNull Application application) {
|
super(application);
|
}
|
|
@Override
|
protected DataRepository initModel() {
|
return DataRepository.getInstance();
|
}
|
|
/**
|
* 获取备忘录
|
*/
|
public void getMemos() {
|
if (beanLiveData.getValue() == null) {
|
return;
|
}
|
model.getMemos(BaseConfig.MEMO_FID_PRIVACY+"", 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<PrivacyBean> getBeanLiveData() {
|
if (beanLiveData == null) {
|
beanLiveData = new MutableLiveData<>();
|
}
|
return beanLiveData;
|
}
|
|
public void setBeanLiveData(MutableLiveData<PrivacyBean> 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;
|
}
|
}
|