|
|
@@ -3,35 +3,35 @@ package com.miekir.mvp.presenter;
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
|
|
|
import com.miekir.mvp.base.DataResult;
|
|
|
-import com.miekir.mvp.view.IView;
|
|
|
+import com.miekir.mvp.bean.BaseBean;
|
|
|
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
|
|
-public abstract class BasePresenter<V extends IView> {
|
|
|
- private WeakReference<V> wrf;
|
|
|
+public abstract class BasePresenter<B extends BaseBean> {
|
|
|
|
|
|
- private MutableLiveData<DataResult> mLiveData;
|
|
|
- public void attachView(V view) {
|
|
|
- wrf = new WeakReference<V>(view);
|
|
|
- }
|
|
|
+ private WeakReference<MutableLiveData<DataResult>> mLiveData;
|
|
|
|
|
|
public void setLiveData(MutableLiveData<DataResult> liveData) {
|
|
|
- mLiveData = liveData;
|
|
|
+ mLiveData = new WeakReference<>(liveData);
|
|
|
}
|
|
|
|
|
|
- public V getView() {
|
|
|
- return wrf == null ? null : wrf.get();
|
|
|
- }
|
|
|
+ public void post(int code, String msg, B dataBean) {
|
|
|
+ if (mLiveData == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ MutableLiveData<DataResult> liveData = mLiveData.get();
|
|
|
+ if (liveData == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- public MutableLiveData<DataResult> getLiveData() {
|
|
|
- return mLiveData;
|
|
|
+ liveData.postValue(new DataResult(code, msg, dataBean));
|
|
|
}
|
|
|
|
|
|
public void detachView() {
|
|
|
- if (wrf != null) {
|
|
|
- wrf.clear();
|
|
|
- wrf = null;
|
|
|
+ if (mLiveData != null) {
|
|
|
+ mLiveData.clear();
|
|
|
+ mLiveData = null;
|
|
|
}
|
|
|
}
|
|
|
}
|