| | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.lifecycle.MutableLiveData; |
| | | |
| | | import com.android.app_base.base.BaseConfig; |
| | | 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.FamilyContactsBean; |
| | | import com.application.zhangshi_app_android.bean.ContactsBean; |
| | | |
| | | import com.application.zhangshi_app_android.data.DataRepository; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | |
| | | */ |
| | | public class ContactsActivityViewModel extends BaseViewModel<DataRepository> { |
| | | |
| | | private MutableLiveData<List<FamilyContactsBean>> dataListLiveData;//所有数据 |
| | | private MutableLiveData<List<ContactsBean>> dataListLiveData;//所有数据 |
| | | |
| | | |
| | | public ContactsActivityViewModel(@NonNull Application application) { |
| | |
| | | } |
| | | |
| | | |
| | | public void getFamilyContacts(){ |
| | | model.getFamilyContacts(new HashMap<>()) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new Observer<ResultData<FamilyContactsBean>>() { |
| | | @Override |
| | | public void onSubscribe(Disposable d) { |
| | | addSubscribe(d); |
| | | } |
| | | |
| | | @Override |
| | | public void onNext(ResultData<FamilyContactsBean> data) { |
| | | if (data.getCode() == CODE_SUCCESS){ |
| | | if (data.getData().getData().isEmpty()){ |
| | | changeStateView(StateViewEnum.DATA_NULL); |
| | | }else { |
| | | changeStateView(StateViewEnum.HIDE); |
| | | dataListLiveData.postValue(data.getData().getData()); |
| | | } |
| | | }else { |
| | | messageLiveData.postValue(data.getMsg()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(Throwable e) { |
| | | messageLiveData.postValue(e.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | public void getContacts(){ |
| | | // model.getFamilyContacts(new HashMap<>()) |
| | | // .compose(RxUtils.schedulersTransformer()) |
| | | // .subscribe(new Observer<ResultData<ContactsBean>>() { |
| | | // @Override |
| | | // public void onSubscribe(Disposable d) { |
| | | // addSubscribe(d); |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onNext(ResultData<ContactsBean> data) { |
| | | // if (data.getCode() == CODE_SUCCESS){ |
| | | // if (data.getData().getData().isEmpty()){ |
| | | // changeStateView(StateViewEnum.DATA_NULL); |
| | | // }else { |
| | | // changeStateView(StateViewEnum.HIDE); |
| | | // dataListLiveData.postValue(data.getData().getData()); |
| | | // } |
| | | // }else { |
| | | // messageLiveData.postValue(data.getMsg()); |
| | | // } |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onError(Throwable e) { |
| | | // messageLiveData.postValue(e.getMessage()); |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onComplete() { |
| | | // |
| | | // } |
| | | // }); |
| | | } |
| | | |
| | | |
| | | |
| | | public MutableLiveData<List<FamilyContactsBean>> getDataListLiveData() { |
| | | public MutableLiveData<List<ContactsBean>> getDataListLiveData() { |
| | | if (dataListLiveData == null){ |
| | | dataListLiveData = new MutableLiveData<>(); |
| | | } |
| | | return dataListLiveData; |
| | | } |
| | | public void setDataListLiveData(MutableLiveData<List<FamilyContactsBean>> dataListLiveData) { |
| | | public void setDataListLiveData(MutableLiveData<List<ContactsBean>> dataListLiveData) { |
| | | this.dataListLiveData = dataListLiveData; |
| | | } |
| | | |