Bladeren bron

返回任务完成了

詹子聪 5 jaren geleden
bovenliggende
commit
fce60a5258

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

@@ -54,7 +54,12 @@ public class TestPresenter extends BasePresenter {
     public void onTaskCancel() {
         super.onTaskCancel();
         if (thread != null) {
-            thread.stop();
+            try {
+                thread.interrupt();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
         }
     }
 }

+ 0 - 1
mvp/src/main/java/com/miekir/mvp/base/BaseFragment.java

@@ -12,7 +12,6 @@ import androidx.annotation.Nullable;
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.FragmentActivity;
 
-import com.miekir.mvp.view.IView;
 import com.miekir.mvp.widget.LoadingDialog;
 
 

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

@@ -37,7 +37,7 @@ public class MvpLiveData<T, C> extends MutableLiveData<T> {
         this.mWidthProgress = withProgress;
     }
 
-    private MvpObserver<T> mObserver;
+    private MvpObserver<T, C> mObserver;
     public void cancelObserve() {
         removeObserver(mObserver);
         mObserver.setLiveData(null);
@@ -49,7 +49,7 @@ public class MvpLiveData<T, C> extends MutableLiveData<T> {
      * 只监听一次的LiveData
      * @param observer
      */
-    public C observeOnce(MvpObserver<T> observer) {
+    public C observeOnce(MvpObserver<T, C> observer) {
         mObserver = observer;
         observer.setLiveData(this);
         observeForever(observer);

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

@@ -32,20 +32,20 @@ public abstract class BasePresenter extends ViewModel {
         return dialogLiveData;
     }
 
-    private List<BeanLiveData<?>> liveDataList = new CopyOnWriteArrayList<>();
-    public List<BeanLiveData<?>> getLiveDataList() {
+    private List<BeanLiveData<?, ?>> liveDataList = new CopyOnWriteArrayList<>();
+    public List<BeanLiveData<?, ?>> getLiveDataList() {
         return liveDataList;
     }
 
-    protected <T> BeanLiveData<T> getLiveData(boolean withProgress) {
+    protected <T, C> BeanLiveData<T, C> getLiveData(boolean withProgress) {
         if (withProgress) {
             showLoading();
         }
-        BeanLiveData<T> liveData = new BeanLiveData<>(this, withProgress);
+        BeanLiveData<T, C> liveData = new BeanLiveData<>(this, withProgress);
         liveDataList.add(liveData);
         return liveData;
     }
-    protected <T> BeanLiveData<T> getLiveData() {
+    protected <T> BeanLiveData<T, ?> getLiveData() {
         return getLiveData(false);
     }
 
@@ -85,7 +85,7 @@ public abstract class BasePresenter extends ViewModel {
      * 当任务被取消时,界面还存在
      */
     public void onTaskCancel() {
-        for (BeanLiveData<?> liveData : liveDataList) {
+        for (BeanLiveData<?, ?> liveData : liveDataList) {
             liveData.cancelObserve();
         }
         liveDataList.clear();