|
|
@@ -1,7 +1,5 @@
|
|
|
package com.miekir.mvp.presenter;
|
|
|
|
|
|
-import android.util.Log;
|
|
|
-
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
import androidx.lifecycle.ViewModel;
|
|
|
|
|
|
@@ -17,6 +15,8 @@ import com.miekir.mvp.constant.BaseMvpSource;
|
|
|
* Description:
|
|
|
*/
|
|
|
public class BaseViewModel extends ViewModel {
|
|
|
+ //private ThreadLocal<Integer> mThreadLocal = new ThreadLocal<>();
|
|
|
+
|
|
|
/**
|
|
|
* ViewModel的生命周期和Activity保持一致;在onStart()、onResume()、onPause()时调用LiveData的setValue才会通知观察者
|
|
|
* liveData在ViewModel(Presenter)创建,然后提供方法给Activity获取,方便取消观察
|
|
|
@@ -27,21 +27,22 @@ public class BaseViewModel extends ViewModel {
|
|
|
return liveData;
|
|
|
}
|
|
|
|
|
|
- private volatile int mLoadingTime;
|
|
|
- public synchronized int onLoadTimeMinus() {
|
|
|
- mLoadingTime = mLoadingTime-1;
|
|
|
- return mLoadingTime;
|
|
|
- }
|
|
|
- public synchronized int onLoadTimeAdd() {
|
|
|
- mLoadingTime = mLoadingTime+1;
|
|
|
- return mLoadingTime;
|
|
|
+ private volatile int mLoadingNum;
|
|
|
+ public synchronized int onLoadTimeChange(boolean isAdd) {
|
|
|
+ if (isAdd) {
|
|
|
+ mLoadingNum = mLoadingNum +1;
|
|
|
+ } else {
|
|
|
+ mLoadingNum = mLoadingNum -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return mLoadingNum;
|
|
|
}
|
|
|
/**
|
|
|
* 这个方法名不能改动
|
|
|
* 对弹出对话框此时进行计数,归零才dismiss
|
|
|
*/
|
|
|
public void showLoading() {
|
|
|
- onLoadTimeAdd();
|
|
|
+ onLoadTimeChange(true);
|
|
|
}
|
|
|
|
|
|
public void post(int responseCode, String msg, Object dataBean, int sourceCode) {
|