|
@@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel;
|
|
|
import com.miekir.mvp.bean.DataResult;
|
|
import com.miekir.mvp.bean.DataResult;
|
|
|
import com.miekir.mvp.constant.DialogAction;
|
|
import com.miekir.mvp.constant.DialogAction;
|
|
|
import com.miekir.mvp.jetpack.BeanLiveData;
|
|
import com.miekir.mvp.jetpack.BeanLiveData;
|
|
|
|
|
+import com.miekir.mvp.jetpack.MvpLiveData;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
@@ -32,8 +33,8 @@ public abstract class BasePresenter extends ViewModel {
|
|
|
return dialogLiveData;
|
|
return dialogLiveData;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private List<BeanLiveData<?, ?>> liveDataList = new CopyOnWriteArrayList<>();
|
|
|
|
|
- public List<BeanLiveData<?, ?>> getLiveDataList() {
|
|
|
|
|
|
|
+ private List<MvpLiveData<?, ?>> liveDataList = new CopyOnWriteArrayList<>();
|
|
|
|
|
+ public List<MvpLiveData<?, ?>> getLiveDataList() {
|
|
|
return liveDataList;
|
|
return liveDataList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -43,7 +44,7 @@ public abstract class BasePresenter extends ViewModel {
|
|
|
* @param <T> 监听者里面的数据类型
|
|
* @param <T> 监听者里面的数据类型
|
|
|
* @param <C> 返回的任务,应该是可取消的类型
|
|
* @param <C> 返回的任务,应该是可取消的类型
|
|
|
*/
|
|
*/
|
|
|
- protected <T, C> BeanLiveData<T, C> getLiveData(boolean withProgress) {
|
|
|
|
|
|
|
+ protected <T, C> BeanLiveData<T, C> getResultLiveData(boolean withProgress) {
|
|
|
if (withProgress) {
|
|
if (withProgress) {
|
|
|
showLoading();
|
|
showLoading();
|
|
|
}
|
|
}
|
|
@@ -51,8 +52,16 @@ public abstract class BasePresenter extends ViewModel {
|
|
|
liveDataList.add(liveData);
|
|
liveDataList.add(liveData);
|
|
|
return liveData;
|
|
return liveData;
|
|
|
}
|
|
}
|
|
|
- protected <T> BeanLiveData<T, ?> getLiveData() {
|
|
|
|
|
- return getLiveData(false);
|
|
|
|
|
|
|
+ protected <T, C> MvpLiveData<T, C> getRawLiveData(boolean withProgress) {
|
|
|
|
|
+ if (withProgress) {
|
|
|
|
|
+ showLoading();
|
|
|
|
|
+ }
|
|
|
|
|
+ MvpLiveData<T, C> liveData = new MvpLiveData<>(this, withProgress);
|
|
|
|
|
+ liveDataList.add(liveData);
|
|
|
|
|
+ return liveData;
|
|
|
|
|
+ }
|
|
|
|
|
+ protected <T> BeanLiveData<T, ?> getResultLiveData() {
|
|
|
|
|
+ return getResultLiveData(false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -101,7 +110,7 @@ public abstract class BasePresenter extends ViewModel {
|
|
|
* 当任务被取消时,界面还存在
|
|
* 当任务被取消时,界面还存在
|
|
|
*/
|
|
*/
|
|
|
public void onTaskCancel() {
|
|
public void onTaskCancel() {
|
|
|
- for (BeanLiveData<?, ?> liveData : liveDataList) {
|
|
|
|
|
|
|
+ for (MvpLiveData<?, ?> liveData : liveDataList) {
|
|
|
liveData.cancelObserve();
|
|
liveData.cancelObserve();
|
|
|
}
|
|
}
|
|
|
liveDataList.clear();
|
|
liveDataList.clear();
|