From de443db2839710e6ecdfb2f9f81b4454ada88aa8 Mon Sep 17 00:00:00 2001 From: zhangqin Date: Mon, 17 Aug 2020 13:47:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96mvp=E7=94=9F=E5=91=BD?= =?UTF-8?q?=E5=91=A8=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../quickseed/mvpretrofit/BaseResponse.java | 4 +- .../quickseed/mvpretrofit/NetworkError.java | 4 +- .../mvpretrofit/RetrofitSubscriber.java | 6 +-- .../quickseed/ui/mvp/WeatherMvpActivity.java | 2 +- .../ui/mvp/WeatherPresenterImpl.java | 10 +++- .../ui/mvp/contract/WeatherContract.java | 8 +-- config.gradle | 29 +++++----- .../sdwfqin/quicklib/base/BaseActivity.java | 30 ++++------- .../sdwfqin/quicklib/base/BaseFragment.java | 30 ++++------- .../sdwfqin/quicklib/mvp/BaseMvpActivity.java | 14 ++--- .../sdwfqin/quicklib/mvp/BaseMvpFragment.java | 2 +- .../sdwfqin/quicklib/mvp/BasePresenter.java | 40 ++++++++++++-- .../sdwfqin/quicklib/mvp/IBasePresenter.java | 13 +++++ .../mvp/{BaseView.java => IBaseView.java} | 2 +- .../sdwfqin/quicklib/mvp/SamplePresenter.java | 21 -------- .../sdwfqin/quicklib/utils/AppManager.java | 5 +- .../com/sdwfqin/quicklib/utils/GsonUtil.java | 3 ++ .../utils/rx/RxJavaLifecycleManager.java | 53 +++++++++++++++++++ sampleCommonLibrary/build.gradle | 1 + .../base/SampleBaseMvpActivity.java | 5 +- 21 files changed, 178 insertions(+), 106 deletions(-) create mode 100644 quicklib/src/main/java/com/sdwfqin/quicklib/mvp/IBasePresenter.java rename quicklib/src/main/java/com/sdwfqin/quicklib/mvp/{BaseView.java => IBaseView.java} (96%) delete mode 100644 quicklib/src/main/java/com/sdwfqin/quicklib/mvp/SamplePresenter.java create mode 100644 quicklib/src/main/java/com/sdwfqin/quicklib/utils/rx/RxJavaLifecycleManager.java diff --git a/README.md b/README.md index caad5fc..6e72ae7 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ # 导入指南 ``` groovy -def quicklib = "4.4.0" +def quicklib = "4.5.0" // quicklib(Base) implementation "com.sdwfqin.quicklib:quicklib:$quicklib" diff --git a/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/BaseResponse.java b/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/BaseResponse.java index 15a3aa0..2bbee32 100644 --- a/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/BaseResponse.java +++ b/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/BaseResponse.java @@ -1,6 +1,6 @@ package com.sdwfqin.quickseed.mvpretrofit; -import com.sdwfqin.quicklib.mvp.BaseView; +import com.sdwfqin.quicklib.mvp.IBaseView; /** * 描述: @@ -24,7 +24,7 @@ public String toString() { '}'; } - public boolean isOk(BaseView view) { + public boolean isOk(IBaseView view) { if (statusCode == 1) { return true; } else { diff --git a/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/NetworkError.java b/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/NetworkError.java index df22925..4133cd8 100644 --- a/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/NetworkError.java +++ b/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/NetworkError.java @@ -1,6 +1,6 @@ package com.sdwfqin.quickseed.mvpretrofit; -import com.sdwfqin.quicklib.mvp.BaseView; +import com.sdwfqin.quicklib.mvp.IBaseView; /** * 描述:网络统一异常处理 @@ -10,7 +10,7 @@ */ public class NetworkError { - public static void error(BaseView view, Throwable throwable) { + public static void error(IBaseView view, Throwable throwable) { RetrofitException.ResponeThrowable responeThrowable = RetrofitException.retrofitException(throwable); // 此处可以通过判断错误代码来实现根据不同的错误代码做出相应的反应 switch (responeThrowable.code) { diff --git a/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/RetrofitSubscriber.java b/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/RetrofitSubscriber.java index aa93bd1..7bfd5da 100644 --- a/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/RetrofitSubscriber.java +++ b/app/src/main/java/com/sdwfqin/quickseed/mvpretrofit/RetrofitSubscriber.java @@ -2,7 +2,7 @@ import com.blankj.utilcode.util.LogUtils; import com.blankj.utilcode.util.NetworkUtils; -import com.sdwfqin.quicklib.mvp.BaseView; +import com.sdwfqin.quicklib.mvp.IBaseView; import java.lang.ref.WeakReference; @@ -19,9 +19,9 @@ */ public abstract class RetrofitSubscriber implements Observer { - private final WeakReference mView; + private final WeakReference mView; - public RetrofitSubscriber(BaseView view) { + public RetrofitSubscriber(IBaseView view) { super(); mView = new WeakReference<>(view); } diff --git a/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/WeatherMvpActivity.java b/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/WeatherMvpActivity.java index 3e0f582..82c8b0a 100644 --- a/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/WeatherMvpActivity.java +++ b/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/WeatherMvpActivity.java @@ -34,7 +34,7 @@ protected void initEventAndData() { @Override protected WeatherContract.WeatherPresenter createPresenter() { - return new WeatherPresenterImpl(); + return new WeatherPresenterImpl(this); } @Override diff --git a/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/WeatherPresenterImpl.java b/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/WeatherPresenterImpl.java index dd53b14..bce3b42 100644 --- a/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/WeatherPresenterImpl.java +++ b/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/WeatherPresenterImpl.java @@ -1,6 +1,8 @@ package com.sdwfqin.quickseed.ui.mvp; -import com.sdwfqin.quicklib.mvp.SamplePresenter; +import androidx.lifecycle.LifecycleOwner; + +import com.sdwfqin.quicklib.mvp.BasePresenter; import com.sdwfqin.quicklib.utils.rx.RxSchedulersUtils; import com.sdwfqin.quickseed.mvpretrofit.RetrofitClient; import com.sdwfqin.quickseed.mvpretrofit.RetrofitSubscriber; @@ -17,7 +19,11 @@ * @author 张钦 * @date 2020/4/16 */ -public class WeatherPresenterImpl extends SamplePresenter implements WeatherContract.WeatherPresenter { +public class WeatherPresenterImpl extends BasePresenter implements WeatherContract.WeatherPresenter { + + public WeatherPresenterImpl(LifecycleOwner owner) { + super(owner); + } @Override public void loadData() { diff --git a/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/contract/WeatherContract.java b/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/contract/WeatherContract.java index c9137da..968a19e 100644 --- a/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/contract/WeatherContract.java +++ b/app/src/main/java/com/sdwfqin/quickseed/ui/mvp/contract/WeatherContract.java @@ -1,7 +1,7 @@ package com.sdwfqin.quickseed.ui.mvp.contract; -import com.sdwfqin.quicklib.mvp.BasePresenter; -import com.sdwfqin.quicklib.mvp.BaseView; +import com.sdwfqin.quicklib.mvp.IBasePresenter; +import com.sdwfqin.quicklib.mvp.IBaseView; import com.sdwfqin.quickseed.ui.mvvm.WeatherBean; /** @@ -13,10 +13,10 @@ */ public interface WeatherContract { - interface WeatherView extends BaseView { + interface WeatherView extends IBaseView { void refreshView(WeatherBean weatherBean); } - interface WeatherPresenter extends BasePresenter { + interface WeatherPresenter extends IBasePresenter { void loadData(); } } diff --git a/config.gradle b/config.gradle index e9e43f3..e9e2f94 100644 --- a/config.gradle +++ b/config.gradle @@ -1,7 +1,7 @@ ext { - versionCode = 202007301 - versionName = "4.4.0" + versionCode = 202008171 + versionName = "4.5.0" qmui = "2.0.0-alpha10" okhttp = "4.7.2" @@ -9,7 +9,7 @@ ext { glide = "4.11.0" vlayout = "1.2.36" camerax_version = "1.0.0-beta07" - smartrefresh = "2.0.0" + smartrefresh = "2.0.1" androidVersion = [ compileSdkVersion: 29, @@ -47,15 +47,16 @@ ext { viewDependencies = [ // qmui - "qmui" : "com.qmuiteam:qmui:$qmui", - "arch" : "com.qmuiteam:arch:$qmui", + "qmui" : "com.qmuiteam:qmui:$qmui", + "arch" : "com.qmuiteam:arch:$qmui", // brvah - "brvah" : "com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4", + "brvah" : "com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4", // smartrefresh - "smartrefresh" : "com.scwang.smart:refresh-layout-kernel:$smartrefresh", - "smartrefresh-classics": "com.scwang.smart:refresh-header-classics:$smartrefresh", + "smartrefresh" : "com.scwang.smart:refresh-layout-kernel:$smartrefresh", + "smartrefresh-classics" : "com.scwang.smart:refresh-header-classics:$smartrefresh", + "smartrefresh-classics-footer": "com.scwang.smart:refresh-footer-classics:$smartrefresh", // pickerview - "pickerview" : "com.contrarywind:Android-PickerView:4.1.9", + "pickerview" : "com.contrarywind:Android-PickerView:4.1.9", ] imageDependencies = [ @@ -74,13 +75,13 @@ ext { utilsDependencies = [ "permissionx": "com.permissionx.guolindev:permissionx:1.3.0", // utils - "utilcodex" : "com.blankj:utilcodex:1.29.0", + "utilcodex" : "com.blankj:utilcodex:1.29.0", // agentweb - "agentweb" : "com.just.agentweb:agentweb:4.1.3", + "agentweb" : "com.just.agentweb:agentweb:4.1.3", // arouter - "arouter" : "com.alibaba:arouter-api:1.5.0", - "gson" : "com.google.code.gson:gson:2.8.6", - "zxing" : "com.google.zxing:core:3.4.0", + "arouter" : "com.alibaba:arouter-api:1.5.0", + "gson" : "com.google.code.gson:gson:2.8.6", + "zxing" : "com.google.zxing:core:3.4.0", ] thirdDependencies = [ diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseActivity.java b/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseActivity.java index 313ccd9..3e669aa 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseActivity.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseActivity.java @@ -17,15 +17,15 @@ import com.qmuiteam.qmui.widget.dialog.QMUITipDialog; import com.sdwfqin.quicklib.R; import com.sdwfqin.quicklib.dialog.PermissionCustomDialog; -import com.sdwfqin.quicklib.mvp.BaseView; +import com.sdwfqin.quicklib.mvp.IBaseView; import com.sdwfqin.quicklib.utils.AppManager; import com.sdwfqin.quicklib.utils.eventbus.Event; import com.sdwfqin.quicklib.utils.eventbus.EventBusUtil; +import com.sdwfqin.quicklib.utils.rx.RxJavaLifecycleManager; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import io.reactivex.rxjava3.disposables.CompositeDisposable; import io.reactivex.rxjava3.disposables.Disposable; /** @@ -33,7 +33,7 @@ * * @author 张钦 */ -public abstract class BaseActivity extends QMUIActivity implements BaseView { +public abstract class BaseActivity extends QMUIActivity implements IBaseView { protected Activity mContext; protected V mBinding; @@ -41,7 +41,7 @@ public abstract class BaseActivity extends QMUIActivity i /** * Rxjava 订阅管理 */ - protected CompositeDisposable mCompositeDisposable; + protected RxJavaLifecycleManager mRxJavaLifecycleManager; /** * 顶部标题栏 */ @@ -59,6 +59,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { mTopBar = findViewById(R.id.quick_base_topbar); mContext = this; AppManager.addActivity(this); + mRxJavaLifecycleManager = new RxJavaLifecycleManager(this); initPresenter(); initViewModel(); initEventAndData(); @@ -84,7 +85,6 @@ protected void onStop() { @Override protected void onDestroy() { - unSubscribe(); removePresenter(); AppManager.removeActivity(this); super.onDestroy(); @@ -212,21 +212,7 @@ public void startActivitySample(Class cls) { */ @Override public void addSubscribe(Disposable subscription) { - if (mCompositeDisposable == null) { - mCompositeDisposable = new CompositeDisposable(); - } - mCompositeDisposable.add(subscription); - } - - /** - * RxJava 解除所有订阅者 - */ - public void unSubscribe() { - if (mCompositeDisposable != null) { - mCompositeDisposable.dispose(); - mCompositeDisposable.clear(); - mCompositeDisposable = new CompositeDisposable(); - } + mRxJavaLifecycleManager.addDisposable(subscription); } // ==================== 权限管理 ==================== @@ -273,6 +259,10 @@ protected void initPresenter() { } + /** + * 改为Lifecycle管理 + */ + @Deprecated protected void removePresenter() { } diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseFragment.java b/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseFragment.java index eb80077..c19ec30 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseFragment.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseFragment.java @@ -14,14 +14,14 @@ import com.blankj.utilcode.util.ToastUtils; import com.qmuiteam.qmui.widget.dialog.QMUITipDialog; -import com.sdwfqin.quicklib.mvp.BaseView; +import com.sdwfqin.quicklib.mvp.IBaseView; import com.sdwfqin.quicklib.utils.eventbus.Event; import com.sdwfqin.quicklib.utils.eventbus.EventBusUtil; +import com.sdwfqin.quicklib.utils.rx.RxJavaLifecycleManager; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import io.reactivex.rxjava3.disposables.CompositeDisposable; import io.reactivex.rxjava3.disposables.Disposable; /** @@ -30,7 +30,7 @@ * @author 张钦 * @date 2017/8/3 */ -public abstract class BaseFragment extends Fragment implements BaseView { +public abstract class BaseFragment extends Fragment implements IBaseView { protected V mBinding; protected BaseActivity mActivity; @@ -53,7 +53,7 @@ public abstract class BaseFragment extends Fragment imple @Deprecated protected boolean mIsLoad = false; private QMUITipDialog mQmuiTipDialog; - protected CompositeDisposable mCompositeDisposable; + protected RxJavaLifecycleManager mRxJavaLifecycleManager; /** * Fragment的UI是否是可见 @@ -76,6 +76,7 @@ public void setUserVisibleHint(boolean isVisibleToUser) { public void onAttach(Context context) { mActivity = (BaseActivity) context; mContext = context; + mRxJavaLifecycleManager = new RxJavaLifecycleManager(this); super.onAttach(context); } @@ -136,7 +137,6 @@ private void baseLazyLoad() { @Override public void onDestroyView() { mIsPrepared = false; - unSubscribe(); removePresenter(); mBinding = null; super.onDestroyView(); @@ -256,21 +256,7 @@ public void startActivitySample(Class cls) { */ @Override public void addSubscribe(Disposable subscription) { - if (mCompositeDisposable == null) { - mCompositeDisposable = new CompositeDisposable(); - } - mCompositeDisposable.add(subscription); - } - - /** - * RxJava 解除所有订阅者 - */ - public void unSubscribe() { - if (mCompositeDisposable != null) { - mCompositeDisposable.dispose(); - mCompositeDisposable.clear(); - mCompositeDisposable = new CompositeDisposable(); - } + mRxJavaLifecycleManager.addDisposable(subscription); } protected void initViewModel() { @@ -281,6 +267,10 @@ protected void initPresenter() { } + /** + * 改为Lifecycle管理 + */ + @Deprecated protected void removePresenter() { } diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseMvpActivity.java b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseMvpActivity.java index 40feb2d..fb786b4 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseMvpActivity.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseMvpActivity.java @@ -9,7 +9,7 @@ * * @author 张钦 */ -public abstract class BaseMvpActivity extends BaseActivity { +public abstract class BaseMvpActivity extends BaseActivity { protected T mPresenter; @@ -21,12 +21,12 @@ protected void initPresenter() { } } - @Override - protected void removePresenter() { - if (mPresenter != null) { - mPresenter.detachView(); - } - } +// @Override +// protected void removePresenter() { +// if (mPresenter != null) { +// mPresenter.detachView(); +// } +// } /** * 创建Presenter diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseMvpFragment.java b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseMvpFragment.java index 9253913..66dca75 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseMvpFragment.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseMvpFragment.java @@ -10,7 +10,7 @@ * @author 张钦 * @date 2017/8/3 */ -public abstract class BaseMvpFragment extends BaseFragment { +public abstract class BaseMvpFragment extends BaseFragment { protected T mPresenter; diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BasePresenter.java b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BasePresenter.java index e062707..7e26a7d 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BasePresenter.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BasePresenter.java @@ -1,13 +1,45 @@ package com.sdwfqin.quicklib.mvp; +import androidx.lifecycle.Lifecycle; +import androidx.lifecycle.LifecycleObserver; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.OnLifecycleEvent; + +import com.sdwfqin.quicklib.utils.rx.RxJavaLifecycleManager; + +import static androidx.lifecycle.Lifecycle.State.DESTROYED; + /** - * 描述:Presenter基类 + * 描述:SamplePresenter * * @author zhangqin */ -public interface BasePresenter { +public abstract class BasePresenter implements IBasePresenter, LifecycleObserver { + + protected T mView; + private RxJavaLifecycleManager mRxJavaLifecycleManager; + + public BasePresenter(LifecycleOwner owner) { + if (owner.getLifecycle().getCurrentState() == DESTROYED) { + // ignore + return; + } + owner.getLifecycle().addObserver(this); + mRxJavaLifecycleManager = new RxJavaLifecycleManager(owner); + } + + @Override + public void attachView(T view) { + mView = view; + } - void attachView(T view); + @Override + public void detachView() { + this.mView = null; + } - void detachView(); + @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) + private void onDestroy() { + detachView(); + } } diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/IBasePresenter.java b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/IBasePresenter.java new file mode 100644 index 0000000..8b902d6 --- /dev/null +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/IBasePresenter.java @@ -0,0 +1,13 @@ +package com.sdwfqin.quicklib.mvp; + +/** + * 描述:Presenter基类 + * + * @author zhangqin + */ +public interface IBasePresenter { + + void attachView(T view); + + void detachView(); +} diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseView.java b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/IBaseView.java similarity index 96% rename from quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseView.java rename to quicklib/src/main/java/com/sdwfqin/quicklib/mvp/IBaseView.java index f1c32ff..46375f2 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/BaseView.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/IBaseView.java @@ -9,7 +9,7 @@ * * @author zhangqin */ -public interface BaseView { +public interface IBaseView { /** * 显示吐司 diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/SamplePresenter.java b/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/SamplePresenter.java deleted file mode 100644 index b84f29f..0000000 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/mvp/SamplePresenter.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.sdwfqin.quicklib.mvp; - -/** - * 描述:SamplePresenter - * - * @author zhangqin - */ -public abstract class SamplePresenter implements BasePresenter { - - protected T mView; - - @Override - public void attachView(T view) { - mView = view; - } - - @Override - public void detachView() { - this.mView = null; - } -} diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/utils/AppManager.java b/quicklib/src/main/java/com/sdwfqin/quicklib/utils/AppManager.java index bc8ed50..cacc5d9 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/utils/AppManager.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/utils/AppManager.java @@ -6,10 +6,13 @@ /** * 描述:Activity栈管理 + *

+ * 现在有了更完善的工具 {@link com.blankj.utilcode.util.ActivityUtils} * - * @author 张钦 + * @author 张钦 * @date 2017/11/11 */ +@Deprecated public class AppManager { private static Stack activityStack = new Stack<>(); diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/utils/GsonUtil.java b/quicklib/src/main/java/com/sdwfqin/quicklib/utils/GsonUtil.java index f1ada18..6851473 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/utils/GsonUtil.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/utils/GsonUtil.java @@ -9,9 +9,12 @@ /** * 描述:Gson工具类 + *

+ * 现在有了更完善的工具 {@link com.blankj.utilcode.util.GsonUtils} * * @author 张钦 */ +@Deprecated public class GsonUtil { private static Gson gson = null; diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/utils/rx/RxJavaLifecycleManager.java b/quicklib/src/main/java/com/sdwfqin/quicklib/utils/rx/RxJavaLifecycleManager.java new file mode 100644 index 0000000..736095f --- /dev/null +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/utils/rx/RxJavaLifecycleManager.java @@ -0,0 +1,53 @@ +package com.sdwfqin.quicklib.utils.rx; + +import androidx.lifecycle.Lifecycle; +import androidx.lifecycle.LifecycleObserver; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.OnLifecycleEvent; + +import io.reactivex.rxjava3.disposables.CompositeDisposable; +import io.reactivex.rxjava3.disposables.Disposable; + +import static androidx.lifecycle.Lifecycle.State.DESTROYED; + +/** + * RxJava生命周期管理 + *

+ * + * @author 张钦 + * @date 2020/8/11 + */ +public class RxJavaLifecycleManager implements LifecycleObserver { + + private CompositeDisposable compositeDisposable; + + public RxJavaLifecycleManager(LifecycleOwner owner) { + if (owner.getLifecycle().getCurrentState() == DESTROYED) { + // ignore + return; + } + owner.getLifecycle().addObserver(this); + } + + public void addDisposable(Disposable disposable) { + if (compositeDisposable == null) { + compositeDisposable = new CompositeDisposable(); + } + if (disposable != null) { + compositeDisposable.add(disposable); + } + + } + + public void dispose() { + if (compositeDisposable != null) { + compositeDisposable.dispose(); + } + compositeDisposable = null; + } + + @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) + private void onDestroy() { + dispose(); + } +} diff --git a/sampleCommonLibrary/build.gradle b/sampleCommonLibrary/build.gradle index 264883f..febaca4 100644 --- a/sampleCommonLibrary/build.gradle +++ b/sampleCommonLibrary/build.gradle @@ -41,6 +41,7 @@ dependencies { api viewDependencies["brvah"] api viewDependencies["smartrefresh"] api viewDependencies["smartrefresh-classics"] + api viewDependencies["smartrefresh-classics-footer"] api viewDependencies["pickerview"] api imageDependencies["camera-camera2"] diff --git a/sampleCommonLibrary/src/main/java/io/github/sdwfqin/samplecommonlibrary/base/SampleBaseMvpActivity.java b/sampleCommonLibrary/src/main/java/io/github/sdwfqin/samplecommonlibrary/base/SampleBaseMvpActivity.java index 3fe9195..1d2cbf3 100644 --- a/sampleCommonLibrary/src/main/java/io/github/sdwfqin/samplecommonlibrary/base/SampleBaseMvpActivity.java +++ b/sampleCommonLibrary/src/main/java/io/github/sdwfqin/samplecommonlibrary/base/SampleBaseMvpActivity.java @@ -9,7 +9,8 @@ import com.qmuiteam.qmui.skin.QMUISkinManager; import com.qmuiteam.qmui.util.QMUIStatusBarHelper; import com.sdwfqin.quicklib.mvp.BaseMvpActivity; -import com.sdwfqin.quicklib.mvp.BasePresenter; +import com.sdwfqin.quicklib.mvp.IBasePresenter; +import com.sdwfqin.quicklib.mvp.IBaseView; import io.github.sdwfqin.samplecommonlibrary.utils.skin.QMUISkinCustManager; @@ -20,7 +21,7 @@ * @author 张钦 * @date 2019-12-06 */ -public abstract class SampleBaseMvpActivity extends BaseMvpActivity { +public abstract class SampleBaseMvpActivity extends BaseMvpActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) {