詹子聪 5 lat temu
rodzic
commit
bbf754edb3

+ 1 - 1
app/src/main/java/com/miekir/newmvp/MainActivity.java

@@ -49,7 +49,7 @@ public class MainActivity extends BaseMvpActivity implements View.OnClickListene
 //                    }
 //                });
 
-                presenter.goWithoutResult().observeOnce(new MvpObserver<List<TestBean1>, Void>() {
+                presenter.goWithoutWrapper().observeOnce(new MvpObserver<List<TestBean1>, Void>() {
                     @Override
                     public void onDataChanged(List<TestBean1> testBean1s) {
                         Toast.makeText(getApplicationContext(), testBean1s.get(0).getName(), Toast.LENGTH_SHORT).show();

+ 3 - 3
app/src/main/java/com/miekir/newmvp/TestPresenter.java

@@ -24,8 +24,8 @@ public class TestPresenter extends BasePresenter {
     }
 
 
-    public BeanLiveData<List<TestBean1>, Thread> goWithResult() {
-        final BeanLiveData<List<TestBean1>, Thread> liveData = getResultLiveData(true);
+    public BeanLiveData<List<TestBean1>, Thread> goWithWrapper() {
+        final BeanLiveData<List<TestBean1>, Thread> liveData = getWrapperLiveData(true);
         Thread thread = new Thread(new Runnable() {
             @Override
             public void run() {
@@ -48,7 +48,7 @@ public class TestPresenter extends BasePresenter {
         return liveData;
     }
 
-    public MvpLiveData<List<TestBean1>, Void> goWithoutResult() {
+    public MvpLiveData<List<TestBean1>, Void> goWithoutWrapper() {
         final MvpLiveData<List<TestBean1>, Void> liveData = getRawLiveData(true);
         Thread thread = new Thread(new Runnable() {
             @Override

+ 1 - 1
mvp/src/main/java/com/miekir/mvp/jetpack/MvpLiveData.java

@@ -35,8 +35,8 @@ public class MvpLiveData<T, C> extends MutableLiveData<T> {
 
     private MvpObserver<T, C> mObserver;
     public void cancelObserve() {
-        removeObserver(mObserver);
         mObserver.setLiveData(null);
+        removeObserver(mObserver);
         mObserver = null;
         mPresenter = null;
     }

+ 2 - 5
mvp/src/main/java/com/miekir/mvp/presenter/BasePresenter.java

@@ -39,12 +39,12 @@ public abstract class BasePresenter extends ViewModel {
     }
 
     /**
-     *
+     * 返回带有结果状态的实体
      * @param withProgress 是否显示加载对话框
      * @param <T> 监听者里面的数据类型
      * @param <C> 返回的任务,应该是可取消的类型
      */
-    protected <T, C> BeanLiveData<T, C> getResultLiveData(boolean withProgress) {
+    protected <T, C> BeanLiveData<T, C> getWrapperLiveData(boolean withProgress) {
         if (withProgress) {
             showLoading();
         }
@@ -60,9 +60,6 @@ public abstract class BasePresenter extends ViewModel {
         liveDataList.add(liveData);
         return liveData;
     }
-    protected <T> BeanLiveData<T, ?> getResultLiveData() {
-        return getResultLiveData(false);
-    }
 
     /**
      * 显示默认文字的进度框