詹子聪 5 rokov pred
rodič
commit
b3dd258846

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

@@ -6,7 +6,7 @@ import android.view.View;
 import android.widget.TextView;
 import android.widget.Toast;
 
-import com.miekir.mvp.jetpack.MvpObserver;
+import com.miekir.mvp.jetpack.ResultObserver;
 import com.miekir.mvp.presenter.InjectPresenter;
 import com.miekir.mvp.view.BaseMvpActivity;
 
@@ -49,7 +49,7 @@ public class MainActivity extends BaseMvpActivity implements View.OnClickListene
 //                    }
 //                });
 
-                presenter.goWithoutWrapper().observeOnce(new MvpObserver<List<TestBean1>, Void>() {
+                presenter.goWithoutWrap().observeOnce(new ResultObserver<List<TestBean1>, Void>() {
                     @Override
                     public void onDataChanged(List<TestBean1> testBean1s) {
                         Toast.makeText(getApplicationContext(), testBean1s.get(0).getName(), Toast.LENGTH_SHORT).show();

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

@@ -2,8 +2,8 @@ package com.miekir.newmvp;
 
 import android.util.Log;
 
-import com.miekir.mvp.jetpack.BeanLiveData;
-import com.miekir.mvp.jetpack.MvpLiveData;
+import com.miekir.mvp.jetpack.RawLiveData;
+import com.miekir.mvp.jetpack.WrapLiveData;
 import com.miekir.mvp.presenter.BasePresenter;
 
 import java.util.ArrayList;
@@ -24,8 +24,8 @@ public class TestPresenter extends BasePresenter {
     }
 
 
-    public BeanLiveData<List<TestBean1>, Thread> goWithWrapper() {
-        final BeanLiveData<List<TestBean1>, Thread> liveData = getWrapperLiveData(true);
+    public WrapLiveData<List<TestBean1>, Thread> goWithWrapper() {
+        final WrapLiveData<List<TestBean1>, Thread> liveData = getWrapperLiveData(true);
         Thread thread = new Thread(new Runnable() {
             @Override
             public void run() {
@@ -48,8 +48,8 @@ public class TestPresenter extends BasePresenter {
         return liveData;
     }
 
-    public MvpLiveData<List<TestBean1>, Void> goWithoutWrapper() {
-        final MvpLiveData<List<TestBean1>, Void> liveData = getRawLiveData(true);
+    public RawLiveData<List<TestBean1>, Void> goWithoutWrap() {
+        final RawLiveData<List<TestBean1>, Void> liveData = getRawLiveData(true);
         Thread thread = new Thread(new Runnable() {
             @Override
             public void run() {

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

@@ -25,15 +25,15 @@ import com.miekir.mvp.presenter.BasePresenter;
  * @param <T> 监听者里面的数据类型
  * @param <C> 返回的任务,是可取消的类型,一般定义为Void即可,除非要在Activity上执行特定操作取消某个特定任务
  */
-public class MvpLiveData<T, C> extends MutableLiveData<T> {
+public class RawLiveData<T, C> extends MutableLiveData<T> {
     protected BasePresenter mPresenter;
     protected boolean mWidthProgress;
-    public MvpLiveData(BasePresenter mPresenter, boolean withProgress) {
+    public RawLiveData(BasePresenter mPresenter, boolean withProgress) {
         this.mPresenter = mPresenter;
         this.mWidthProgress = withProgress;
     }
 
-    private MvpObserver<T, C> mObserver;
+    private ResultObserver<T, C> mObserver;
     public void cancelObserve() {
         mObserver.setLiveData(null);
         removeObserver(mObserver);
@@ -49,7 +49,7 @@ public class MvpLiveData<T, C> extends MutableLiveData<T> {
      * 只监听一次的LiveData
      * @param observer
      */
-    public C observeOnce(MvpObserver<T, C> observer) {
+    public C observeOnce(ResultObserver<T, C> observer) {
         mObserver = observer;
         observer.setLiveData(this);
         observeForever(observer);

+ 3 - 3
mvp/src/main/java/com/miekir/mvp/jetpack/MvpObserver.java

@@ -11,9 +11,9 @@ import androidx.lifecycle.Observer;
  * @param <T> 监听者里面的数据类型
  * @param <C> 返回的任务,是可取消的类型,一般定义为Void即可,除非要在Activity上执行特定操作取消某个特定任务
  */
-public abstract class MvpObserver<T, C> implements Observer<T> {
-    private MvpLiveData<T, C> liveData;
-    public void setLiveData(MvpLiveData<T, C> liveData) {
+public abstract class ResultObserver<T, C> implements Observer<T> {
+    private RawLiveData<T, C> liveData;
+    public void setLiveData(RawLiveData<T, C> liveData) {
         this.liveData = liveData;
     }
 

+ 2 - 2
mvp/src/main/java/com/miekir/mvp/jetpack/BeanLiveData.java

@@ -13,8 +13,8 @@ import com.miekir.mvp.presenter.BasePresenter;
  * @param <T> 监听者里面的数据类型
  * @param <C> 返回的任务,是可取消的类型,一般定义为Void即可,除非要在Activity上执行特定操作取消某个特定任务
  */
-public class BeanLiveData<T, C> extends MvpLiveData<DataResult<T>, C> {
-    public BeanLiveData(BasePresenter mPresenter, boolean withProgress) {
+public class WrapLiveData<T, C> extends RawLiveData<DataResult<T>, C> {
+    public WrapLiveData(BasePresenter mPresenter, boolean withProgress) {
         super(mPresenter, withProgress);
     }
 

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

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