|
|
@@ -11,6 +11,7 @@ import androidx.lifecycle.Observer;
|
|
|
|
|
|
import com.miekir.mvp.base.BaseFragment;
|
|
|
import com.miekir.mvp.bean.DataResult;
|
|
|
+import com.miekir.mvp.constant.BaseMvpSource;
|
|
|
import com.miekir.mvp.presenter.BaseViewModel;
|
|
|
import com.miekir.mvp.presenter.DataMethod;
|
|
|
import com.miekir.mvp.presenter.InjectViewModel;
|
|
|
@@ -39,6 +40,22 @@ public abstract class BaseMvpFragment extends BaseFragment implements IView {
|
|
|
private List<Method> mDataMethodList = new ArrayList<>();
|
|
|
private List<BaseViewModel> mInjectPresenters = new ArrayList<>();
|
|
|
|
|
|
+ private volatile int mLoadingNum;
|
|
|
+ public synchronized int onLoadTimeChange(boolean isAdd) {
|
|
|
+ if (isAdd) {
|
|
|
+ mLoadingNum = mLoadingNum +1;
|
|
|
+ } else {
|
|
|
+ mLoadingNum = mLoadingNum -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mLoadingNum == 0) {
|
|
|
+ dismissLoading();
|
|
|
+ } else {
|
|
|
+ showLoading();
|
|
|
+ }
|
|
|
+ return mLoadingNum;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
initVariables();
|
|
|
@@ -78,7 +95,13 @@ public abstract class BaseMvpFragment extends BaseFragment implements IView {
|
|
|
public void onChanged(final DataResult result) {
|
|
|
// 回调是在主线程
|
|
|
// Log.i("Thread", String.valueOf(Thread.currentThread() == Looper.getMainLooper().getThread()));
|
|
|
- onDataResult(result);
|
|
|
+ if (result.getSourceCode() == BaseMvpSource.DIALOG_SHOW) {
|
|
|
+ onLoadTimeChange(true);
|
|
|
+ } else if (result.getSourceCode() == BaseMvpSource.DIALOG_DISMISS) {
|
|
|
+ onLoadTimeChange(false);
|
|
|
+ } else {
|
|
|
+ onDataResult(result);
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
if (injectViewModel.isPersist()) {
|
|
|
@@ -228,7 +251,6 @@ public abstract class BaseMvpFragment extends BaseFragment implements IView {
|
|
|
}
|
|
|
|
|
|
private void onDataResult(DataResult result) {
|
|
|
- dismissLoading();
|
|
|
Class objParamClass = result.getBean().getClass();
|
|
|
for (Method method : mDataMethodList) {
|
|
|
Class methodParamClass = method.getParameterTypes()[2];
|