Commit 367b38f0fa797be2a3668b8bc06bda8a2ef9b604
1 parent
3f5d3adb
1 同步更新B端基类
Showing
14 changed files
with
1280 additions
and
239 deletions
core/base/src/main/java/com/cnlive/core/libs/base/frame/activity/BaseActivity.java
| 1 | package com.cnlive.core.libs.base.frame.activity; | 1 | package com.cnlive.core.libs.base.frame.activity; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import android.annotation.SuppressLint; | ||
| 4 | import android.app.Activity; | 5 | import android.app.Activity; |
| 5 | import android.content.Context; | 6 | import android.content.Context; |
| 6 | -import android.content.DialogInterface; | ||
| 7 | import android.content.Intent; | 7 | import android.content.Intent; |
| 8 | import android.content.pm.ActivityInfo; | 8 | import android.content.pm.ActivityInfo; |
| 9 | import android.content.pm.PackageManager; | 9 | import android.content.pm.PackageManager; |
| 10 | import android.content.res.Configuration; | 10 | import android.content.res.Configuration; |
| 11 | import android.content.res.Resources; | 11 | import android.content.res.Resources; |
| 12 | import android.graphics.Bitmap; | 12 | import android.graphics.Bitmap; |
| 13 | -import android.graphics.Color; | 13 | +import android.graphics.drawable.Drawable; |
| 14 | import android.net.Uri; | 14 | import android.net.Uri; |
| 15 | import android.os.Build; | 15 | import android.os.Build; |
| 16 | import android.os.Bundle; | 16 | import android.os.Bundle; |
| @@ -20,42 +20,48 @@ import android.provider.Settings; | @@ -20,42 +20,48 @@ import android.provider.Settings; | ||
| 20 | import android.text.TextUtils; | 20 | import android.text.TextUtils; |
| 21 | import android.util.DisplayMetrics; | 21 | import android.util.DisplayMetrics; |
| 22 | import android.util.Log; | 22 | import android.util.Log; |
| 23 | +import android.view.Gravity; | ||
| 23 | import android.view.MotionEvent; | 24 | import android.view.MotionEvent; |
| 24 | import android.view.View; | 25 | import android.view.View; |
| 25 | import android.view.ViewGroup; | 26 | import android.view.ViewGroup; |
| 26 | -import android.view.Window; | ||
| 27 | import android.view.WindowManager; | 27 | import android.view.WindowManager; |
| 28 | import android.view.inputmethod.InputMethodManager; | 28 | import android.view.inputmethod.InputMethodManager; |
| 29 | 29 | ||
| 30 | -import androidx.annotation.ColorInt; | ||
| 31 | import androidx.annotation.ColorRes; | 30 | import androidx.annotation.ColorRes; |
| 32 | import androidx.annotation.DrawableRes; | 31 | import androidx.annotation.DrawableRes; |
| 33 | import androidx.annotation.IntRange; | 32 | import androidx.annotation.IntRange; |
| 34 | import androidx.annotation.NonNull; | 33 | import androidx.annotation.NonNull; |
| 35 | import androidx.annotation.Nullable; | 34 | import androidx.annotation.Nullable; |
| 36 | import androidx.annotation.StringRes; | 35 | import androidx.annotation.StringRes; |
| 37 | -import androidx.appcompat.app.AlertDialog; | ||
| 38 | import androidx.core.app.ActivityCompat; | 36 | import androidx.core.app.ActivityCompat; |
| 39 | import androidx.core.content.ContextCompat; | 37 | import androidx.core.content.ContextCompat; |
| 40 | import androidx.databinding.DataBindingUtil; | 38 | import androidx.databinding.DataBindingUtil; |
| 41 | import androidx.databinding.ViewDataBinding; | 39 | import androidx.databinding.ViewDataBinding; |
| 42 | import androidx.fragment.app.Fragment; | 40 | import androidx.fragment.app.Fragment; |
| 43 | 41 | ||
| 42 | +import com.alibaba.android.arouter.facade.Postcard; | ||
| 43 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 44 | import com.alibaba.android.arouter.launcher.ARouter; | 44 | import com.alibaba.android.arouter.launcher.ARouter; |
| 45 | -import com.cnlive.core.libs.base.application.AppConfig; | 45 | +import com.cnlive.cloud.base.BuildConfig; |
| 46 | +import com.cnlive.cloud.base.R; | ||
| 46 | import com.cnlive.core.libs.base.frame.fragment.BaseFragment; | 47 | import com.cnlive.core.libs.base.frame.fragment.BaseFragment; |
| 47 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; | 48 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; |
| 48 | import com.cnlive.core.libs.base.frame.view.BaseView; | 49 | import com.cnlive.core.libs.base.frame.view.BaseView; |
| 49 | import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; | 50 | import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; |
| 50 | -import com.cnlive.core.libs.base.network.manager.SubscriptionManager; | 51 | +import com.cnlive.core.libs.base.listener.Callback; |
| 52 | +import com.cnlive.core.libs.base.network.manager.RxManager; | ||
| 53 | +import com.cnlive.core.libs.base.ui.widget.SelectDialog; | ||
| 54 | +import com.cnlive.core.libs.base.util.AlertUtil; | ||
| 51 | import com.cnlive.core.libs.base.util.AppManager; | 55 | import com.cnlive.core.libs.base.util.AppManager; |
| 56 | +import com.cnlive.core.libs.base.util.BaseHelpUtil; | ||
| 57 | +import com.cnlive.core.libs.base.util.GlobalLifeCircleListener; | ||
| 58 | +import com.cnlive.core.libs.base.util.LifeCircleListener; | ||
| 52 | import com.cnlive.core.libs.base.util.ReflectUtil; | 59 | import com.cnlive.core.libs.base.util.ReflectUtil; |
| 60 | +import com.cnlive.core.libs.base.util.SharedPreferencesHelper; | ||
| 53 | import com.cnlive.core.libs.base.util.StatusBarConfig; | 61 | import com.cnlive.core.libs.base.util.StatusBarConfig; |
| 54 | import com.cnlive.core.libs.base.util.StatusBarUtil; | 62 | import com.cnlive.core.libs.base.util.StatusBarUtil; |
| 55 | -import com.cnlive.cloud.base.R; | ||
| 56 | import com.hannesdorfmann.mosby3.mvp.MvpActivity; | 63 | import com.hannesdorfmann.mosby3.mvp.MvpActivity; |
| 57 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; | 64 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 58 | -import com.hannesdorfmann.mosby3.mvp.delegate.ActivityMvpDelegate; | ||
| 59 | import com.me.yokeyword.fragmentation.ExtraTransaction; | 65 | import com.me.yokeyword.fragmentation.ExtraTransaction; |
| 60 | import com.me.yokeyword.fragmentation.Fragmentation; | 66 | import com.me.yokeyword.fragmentation.Fragmentation; |
| 61 | import com.me.yokeyword.fragmentation.ISupportActivity; | 67 | import com.me.yokeyword.fragmentation.ISupportActivity; |
| @@ -75,6 +81,9 @@ import java.util.List; | @@ -75,6 +81,9 @@ import java.util.List; | ||
| 75 | import java.util.Observable; | 81 | import java.util.Observable; |
| 76 | import java.util.Observer; | 82 | import java.util.Observer; |
| 77 | 83 | ||
| 84 | +import io.reactivex.disposables.CompositeDisposable; | ||
| 85 | +import io.reactivex.disposables.Disposable; | ||
| 86 | + | ||
| 78 | 87 | ||
| 79 | /** | 88 | /** |
| 80 | * @author ys | 89 | * @author ys |
| @@ -86,8 +95,6 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -86,8 +95,6 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 86 | private ViewDataBinding baseBinding; | 95 | private ViewDataBinding baseBinding; |
| 87 | //获取TAG的activity名称 | 96 | //获取TAG的activity名称 |
| 88 | public final String TAG = this.getClass().getSimpleName(); | 97 | public final String TAG = this.getClass().getSimpleName(); |
| 89 | - //是否显示标题栏 | ||
| 90 | - private boolean isShowTitle = true; | ||
| 91 | //是否显示状态栏 | 98 | //是否显示状态栏 |
| 92 | private boolean isShowStatusBar = true; | 99 | private boolean isShowStatusBar = true; |
| 93 | public Context context; | 100 | public Context context; |
| @@ -110,9 +117,17 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -110,9 +117,17 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 110 | private boolean isUserClickAllowBtn = false;//用户是否点击允许按钮 | 117 | private boolean isUserClickAllowBtn = false;//用户是否点击允许按钮 |
| 111 | private boolean isShowRefuseDialog = true;//是否显示拒绝提示框 | 118 | private boolean isShowRefuseDialog = true;//是否显示拒绝提示框 |
| 112 | private String[] userSetPermission; | 119 | private String[] userSetPermission; |
| 120 | + private SelectDialog permissionTipDialog; | ||
| 113 | private Handler myActHandler; | 121 | private Handler myActHandler; |
| 114 | private List<Observable> observableList; | 122 | private List<Observable> observableList; |
| 115 | private boolean isCreateDefultEmptyView = true;//如果没有填充布局,是否设置默认布局,默认是设置的 | 123 | private boolean isCreateDefultEmptyView = true;//如果没有填充布局,是否设置默认布局,默认是设置的 |
| 124 | + private LifeCircleListener lifeCircleListener; //快速管理生命周期 | ||
| 125 | + private static GlobalLifeCircleListener globalLifeCircleListener; //全局生命周期 | ||
| 126 | + | ||
| 127 | + public boolean isActive = false; //当前Activity是否处于前台 | ||
| 128 | + public boolean isAlive = false; //当前Activity是否处于存活状态 | ||
| 129 | + private CompositeDisposable destoryDisposable;//生命周期在destory销毁 | ||
| 130 | + private CompositeDisposable pauseDisposable;//生命周期在onPause销毁 | ||
| 116 | 131 | ||
| 117 | public final ViewDataBinding getBaseBinding() { | 132 | public final ViewDataBinding getBaseBinding() { |
| 118 | return baseBinding; | 133 | return baseBinding; |
| @@ -122,55 +137,213 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -122,55 +137,213 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 122 | @Override | 137 | @Override |
| 123 | protected void onCreate(@Nullable Bundle savedInstanceState) { | 138 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 124 | super.onCreate(savedInstanceState); | 139 | super.onCreate(savedInstanceState); |
| 125 | - if (0 != getBindLayoutId()) { | ||
| 126 | - baseBinding = DataBindingUtil.setContentView(this, getBindLayoutId()); | ||
| 127 | - } else if (0 != getViewLayoutId()) { | ||
| 128 | - setContentView(getViewLayoutId()); | ||
| 129 | - } | ||
| 130 | context = this; | 140 | context = this; |
| 131 | me = this; | 141 | me = this; |
| 142 | + isAlive = true; | ||
| 132 | this.savedInstanceState = savedInstanceState; | 143 | this.savedInstanceState = savedInstanceState; |
| 133 | -// //路由参数初始化 | ||
| 134 | -// ARouter.getInstance().inject(this); | 144 | + initRxjava(); |
| 145 | + //路由参数初始化 | ||
| 146 | + ARouter.getInstance().inject(this); | ||
| 135 | //activity管理 | 147 | //activity管理 |
| 136 | AppManager.getInstance().pushActivity(me); | 148 | AppManager.getInstance().pushActivity(me); |
| 137 | - //创建订阅映射 | ||
| 138 | - SubscriptionManager.getInstance().setCurrentDisposables(TAG); | ||
| 139 | //fragment管理 | 149 | //fragment管理 |
| 140 | mDelegate.onCreate(savedInstanceState); | 150 | mDelegate.onCreate(savedInstanceState); |
| 141 | mSwipeDelegate.onCreate(savedInstanceState); | 151 | mSwipeDelegate.onCreate(savedInstanceState); |
| 142 | init(savedInstanceState); | 152 | init(savedInstanceState); |
| 153 | +// if (!isShowTitle) { | ||
| 154 | +// requestWindowFeature(Window.FEATURE_NO_TITLE); | ||
| 155 | +// } | ||
| 156 | + if (!isShowStatusBar) { | ||
| 157 | + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | ||
| 158 | + , WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
| 159 | + } | ||
| 160 | + if (0 != getBindLayoutId()) { | ||
| 161 | + baseBinding = DataBindingUtil.setContentView(this, getBindLayoutId()); | ||
| 162 | + } else if (0 != getViewLayoutId()) { | ||
| 163 | + setContentView(getViewLayoutId()); | ||
| 164 | + } | ||
| 143 | //两种视图都没有设置,就加载默认跟视图,用于fragment切换 | 165 | //两种视图都没有设置,就加载默认跟视图,用于fragment切换 |
| 144 | - if (isCreateDefultEmptyView) { | 166 | + else if (isCreateDefultEmptyView) { |
| 145 | if (0 == getBindLayoutId() && 0 == getViewLayoutId()) { | 167 | if (0 == getBindLayoutId() && 0 == getViewLayoutId()) { |
| 146 | setContentView(R.layout.base_activity_main); | 168 | setContentView(R.layout.base_activity_main); |
| 147 | } | 169 | } |
| 148 | } | 170 | } |
| 149 | - if (null == observableList) { | ||
| 150 | - observableList = new ArrayList<>(); | ||
| 151 | - } | ||
| 152 | - | ||
| 153 | //设置binding数据 | 171 | //设置binding数据 |
| 154 | if (null != baseBinding) { | 172 | if (null != baseBinding) { |
| 155 | initBindingLayoutData(baseBinding); | 173 | initBindingLayoutData(baseBinding); |
| 174 | + if (isViewAttached()) { | ||
| 175 | + getMvpView().initActBindingLayout(this, baseBinding); | ||
| 176 | + } | ||
| 156 | } | 177 | } |
| 157 | if (null != getIntent()) { | 178 | if (null != getIntent()) { |
| 158 | initParams(getIntent()); | 179 | initParams(getIntent()); |
| 159 | } | 180 | } |
| 160 | //初始化控件 | 181 | //初始化控件 |
| 161 | initView(); | 182 | initView(); |
| 162 | - if (!isShowTitle) { | ||
| 163 | - requestWindowFeature(Window.FEATURE_NO_TITLE); | ||
| 164 | - } | ||
| 165 | - | ||
| 166 | - if (!isShowStatusBar) { | ||
| 167 | - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | ||
| 168 | - , WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
| 169 | - } | ||
| 170 | //设置数据 | 183 | //设置数据 |
| 171 | initData(); | 184 | initData(); |
| 185 | + if (null == observableList) { | ||
| 186 | + observableList = new ArrayList<>(); | ||
| 187 | + } | ||
| 172 | //是否开启滑动返回 | 188 | //是否开启滑动返回 |
| 173 | setSwipeBackEnable(isOpenSwipBack); | 189 | setSwipeBackEnable(isOpenSwipBack); |
| 190 | + //生命周期监听 | ||
| 191 | + if (lifeCircleListener != null) { | ||
| 192 | + lifeCircleListener.onCreate(); | ||
| 193 | + } | ||
| 194 | + //全局生命周期监听 | ||
| 195 | + if (globalLifeCircleListener != null) { | ||
| 196 | + globalLifeCircleListener.onCreate(me, me.getClass().getName()); | ||
| 197 | + } | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + private void initRxjava() { | ||
| 201 | + pauseDisposable = new CompositeDisposable(); | ||
| 202 | + destoryDisposable = new CompositeDisposable(); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + protected void init(@Nullable Bundle savedInstanceState) { | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + protected void initParams(Intent params) { | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + /** | ||
| 212 | + * 获取自己的databinding | ||
| 213 | + * | ||
| 214 | + * @param baseBinding | ||
| 215 | + */ | ||
| 216 | + protected void initBindingLayoutData(ViewDataBinding baseBinding) { | ||
| 217 | + | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + /** | ||
| 221 | + * 初始化控件 | ||
| 222 | + */ | ||
| 223 | + protected abstract void initView(); | ||
| 224 | + | ||
| 225 | + | ||
| 226 | + /** | ||
| 227 | + * 设置数据 | ||
| 228 | + */ | ||
| 229 | + protected void initData() { | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + /** | ||
| 233 | + * 添加订阅 | ||
| 234 | + * Pause 销毁 | ||
| 235 | + * | ||
| 236 | + * @param disposable | ||
| 237 | + * @return | ||
| 238 | + */ | ||
| 239 | + public Disposable addPauseDisPosable(Disposable disposable) { | ||
| 240 | + if (null != disposable) { | ||
| 241 | + if (null != pauseDisposable) { | ||
| 242 | + pauseDisposable.add(disposable); | ||
| 243 | + } | ||
| 244 | + } | ||
| 245 | + return disposable; | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + /** | ||
| 249 | + * 添加订阅 | ||
| 250 | + * Destory 销毁 | ||
| 251 | + * | ||
| 252 | + * @param disposable | ||
| 253 | + * @return | ||
| 254 | + */ | ||
| 255 | + public Disposable addDestoryDisPosable(Disposable disposable) { | ||
| 256 | + if (null != disposable) { | ||
| 257 | + if (null != destoryDisposable) { | ||
| 258 | + destoryDisposable.add(disposable); | ||
| 259 | + } | ||
| 260 | + } | ||
| 261 | + return disposable; | ||
| 262 | + } | ||
| 263 | + | ||
| 264 | + /** | ||
| 265 | + * 实例化路由-对象 | ||
| 266 | + */ | ||
| 267 | + public <T extends IProvider> T initRouterImpl(String routerPath) { | ||
| 268 | + T obj = null; | ||
| 269 | + try { | ||
| 270 | + obj = (T) ARouter.getInstance().build(routerPath).navigation(this); | ||
| 271 | + } catch (Exception ignored) { | ||
| 272 | + } | ||
| 273 | + return obj; | ||
| 274 | + } | ||
| 275 | + | ||
| 276 | + /** | ||
| 277 | + * 获取资源颜色 | ||
| 278 | + * | ||
| 279 | + * @param colorId | ||
| 280 | + * @return | ||
| 281 | + */ | ||
| 282 | + public int getResourceColor(@ColorRes int colorId) { | ||
| 283 | + return BaseHelpUtil.getResourceColor(me, colorId); | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + /** | ||
| 287 | + * 获取资源字符串 | ||
| 288 | + * | ||
| 289 | + * @param stringId | ||
| 290 | + * @return | ||
| 291 | + */ | ||
| 292 | + public String getResourceStr(@StringRes int stringId) { | ||
| 293 | + return BaseHelpUtil.getResourceStr(me, stringId); | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + /** | ||
| 297 | + * 获取资源 | ||
| 298 | + * | ||
| 299 | + * @param drawableId | ||
| 300 | + * @return | ||
| 301 | + */ | ||
| 302 | + public Drawable getResourceDrawable(@DrawableRes int drawableId) { | ||
| 303 | + return BaseHelpUtil.getResourceDrawable(me, drawableId); | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + /** | ||
| 307 | + * 用户提示 | ||
| 308 | + */ | ||
| 309 | + public void showToast(String message) { | ||
| 310 | + AlertUtil.showDeftToast(me, message); | ||
| 311 | + } | ||
| 312 | + | ||
| 313 | + /** | ||
| 314 | + * Arouter跳转 | ||
| 315 | + * | ||
| 316 | + * @param routerPath | ||
| 317 | + * @return | ||
| 318 | + */ | ||
| 319 | + public Postcard goToRouter(String routerPath) { | ||
| 320 | + return ARouter.getInstance().build(routerPath); | ||
| 321 | + } | ||
| 322 | + | ||
| 323 | + /** | ||
| 324 | + * Arouter跳转无参数 | ||
| 325 | + * | ||
| 326 | + * @param routerPath | ||
| 327 | + * @return | ||
| 328 | + */ | ||
| 329 | + public void goToRouterNoParams(String routerPath) { | ||
| 330 | + ARouter.getInstance().build(routerPath).navigation(this); | ||
| 331 | + } | ||
| 332 | + | ||
| 333 | + /** | ||
| 334 | + * 实例化路由-对象 (异步) | ||
| 335 | + */ | ||
| 336 | + public <T extends IProvider> void initRouterImpl(String routerPath, Callback<T> callback) { | ||
| 337 | + if (callback == null) return; | ||
| 338 | + | ||
| 339 | + T obj = null; | ||
| 340 | + try { | ||
| 341 | + obj = (T) ARouter.getInstance().build(routerPath).navigation(this); | ||
| 342 | + } catch (Exception ignored) { | ||
| 343 | + } | ||
| 344 | + | ||
| 345 | + if (obj != null) callback.call(obj); | ||
| 346 | + else if (BuildConfig.DEBUG) AlertUtil.showDeftToast(this, "功能暂未开放"); | ||
| 174 | } | 347 | } |
| 175 | 348 | ||
| 176 | 349 | ||
| @@ -250,34 +423,37 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -250,34 +423,37 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 250 | return StatusBarUtil.getStatusBarHeight(this); | 423 | return StatusBarUtil.getStatusBarHeight(this); |
| 251 | } | 424 | } |
| 252 | 425 | ||
| 253 | - /**将标题视图自适应沉浸式状态栏 | 426 | + /** |
| 427 | + * 将标题视图自适应沉浸式状态栏 | ||
| 428 | + * | ||
| 254 | * @param view | 429 | * @param view |
| 255 | */ | 430 | */ |
| 256 | - public void setTitleViewAdjustImmersiveStatusBar(View view) { | ||
| 257 | - if (null==view){ | ||
| 258 | - Log.e(TAG,"setTitleViewAdjustImmersiveStatusBar->view is Null"); | 431 | + public void setTitleViewAdjustImmersiveStatusBar(View view) { |
| 432 | + if (null == view) { | ||
| 433 | + Log.e(TAG, "setTitleViewAdjustImmersiveStatusBar->view is Null"); | ||
| 259 | } | 434 | } |
| 260 | ViewGroup.LayoutParams params = view.getLayoutParams(); | 435 | ViewGroup.LayoutParams params = view.getLayoutParams(); |
| 261 | - if (null==params){ | ||
| 262 | - Log.e(TAG,"setTitleViewAdjustImmersiveStatusBar->LayoutParams is Null 无法将标题视图自适应沉浸式状态栏!"); | 436 | + if (null == params) { |
| 437 | + Log.e(TAG, "setTitleViewAdjustImmersiveStatusBar->LayoutParams is Null 无法将标题视图自适应沉浸式状态栏!"); | ||
| 263 | return; | 438 | return; |
| 264 | } | 439 | } |
| 265 | int oldHeight = params.height; | 440 | int oldHeight = params.height; |
| 266 | - if (oldHeight<=0){ | ||
| 267 | - Log.e(TAG,"setTitleViewAdjustImmersiveStatusBar->无法获取标题视图高度!"); | 441 | + if (oldHeight <= 0) { |
| 442 | + Log.e(TAG, "setTitleViewAdjustImmersiveStatusBar->无法获取标题视图高度!"); | ||
| 268 | return; | 443 | return; |
| 269 | } | 444 | } |
| 270 | - if (0==getStatusBarHeight()){ | ||
| 271 | - Log.e(TAG,"setTitleViewAdjustImmersiveStatusBar->无法获取状态栏高度!"); | 445 | + if (0 == getStatusBarHeight()) { |
| 446 | + Log.e(TAG, "setTitleViewAdjustImmersiveStatusBar->无法获取状态栏高度!"); | ||
| 272 | return; | 447 | return; |
| 273 | } | 448 | } |
| 274 | params.height = oldHeight + getStatusBarHeight(); | 449 | params.height = oldHeight + getStatusBarHeight(); |
| 275 | view.setLayoutParams(params); | 450 | view.setLayoutParams(params); |
| 276 | } | 451 | } |
| 452 | + | ||
| 277 | /** | 453 | /** |
| 278 | * 设置状态栏字体颜色 | 454 | * 设置状态栏字体颜色 |
| 279 | */ | 455 | */ |
| 280 | - // 定义适用于参数的注解,限定取值范围为{STATUS_OPEN, STATUS_CLOSE} | 456 | + // 定义适用于参数的注解,限定取值范围为{BLACK, WHITE} |
| 281 | public void setStatusBarTextColor(@StatusBarConfig.Unit final int type) { | 457 | public void setStatusBarTextColor(@StatusBarConfig.Unit final int type) { |
| 282 | if (type == StatusBarConfig.BLACK) { | 458 | if (type == StatusBarConfig.BLACK) { |
| 283 | StatusBarUtil.setStatusBarWrite(this); | 459 | StatusBarUtil.setStatusBarWrite(this); |
| @@ -295,6 +471,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -295,6 +471,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 295 | isCreateDefultEmptyView = enable; | 471 | isCreateDefultEmptyView = enable; |
| 296 | } | 472 | } |
| 297 | 473 | ||
| 474 | + /** | ||
| 475 | + * 初始化handler | ||
| 476 | + * | ||
| 477 | + * @return | ||
| 478 | + */ | ||
| 298 | public Handler getMyActHandler() { | 479 | public Handler getMyActHandler() { |
| 299 | if (null == myActHandler) { | 480 | if (null == myActHandler) { |
| 300 | myActHandler = new Handler() { | 481 | myActHandler = new Handler() { |
| @@ -308,6 +489,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -308,6 +489,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 308 | return myActHandler; | 489 | return myActHandler; |
| 309 | } | 490 | } |
| 310 | 491 | ||
| 492 | + /** | ||
| 493 | + * 收到Activity的handler | ||
| 494 | + * | ||
| 495 | + * @param msg | ||
| 496 | + */ | ||
| 311 | public void onReceiveActHandleMessage(@NonNull Message msg) { | 497 | public void onReceiveActHandleMessage(@NonNull Message msg) { |
| 312 | if (null != getMvpView()) { | 498 | if (null != getMvpView()) { |
| 313 | getMvpView().onReceiveActHandleMessage(msg); | 499 | getMvpView().onReceiveActHandleMessage(msg); |
| @@ -337,6 +523,12 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -337,6 +523,12 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 337 | } | 523 | } |
| 338 | } | 524 | } |
| 339 | 525 | ||
| 526 | + /** | ||
| 527 | + * 收到观察者通知 | ||
| 528 | + * | ||
| 529 | + * @param o | ||
| 530 | + * @param data | ||
| 531 | + */ | ||
| 340 | @Override | 532 | @Override |
| 341 | public void update(Observable o, Object data) { | 533 | public void update(Observable o, Object data) { |
| 342 | if (null == getMvpView()) { | 534 | if (null == getMvpView()) { |
| @@ -360,6 +552,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -360,6 +552,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 360 | /** | 552 | /** |
| 361 | * 显示竖屏 | 553 | * 显示竖屏 |
| 362 | */ | 554 | */ |
| 555 | + @SuppressLint("SourceLockedOrientationActivity") | ||
| 363 | public void showPortraitScreen() { | 556 | public void showPortraitScreen() { |
| 364 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | 557 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 365 | } | 558 | } |
| @@ -367,46 +560,22 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -367,46 +560,22 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 367 | /** | 560 | /** |
| 368 | * 显示横屏 | 561 | * 显示横屏 |
| 369 | */ | 562 | */ |
| 563 | + @SuppressLint("SourceLockedOrientationActivity") | ||
| 370 | public void showLandscapeScreen() { | 564 | public void showLandscapeScreen() { |
| 371 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | 565 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| 372 | } | 566 | } |
| 373 | 567 | ||
| 374 | - protected void init(@Nullable Bundle savedInstanceState) { | ||
| 375 | - } | ||
| 376 | - | ||
| 377 | - protected void initParams(Intent params) { | ||
| 378 | - } | ||
| 379 | 568 | ||
| 380 | /** | 569 | /** |
| 381 | - * 初始化控件 | ||
| 382 | - */ | ||
| 383 | - protected abstract void initView(); | ||
| 384 | - | ||
| 385 | - | ||
| 386 | - /** | ||
| 387 | - * 设置数据 | 570 | + * 是否已经开启侧滑返回 |
| 571 | + * | ||
| 572 | + * @return | ||
| 388 | */ | 573 | */ |
| 389 | - protected void initData() { | ||
| 390 | - } | ||
| 391 | - | ||
| 392 | - protected void initBindingLayoutData(ViewDataBinding baseBinding) { | ||
| 393 | - | ||
| 394 | - } | ||
| 395 | - | ||
| 396 | public boolean isOpenSwipBack() { | 574 | public boolean isOpenSwipBack() { |
| 397 | return isOpenSwipBack; | 575 | return isOpenSwipBack; |
| 398 | } | 576 | } |
| 399 | 577 | ||
| 400 | /** | 578 | /** |
| 401 | - * 设置是否显示标题栏 | ||
| 402 | - * | ||
| 403 | - * @param showTitle true or false | ||
| 404 | - */ | ||
| 405 | - public void setShowTitle(boolean showTitle) { | ||
| 406 | - isShowTitle = showTitle; | ||
| 407 | - } | ||
| 408 | - | ||
| 409 | - /** | ||
| 410 | * 设置是否显示状态栏 | 579 | * 设置是否显示状态栏 |
| 411 | * | 580 | * |
| 412 | * @param showStatusBar true or false | 581 | * @param showStatusBar true or false |
| @@ -420,6 +589,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -420,6 +589,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 420 | * 设置屏幕为横屏 | 589 | * 设置屏幕为横屏 |
| 421 | * Set the screen to landscape. | 590 | * Set the screen to landscape. |
| 422 | */ | 591 | */ |
| 592 | + @SuppressLint("SourceLockedOrientationActivity") | ||
| 423 | public void setLandscape() { | 593 | public void setLandscape() { |
| 424 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | 594 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| 425 | } | 595 | } |
| @@ -428,6 +598,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -428,6 +598,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 428 | * 设置屏幕为竖屏 | 598 | * 设置屏幕为竖屏 |
| 429 | * Set the screen to portrait. | 599 | * Set the screen to portrait. |
| 430 | */ | 600 | */ |
| 601 | + @SuppressLint("SourceLockedOrientationActivity") | ||
| 431 | public void setPortrait() { | 602 | public void setPortrait() { |
| 432 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | 603 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 433 | } | 604 | } |
| @@ -551,9 +722,19 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -551,9 +722,19 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 551 | imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); | 722 | imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); |
| 552 | } | 723 | } |
| 553 | 724 | ||
| 725 | + /** | ||
| 726 | + * 获取 SharedPreferencesHelper | ||
| 727 | + */ | ||
| 728 | + protected SharedPreferencesHelper getSP() { | ||
| 729 | + return SharedPreferencesHelper.getInstance(this); | ||
| 730 | + } | ||
| 731 | + | ||
| 554 | @Override | 732 | @Override |
| 555 | protected void onResume() { | 733 | protected void onResume() { |
| 556 | super.onResume(); | 734 | super.onResume(); |
| 735 | + isActive = true; | ||
| 736 | + //创建订阅映射 | ||
| 737 | + RxManager.getInstance().setCurrentDisposables(TAG); | ||
| 557 | if (isUserClickAllowBtn) { | 738 | if (isUserClickAllowBtn) { |
| 558 | isUserClickAllowBtn = false; | 739 | isUserClickAllowBtn = false; |
| 559 | int requestCode = DEFAULT_REQUEST_CODE_PERMISSION; | 740 | int requestCode = DEFAULT_REQUEST_CODE_PERMISSION; |
| @@ -570,6 +751,35 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -570,6 +751,35 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 570 | requestPermission(requestCode, tip, isDefinePermissionCloseActivity, userSetPermission, isShowDialog, onPermissionResponseListener); | 751 | requestPermission(requestCode, tip, isDefinePermissionCloseActivity, userSetPermission, isShowDialog, onPermissionResponseListener); |
| 571 | } | 752 | } |
| 572 | } | 753 | } |
| 754 | + if (lifeCircleListener != null) { | ||
| 755 | + lifeCircleListener.onResume(); | ||
| 756 | + } | ||
| 757 | + if (globalLifeCircleListener != null) { | ||
| 758 | + globalLifeCircleListener.onResume(me, me.getClass().getName()); | ||
| 759 | + } | ||
| 760 | + AppManager.setActiveActivity(this); | ||
| 761 | + } | ||
| 762 | + | ||
| 763 | + | ||
| 764 | + @Override | ||
| 765 | + protected void onPause() { | ||
| 766 | + if (null != getPresenter()) { | ||
| 767 | + getPresenter().onPause(); | ||
| 768 | + } | ||
| 769 | + if (null != getMvpView()) { | ||
| 770 | + getMvpView().onPause(); | ||
| 771 | + } | ||
| 772 | + if (null != pauseDisposable && pauseDisposable.size() > 0) { | ||
| 773 | + pauseDisposable.clear(); | ||
| 774 | + } | ||
| 775 | + isActive = false; | ||
| 776 | + if (lifeCircleListener != null) { | ||
| 777 | + lifeCircleListener.onPause(); | ||
| 778 | + } | ||
| 779 | + if (globalLifeCircleListener != null) { | ||
| 780 | + globalLifeCircleListener.onPause(me, me.getClass().getName()); | ||
| 781 | + } | ||
| 782 | + super.onPause(); | ||
| 573 | } | 783 | } |
| 574 | 784 | ||
| 575 | public void registerEventBus() { | 785 | public void registerEventBus() { |
| @@ -598,31 +808,92 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -598,31 +808,92 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 598 | @Override | 808 | @Override |
| 599 | protected void onDestroy() { | 809 | protected void onDestroy() { |
| 600 | super.onDestroy(); | 810 | super.onDestroy(); |
| 811 | + isAlive = false; | ||
| 601 | //删除观察者 | 812 | //删除观察者 |
| 602 | deleteObservable(); | 813 | deleteObservable(); |
| 603 | mDelegate.onDestroy(); | 814 | mDelegate.onDestroy(); |
| 604 | - if (null != baseBinding) { | ||
| 605 | - baseBinding.unbind(); | ||
| 606 | - } | ||
| 607 | if (null != myActHandler) { | 815 | if (null != myActHandler) { |
| 608 | myActHandler.removeCallbacksAndMessages(null); | 816 | myActHandler.removeCallbacksAndMessages(null); |
| 609 | } | 817 | } |
| 818 | + //清除当前订阅 | ||
| 819 | + RxManager.getInstance().cancel(TAG); | ||
| 820 | + //取消Rxjava订阅 | ||
| 821 | + if (null != destoryDisposable && destoryDisposable.size() > 0) { | ||
| 822 | + destoryDisposable.clear(); | ||
| 823 | + } | ||
| 610 | unRegisterEventBus(); | 824 | unRegisterEventBus(); |
| 611 | onPermissionResponseListener = null; | 825 | onPermissionResponseListener = null; |
| 612 | userSetPermission = null; | 826 | userSetPermission = null; |
| 613 | userSetDefinePermissionTip = null; | 827 | userSetDefinePermissionTip = null; |
| 614 | - //activity管理 | ||
| 615 | - AppManager.getInstance().deleteActivity(me); | ||
| 616 | - //清除当前订阅 | ||
| 617 | - SubscriptionManager.getInstance().cancel(TAG); | 828 | + if (null != baseBinding) { |
| 829 | + baseBinding.unbind(); | ||
| 830 | + } | ||
| 618 | if (null != getPresenter()) { | 831 | if (null != getPresenter()) { |
| 619 | - getPresenter().onDestory(); | 832 | + getPresenter().onDestroy(); |
| 620 | } | 833 | } |
| 621 | if (null != getMvpView()) { | 834 | if (null != getMvpView()) { |
| 622 | getMvpView().onDestory(); | 835 | getMvpView().onDestory(); |
| 623 | } | 836 | } |
| 837 | + //activity管理 | ||
| 838 | + AppManager.getInstance().deleteActivity(me); | ||
| 839 | + if (lifeCircleListener != null) { | ||
| 840 | + lifeCircleListener.onDestroy(); | ||
| 841 | + } | ||
| 842 | + if (globalLifeCircleListener != null) { | ||
| 843 | + globalLifeCircleListener.onDestroy(me, me.getClass().getName()); | ||
| 844 | + } | ||
| 845 | + | ||
| 624 | } | 846 | } |
| 625 | 847 | ||
| 848 | + public void setLifeCircleListener(LifeCircleListener lifeCircleListener) { | ||
| 849 | + this.lifeCircleListener = lifeCircleListener; | ||
| 850 | + } | ||
| 851 | + | ||
| 852 | + public static GlobalLifeCircleListener getGlobalLifeCircleListener() { | ||
| 853 | + return globalLifeCircleListener; | ||
| 854 | + } | ||
| 855 | + | ||
| 856 | + public static void setGlobalLifeCircleListener(GlobalLifeCircleListener globalLifeCircleListener) { | ||
| 857 | + BaseActivity.globalLifeCircleListener = globalLifeCircleListener; | ||
| 858 | + } | ||
| 859 | + | ||
| 860 | + | ||
| 861 | + public void runOnMain(Runnable runnable) { | ||
| 862 | + runOnUiThread(new Runnable() { | ||
| 863 | + @Override | ||
| 864 | + public void run() { | ||
| 865 | + if (isAlive) { | ||
| 866 | + runnable.run(); | ||
| 867 | + } | ||
| 868 | + } | ||
| 869 | + }); | ||
| 870 | + } | ||
| 871 | + | ||
| 872 | + public void runOnMainDelayed(Runnable runnable, long time) { | ||
| 873 | + getMyActHandler().postDelayed(new Runnable() { | ||
| 874 | + @Override | ||
| 875 | + public void run() { | ||
| 876 | + runOnMain(runnable); | ||
| 877 | + } | ||
| 878 | + }, time); | ||
| 879 | + } | ||
| 880 | + | ||
| 881 | + public void runDelayed(Runnable runnable, long time) { | ||
| 882 | + getMyActHandler().postDelayed(new Runnable() { | ||
| 883 | + @Override | ||
| 884 | + public void run() { | ||
| 885 | + runnable.run(); | ||
| 886 | + } | ||
| 887 | + }, time); | ||
| 888 | + } | ||
| 889 | + | ||
| 890 | + @Override | ||
| 891 | + public void onWindowFocusChanged(boolean hasFocus) { | ||
| 892 | + super.onWindowFocusChanged(hasFocus); | ||
| 893 | + if (globalLifeCircleListener != null) { | ||
| 894 | + globalLifeCircleListener.windowFocus(me, me.getClass().getName(), hasFocus); | ||
| 895 | + } | ||
| 896 | + } | ||
| 626 | 897 | ||
| 627 | @NonNull | 898 | @NonNull |
| 628 | public final V createView() { | 899 | public final V createView() { |
| @@ -689,19 +960,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -689,19 +960,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 689 | /** | 960 | /** |
| 690 | * 判空 | 961 | * 判空 |
| 691 | * | 962 | * |
| 692 | - * @param o | 963 | + * @param os |
| 693 | * @return | 964 | * @return |
| 694 | */ | 965 | */ |
| 695 | - public boolean isNull(Object o) { | ||
| 696 | - if (o instanceof String) { | ||
| 697 | - String s = (String) o; | ||
| 698 | - if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | ||
| 699 | - return true; | ||
| 700 | - } | ||
| 701 | - } else if (null == o) { | ||
| 702 | - return true; | ||
| 703 | - } | ||
| 704 | - return false; | 966 | + public boolean isNull(Object... os) { |
| 967 | + return BaseHelpUtil.isNull(os); | ||
| 705 | } | 968 | } |
| 706 | 969 | ||
| 707 | @Override | 970 | @Override |
| @@ -1286,27 +1549,55 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1286,27 +1549,55 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1286 | } else { | 1549 | } else { |
| 1287 | tip = userSetDefinePermissionTip; | 1550 | tip = userSetDefinePermissionTip; |
| 1288 | } | 1551 | } |
| 1289 | - new AlertDialog.Builder(this) | ||
| 1290 | - .setTitle("温馨提示") | ||
| 1291 | - .setMessage(tip) | ||
| 1292 | - .setCancelable(false) | ||
| 1293 | - .setNegativeButton("取消", new DialogInterface.OnClickListener() { | ||
| 1294 | - @Override | ||
| 1295 | - public void onClick(DialogInterface dialog, int which) { | ||
| 1296 | - if (isDefinePermissionCloseActivity) { | ||
| 1297 | - finish(); | ||
| 1298 | - } | ||
| 1299 | - resetPermissionConfig(); | ||
| 1300 | - } | ||
| 1301 | - }) | ||
| 1302 | - .setPositiveButton("去设置", new DialogInterface.OnClickListener() { | ||
| 1303 | - @Override | ||
| 1304 | - public void onClick(DialogInterface dialog, int which) { | ||
| 1305 | - dialog.dismiss(); | ||
| 1306 | - startAppSettings(); | ||
| 1307 | - isUserClickAllowBtn = true; | 1552 | +// new AlertDialog.Builder(this) |
| 1553 | +// .setTitle("温馨提示") | ||
| 1554 | +// .setMessage(tip) | ||
| 1555 | +// .setCancelable(false) | ||
| 1556 | +// .setNegativeButton("取消", new DialogInterface.OnClickListener() { | ||
| 1557 | +// @Override | ||
| 1558 | +// public void onClick(DialogInterface dialog, int which) { | ||
| 1559 | +// if (isDefinePermissionCloseActivity) { | ||
| 1560 | +// finish(); | ||
| 1561 | +// } | ||
| 1562 | +// resetPermissionConfig(); | ||
| 1563 | +// } | ||
| 1564 | +// }) | ||
| 1565 | +// .setPositiveButton("去设置", new DialogInterface.OnClickListener() { | ||
| 1566 | +// @Override | ||
| 1567 | +// public void onClick(DialogInterface dialog, int which) { | ||
| 1568 | +// dialog.dismiss(); | ||
| 1569 | +// startAppSettings(); | ||
| 1570 | +// isUserClickAllowBtn = true; | ||
| 1571 | +// } | ||
| 1572 | +// }).show(); | ||
| 1573 | + if (null == permissionTipDialog) { | ||
| 1574 | + permissionTipDialog = new SelectDialog(me, tip, "取消", new SelectDialog.DialogInterface() { | ||
| 1575 | + @Override | ||
| 1576 | + public void onClick(SelectDialog dialog) { | ||
| 1577 | + dialog.dismiss(); | ||
| 1578 | + if (isDefinePermissionCloseActivity) { | ||
| 1579 | + finish(); | ||
| 1308 | } | 1580 | } |
| 1309 | - }).show(); | 1581 | + resetPermissionConfig(); |
| 1582 | + } | ||
| 1583 | + }, "去设置", new SelectDialog.DialogInterface() { | ||
| 1584 | + @Override | ||
| 1585 | + public void onClick(SelectDialog dialog) { | ||
| 1586 | + dialog.dismiss(); | ||
| 1587 | + startAppSettings(); | ||
| 1588 | + isUserClickAllowBtn = true; | ||
| 1589 | + } | ||
| 1590 | + }); | ||
| 1591 | + permissionTipDialog.setCanceledOnTouchOutside(false); | ||
| 1592 | + permissionTipDialog.setCancelable(false); | ||
| 1593 | + permissionTipDialog.setTipGravity(Gravity.LEFT); | ||
| 1594 | + permissionTipDialog.setLeftBtnColor(R.color.color_282828); | ||
| 1595 | + } else { | ||
| 1596 | + permissionTipDialog.setTipMessage(tip); | ||
| 1597 | + } | ||
| 1598 | + if (!permissionTipDialog.isShowing()) { | ||
| 1599 | + permissionTipDialog.show(); | ||
| 1600 | + } | ||
| 1310 | } | 1601 | } |
| 1311 | 1602 | ||
| 1312 | 1603 | ||
| @@ -1474,6 +1765,10 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1474,6 +1765,10 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1474 | mDelegate.loadRootFragment(R.id.root_container, toFragment, allowAnimation); | 1765 | mDelegate.loadRootFragment(R.id.root_container, toFragment, allowAnimation); |
| 1475 | } | 1766 | } |
| 1476 | 1767 | ||
| 1768 | + public final void loadRootFragment(ISupportFragment toFragment, boolean addToBackStack, boolean allowAnimation) { | ||
| 1769 | + mDelegate.loadRootFragment(R.id.root_container, toFragment, addToBackStack, allowAnimation); | ||
| 1770 | + } | ||
| 1771 | + | ||
| 1477 | /** | 1772 | /** |
| 1478 | * 加载根Fragment, 即Activity内的第一个Fragment 或 Fragment内的第一个子Fragment | 1773 | * 加载根Fragment, 即Activity内的第一个Fragment 或 Fragment内的第一个子Fragment |
| 1479 | * | 1774 | * |
| @@ -1644,7 +1939,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1644,7 +1939,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1644 | Fragmentation.builder() | 1939 | Fragmentation.builder() |
| 1645 | // show stack view. Mode: BUBBLE, SHAKE, NONE | 1940 | // show stack view. Mode: BUBBLE, SHAKE, NONE |
| 1646 | .stackViewMode(Fragmentation.BUBBLE) | 1941 | .stackViewMode(Fragmentation.BUBBLE) |
| 1647 | - .debug(AppConfig.isDebug()) | 1942 | + .debug(BuildConfig.DEBUG) |
| 1648 | .install(); | 1943 | .install(); |
| 1649 | } | 1944 | } |
| 1650 | /***********************************滑动返回********************************************/ | 1945 | /***********************************滑动返回********************************************/ |
core/base/src/main/java/com/cnlive/core/libs/base/frame/fragment/BaseFragment.java
| @@ -2,6 +2,7 @@ package com.cnlive.core.libs.base.frame.fragment; | @@ -2,6 +2,7 @@ package com.cnlive.core.libs.base.frame.fragment; | ||
| 2 | 2 | ||
| 3 | import android.app.Activity; | 3 | import android.app.Activity; |
| 4 | import android.content.Intent; | 4 | import android.content.Intent; |
| 5 | +import android.graphics.drawable.Drawable; | ||
| 5 | import android.os.Bundle; | 6 | import android.os.Bundle; |
| 6 | import android.os.Handler; | 7 | import android.os.Handler; |
| 7 | import android.os.Message; | 8 | import android.os.Message; |
| @@ -10,8 +11,8 @@ import android.view.View; | @@ -10,8 +11,8 @@ import android.view.View; | ||
| 10 | import android.view.ViewGroup; | 11 | import android.view.ViewGroup; |
| 11 | import android.view.animation.Animation; | 12 | import android.view.animation.Animation; |
| 12 | 13 | ||
| 13 | -import androidx.annotation.ColorInt; | ||
| 14 | import androidx.annotation.ColorRes; | 14 | import androidx.annotation.ColorRes; |
| 15 | +import androidx.annotation.DrawableRes; | ||
| 15 | import androidx.annotation.FloatRange; | 16 | import androidx.annotation.FloatRange; |
| 16 | import androidx.annotation.IntRange; | 17 | import androidx.annotation.IntRange; |
| 17 | import androidx.annotation.NonNull; | 18 | import androidx.annotation.NonNull; |
| @@ -20,16 +21,20 @@ import androidx.annotation.StringRes; | @@ -20,16 +21,20 @@ import androidx.annotation.StringRes; | ||
| 20 | import androidx.databinding.DataBindingUtil; | 21 | import androidx.databinding.DataBindingUtil; |
| 21 | import androidx.databinding.ViewDataBinding; | 22 | import androidx.databinding.ViewDataBinding; |
| 22 | 23 | ||
| 24 | +import com.alibaba.android.arouter.facade.Postcard; | ||
| 25 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 23 | import com.alibaba.android.arouter.launcher.ARouter; | 26 | import com.alibaba.android.arouter.launcher.ARouter; |
| 27 | +import com.cnlive.cloud.base.R; | ||
| 24 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; | 28 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; |
| 25 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; | 29 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; |
| 30 | +import com.cnlive.core.libs.base.frame.view.BaseView; | ||
| 26 | import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; | 31 | import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; |
| 27 | -import com.cnlive.core.libs.base.network.manager.SubscriptionManager; | 32 | +import com.cnlive.core.libs.base.network.manager.RxManager; |
| 33 | +import com.cnlive.core.libs.base.util.AlertUtil; | ||
| 34 | +import com.cnlive.core.libs.base.util.BaseHelpUtil; | ||
| 35 | +import com.cnlive.core.libs.base.util.LifeCircleListener; | ||
| 28 | import com.cnlive.core.libs.base.util.ReflectUtil; | 36 | import com.cnlive.core.libs.base.util.ReflectUtil; |
| 29 | -import com.cnlive.core.libs.base.frame.view.BaseView; | ||
| 30 | import com.cnlive.core.libs.base.util.StatusBarConfig; | 37 | import com.cnlive.core.libs.base.util.StatusBarConfig; |
| 31 | -import com.cnlive.cloud.base.R; | ||
| 32 | -import com.cnlive.core.libs.base.util.StatusBarUtil; | ||
| 33 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; | 38 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 34 | import com.me.yokeyword.fragmentation.ExtraTransaction; | 39 | import com.me.yokeyword.fragmentation.ExtraTransaction; |
| 35 | import com.me.yokeyword.fragmentation.ISupportFragment; | 40 | import com.me.yokeyword.fragmentation.ISupportFragment; |
| @@ -48,6 +53,9 @@ import java.util.List; | @@ -48,6 +53,9 @@ import java.util.List; | ||
| 48 | import java.util.Observable; | 53 | import java.util.Observable; |
| 49 | import java.util.Observer; | 54 | import java.util.Observer; |
| 50 | 55 | ||
| 56 | +import io.reactivex.disposables.CompositeDisposable; | ||
| 57 | +import io.reactivex.disposables.Disposable; | ||
| 58 | + | ||
| 51 | /** | 59 | /** |
| 52 | * 基类fragment | 60 | * 基类fragment |
| 53 | * | 61 | * |
| @@ -69,6 +77,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -69,6 +77,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 69 | private List<Observable> observableList; | 77 | private List<Observable> observableList; |
| 70 | private Bundle savedInstanceState; | 78 | private Bundle savedInstanceState; |
| 71 | private boolean isCreateDefultEmptyView = true;//默认显示空视图 | 79 | private boolean isCreateDefultEmptyView = true;//默认显示空视图 |
| 80 | + public boolean isActive = false;//当前Fragment是否活跃 | ||
| 81 | + private CompositeDisposable destoryDisposable;//生命周期在destory销毁 | ||
| 82 | + private CompositeDisposable pauseDisposable;//生命周期在onPause销毁 | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 快速管理生命周期 | ||
| 86 | + */ | ||
| 87 | + private LifeCircleListener lifeCircleListener; | ||
| 72 | 88 | ||
| 73 | public final ViewDataBinding getBaseBinding() { | 89 | public final ViewDataBinding getBaseBinding() { |
| 74 | return baseBinding; | 90 | return baseBinding; |
| @@ -86,9 +102,9 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -86,9 +102,9 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 86 | if (null == observableList) { | 102 | if (null == observableList) { |
| 87 | observableList = new ArrayList<>(); | 103 | observableList = new ArrayList<>(); |
| 88 | } | 104 | } |
| 105 | + //初始化rxjava管理 | ||
| 106 | + initRxjava(); | ||
| 89 | this.savedInstanceState = savedInstanceState; | 107 | this.savedInstanceState = savedInstanceState; |
| 90 | - //创建订阅映射 | ||
| 91 | - SubscriptionManager.getInstance().setCurrentDisposables(TAG); | ||
| 92 | mDelegate.onCreate(savedInstanceState); | 108 | mDelegate.onCreate(savedInstanceState); |
| 93 | mSwipeDelegate.onCreate(savedInstanceState); | 109 | mSwipeDelegate.onCreate(savedInstanceState); |
| 94 | setSwipeBackEnable(me.isOpenSwipBack()); | 110 | setSwipeBackEnable(me.isOpenSwipBack()); |
| @@ -97,6 +113,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -97,6 +113,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 97 | if (null != getArguments()) { | 113 | if (null != getArguments()) { |
| 98 | initParams(getArguments()); | 114 | initParams(getArguments()); |
| 99 | } | 115 | } |
| 116 | + if (lifeCircleListener != null) { | ||
| 117 | + lifeCircleListener.onCreate(); | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + private void initRxjava() { | ||
| 122 | + pauseDisposable = new CompositeDisposable(); | ||
| 123 | + destoryDisposable = new CompositeDisposable(); | ||
| 100 | } | 124 | } |
| 101 | 125 | ||
| 102 | @Nullable | 126 | @Nullable |
| @@ -128,15 +152,115 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -128,15 +152,115 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 128 | } | 152 | } |
| 129 | } | 153 | } |
| 130 | } | 154 | } |
| 155 | + | ||
| 131 | return super.onCreateView(inflater, container, savedInstanceState); | 156 | return super.onCreateView(inflater, container, savedInstanceState); |
| 132 | } | 157 | } |
| 133 | 158 | ||
| 159 | + public void setLifeCircleListener(LifeCircleListener lifeCircleListener) { | ||
| 160 | + this.lifeCircleListener = lifeCircleListener; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * 添加订阅 | ||
| 165 | + * Pause 销毁 | ||
| 166 | + * | ||
| 167 | + * @param disposable | ||
| 168 | + * @return | ||
| 169 | + */ | ||
| 170 | + public Disposable addPauseDisPosable(Disposable disposable) { | ||
| 171 | + if (null != disposable) { | ||
| 172 | + if (null != pauseDisposable) { | ||
| 173 | + pauseDisposable.add(disposable); | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + return disposable; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + /** | ||
| 180 | + * 添加订阅 | ||
| 181 | + * Destory 销毁 | ||
| 182 | + * | ||
| 183 | + * @param disposable | ||
| 184 | + * @return | ||
| 185 | + */ | ||
| 186 | + public Disposable addDestoryDisPosable(Disposable disposable) { | ||
| 187 | + if (null != disposable) { | ||
| 188 | + if (null != destoryDisposable) { | ||
| 189 | + destoryDisposable.add(disposable); | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + return disposable; | ||
| 193 | + } | ||
| 134 | 194 | ||
| 135 | - public boolean isNull(Object o) { | 195 | + /** |
| 196 | + * 获取资源颜色 | ||
| 197 | + * | ||
| 198 | + * @param colorId | ||
| 199 | + * @return | ||
| 200 | + */ | ||
| 201 | + public int getResourceColor(@ColorRes int colorId) { | ||
| 202 | + return BaseHelpUtil.getResourceColor(me, colorId); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + /** | ||
| 206 | + * 获取资源字符串 | ||
| 207 | + * | ||
| 208 | + * @param stringId | ||
| 209 | + * @return | ||
| 210 | + */ | ||
| 211 | + public String getResourceStr(@StringRes int stringId) { | ||
| 212 | + return BaseHelpUtil.getResourceStr(me, stringId); | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + /** | ||
| 216 | + * 获取资源 | ||
| 217 | + * | ||
| 218 | + * @param drawableId | ||
| 219 | + * @return | ||
| 220 | + */ | ||
| 221 | + public Drawable getResourceDrawable(@DrawableRes int drawableId) { | ||
| 222 | + return BaseHelpUtil.getResourceDrawable(me, drawableId); | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + /** | ||
| 226 | + * 用户提示 | ||
| 227 | + */ | ||
| 228 | + public void showToast(String message) { | ||
| 229 | + AlertUtil.showDeftToast(me, message); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + public boolean isNull(Object... o) { | ||
| 136 | return me.isNull(o); | 233 | return me.isNull(o); |
| 137 | } | 234 | } |
| 138 | 235 | ||
| 139 | /** | 236 | /** |
| 237 | + * 实例化路由-对象 | ||
| 238 | + */ | ||
| 239 | + public <T extends IProvider> T initRouterImpl(String routerPath) { | ||
| 240 | + return (T) me.initRouterImpl(routerPath); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + /** | ||
| 244 | + * Arouter跳转 | ||
| 245 | + * | ||
| 246 | + * @param routerPath | ||
| 247 | + * @return | ||
| 248 | + */ | ||
| 249 | + public Postcard goToRouter(String routerPath) { | ||
| 250 | + return ARouter.getInstance().build(routerPath); | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + /** | ||
| 254 | + * Arouter跳转无参数 | ||
| 255 | + * | ||
| 256 | + * @param routerPath | ||
| 257 | + * @return | ||
| 258 | + */ | ||
| 259 | + public void goToRouterNoParams(String routerPath) { | ||
| 260 | + ARouter.getInstance().build(routerPath).navigation(me); | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + /** | ||
| 140 | * 显示白色通知栏 | 264 | * 显示白色通知栏 |
| 141 | */ | 265 | */ |
| 142 | public void showDefaultWhiteStatusBar() { | 266 | public void showDefaultWhiteStatusBar() { |
| @@ -166,9 +290,15 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -166,9 +290,15 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 166 | if (null != getMvpView() && null != getPresenter()) { | 290 | if (null != getMvpView() && null != getPresenter()) { |
| 167 | if (null != baseBinding) { | 291 | if (null != baseBinding) { |
| 168 | initBindingLayoutData(baseBinding); | 292 | initBindingLayoutData(baseBinding); |
| 293 | + if (isViewAttached() && !isNull(me)) { | ||
| 294 | + getMvpView().initFragBindingLayout(me, this, baseBinding); | ||
| 295 | + } | ||
| 169 | } | 296 | } |
| 170 | if (null != baseView) { | 297 | if (null != baseView) { |
| 171 | initViewLayoutData(baseView); | 298 | initViewLayoutData(baseView); |
| 299 | + if (isViewAttached() && !isNull(me)) { | ||
| 300 | + getMvpView().initFragViewLayout(me, this, baseView); | ||
| 301 | + } | ||
| 172 | } | 302 | } |
| 173 | initView(); | 303 | initView(); |
| 174 | initData(); | 304 | initData(); |
| @@ -276,6 +406,11 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -276,6 +406,11 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 276 | EventBus.getDefault().postSticky(object); | 406 | EventBus.getDefault().postSticky(object); |
| 277 | } | 407 | } |
| 278 | 408 | ||
| 409 | + /** | ||
| 410 | + * 初始化fragment的handler | ||
| 411 | + * | ||
| 412 | + * @return | ||
| 413 | + */ | ||
| 279 | public Handler getMyFragHandler() { | 414 | public Handler getMyFragHandler() { |
| 280 | if (null == myFragHandler) { | 415 | if (null == myFragHandler) { |
| 281 | myFragHandler = new Handler() { | 416 | myFragHandler = new Handler() { |
| @@ -289,12 +424,22 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -289,12 +424,22 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 289 | return myFragHandler; | 424 | return myFragHandler; |
| 290 | } | 425 | } |
| 291 | 426 | ||
| 427 | + /** | ||
| 428 | + * 收到fragment对应的Activity的handler | ||
| 429 | + * | ||
| 430 | + * @param msg | ||
| 431 | + */ | ||
| 292 | public void onReceiveActHandleMessage(@NonNull Message msg) { | 432 | public void onReceiveActHandleMessage(@NonNull Message msg) { |
| 293 | if (null != getMvpView()) { | 433 | if (null != getMvpView()) { |
| 294 | getMvpView().onReceiveActHandleMessage(msg); | 434 | getMvpView().onReceiveActHandleMessage(msg); |
| 295 | } | 435 | } |
| 296 | } | 436 | } |
| 297 | 437 | ||
| 438 | + /** | ||
| 439 | + * 收到当前fragment的handler | ||
| 440 | + * | ||
| 441 | + * @param msg | ||
| 442 | + */ | ||
| 298 | public void onReceiveFragHandleMessage(@NonNull Message msg) { | 443 | public void onReceiveFragHandleMessage(@NonNull Message msg) { |
| 299 | if (null != getMvpView()) { | 444 | if (null != getMvpView()) { |
| 300 | getMvpView().onReceiveFragHandleMessage(msg); | 445 | getMvpView().onReceiveFragHandleMessage(msg); |
| @@ -417,6 +562,15 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -417,6 +562,15 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 417 | } | 562 | } |
| 418 | 563 | ||
| 419 | /** | 564 | /** |
| 565 | + * 获取状态栏高度dp | ||
| 566 | + * | ||
| 567 | + * @return | ||
| 568 | + */ | ||
| 569 | + public int getStatusBarHeight() { | ||
| 570 | + return me.getStatusBarHeight(); | ||
| 571 | + } | ||
| 572 | + | ||
| 573 | + /** | ||
| 420 | * 将标题视图自适应沉浸式状态栏 | 574 | * 将标题视图自适应沉浸式状态栏 |
| 421 | * | 575 | * |
| 422 | * @param view | 576 | * @param view |
| @@ -426,37 +580,63 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -426,37 +580,63 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 426 | } | 580 | } |
| 427 | 581 | ||
| 428 | /** | 582 | /** |
| 429 | - * 获取状态栏高度 | ||
| 430 | - * | ||
| 431 | - * @return | 583 | + * 销毁 Rx Dispose |
| 432 | */ | 584 | */ |
| 433 | - public int getStatusBarHeight() { | ||
| 434 | - return me.getStatusBarHeight(); | 585 | + public void disposeRxEvent(Disposable... disposables) { |
| 586 | + if (disposables == null) return; | ||
| 587 | + for (Disposable disposable : disposables) if (disposable != null) disposable.dispose(); | ||
| 588 | + } | ||
| 589 | + | ||
| 590 | + @Override | ||
| 591 | + public void onDestroyView() { | ||
| 592 | + mDelegate.onDestroyView(); | ||
| 593 | + super.onDestroyView(); | ||
| 594 | + deleteObservable(); | ||
| 595 | + if (null != myFragHandler) { | ||
| 596 | + myFragHandler.removeCallbacksAndMessages(null); | ||
| 597 | + } | ||
| 598 | + unRegisterEventBus(); | ||
| 599 | + //清除当前订阅 | ||
| 600 | + RxManager.getInstance().cancel(TAG); | ||
| 601 | + if (null != getMvpView()) { | ||
| 602 | + getMvpView().onDestory(); | ||
| 603 | + } | ||
| 604 | + if (null != getPresenter()) { | ||
| 605 | + getPresenter().onDestroy(); | ||
| 606 | + } | ||
| 435 | } | 607 | } |
| 436 | 608 | ||
| 437 | @Override | 609 | @Override |
| 438 | public void onDestroy() { | 610 | public void onDestroy() { |
| 439 | super.onDestroy(); | 611 | super.onDestroy(); |
| 440 | deleteObservable(); | 612 | deleteObservable(); |
| 441 | - if (null != baseBinding) { | ||
| 442 | - baseBinding.unbind(); | 613 | + unRegisterEventBus(); |
| 614 | + //清除当前订阅 | ||
| 615 | + RxManager.getInstance().cancel(TAG); | ||
| 616 | + //取消Rxjava订阅 | ||
| 617 | + if (null != destoryDisposable && destoryDisposable.size() > 0) { | ||
| 618 | + destoryDisposable.clear(); | ||
| 443 | } | 619 | } |
| 444 | if (null != myFragHandler) { | 620 | if (null != myFragHandler) { |
| 445 | myFragHandler.removeCallbacksAndMessages(null); | 621 | myFragHandler.removeCallbacksAndMessages(null); |
| 446 | } | 622 | } |
| 447 | - unRegisterEventBus(); | 623 | + if (null != baseBinding) { |
| 624 | + baseBinding.unbind(); | ||
| 625 | + } | ||
| 448 | mDelegate.onDestroy(); | 626 | mDelegate.onDestroy(); |
| 449 | mSwipeDelegate.onDestroyView(); | 627 | mSwipeDelegate.onDestroyView(); |
| 450 | - //清除当前订阅 | ||
| 451 | - SubscriptionManager.getInstance().cancel(TAG); | ||
| 452 | if (null != getPresenter()) { | 628 | if (null != getPresenter()) { |
| 453 | - getPresenter().onDestory(); | 629 | + getPresenter().onDestroy(); |
| 454 | } | 630 | } |
| 455 | if (null != getMvpView()) { | 631 | if (null != getMvpView()) { |
| 456 | getMvpView().onDestory(); | 632 | getMvpView().onDestory(); |
| 457 | } | 633 | } |
| 634 | + if (lifeCircleListener != null) { | ||
| 635 | + lifeCircleListener.onDestroy(); | ||
| 636 | + } | ||
| 458 | } | 637 | } |
| 459 | 638 | ||
| 639 | + | ||
| 460 | /** | 640 | /** |
| 461 | * 设置状态栏字体颜色 | 641 | * 设置状态栏字体颜色 |
| 462 | */ | 642 | */ |
| @@ -674,34 +854,37 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -674,34 +854,37 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 674 | @Override | 854 | @Override |
| 675 | public void onResume() { | 855 | public void onResume() { |
| 676 | super.onResume(); | 856 | super.onResume(); |
| 857 | + //创建订阅映射 | ||
| 858 | + RxManager.getInstance().setCurrentDisposables(TAG); | ||
| 677 | mDelegate.onResume(); | 859 | mDelegate.onResume(); |
| 678 | - } | 860 | + isActive = true; |
| 861 | + if (lifeCircleListener != null) { | ||
| 862 | + lifeCircleListener.onResume(); | ||
| 863 | + } | ||
| 679 | 864 | ||
| 680 | - @Override | ||
| 681 | - public void onPause() { | ||
| 682 | - super.onPause(); | ||
| 683 | - mDelegate.onPause(); | ||
| 684 | } | 865 | } |
| 685 | 866 | ||
| 686 | @Override | 867 | @Override |
| 687 | - public void onDestroyView() { | ||
| 688 | - mDelegate.onDestroyView(); | ||
| 689 | - super.onDestroyView(); | ||
| 690 | - deleteObservable(); | ||
| 691 | - if (null != myFragHandler) { | ||
| 692 | - myFragHandler.removeCallbacksAndMessages(null); | 868 | + public void onPause() { |
| 869 | + if (null != getPresenter()) { | ||
| 870 | + getPresenter().onPause(); | ||
| 693 | } | 871 | } |
| 694 | - unRegisterEventBus(); | ||
| 695 | - //清除当前订阅 | ||
| 696 | - SubscriptionManager.getInstance().cancel(TAG); | ||
| 697 | if (null != getMvpView()) { | 872 | if (null != getMvpView()) { |
| 698 | - getMvpView().onDestory(); | 873 | + getMvpView().onPause(); |
| 699 | } | 874 | } |
| 700 | - if (null != getPresenter()) { | ||
| 701 | - getPresenter().onDestory(); | 875 | + if (null != pauseDisposable && pauseDisposable.size() > 0) { |
| 876 | + pauseDisposable.clear(); | ||
| 702 | } | 877 | } |
| 878 | + isActive = false; | ||
| 879 | + if (lifeCircleListener != null) { | ||
| 880 | + lifeCircleListener.onPause(); | ||
| 881 | + } | ||
| 882 | + | ||
| 883 | + super.onPause(); | ||
| 884 | + mDelegate.onPause(); | ||
| 703 | } | 885 | } |
| 704 | 886 | ||
| 887 | + | ||
| 705 | @Override | 888 | @Override |
| 706 | public void onHiddenChanged(boolean hidden) { | 889 | public void onHiddenChanged(boolean hidden) { |
| 707 | super.onHiddenChanged(hidden); | 890 | super.onHiddenChanged(hidden); |
| @@ -1131,4 +1314,16 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -1131,4 +1314,16 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 1131 | public void setParallaxOffset(@FloatRange(from = 0.0f, to = 1.0f) float offset) { | 1314 | public void setParallaxOffset(@FloatRange(from = 0.0f, to = 1.0f) float offset) { |
| 1132 | mSwipeDelegate.setParallaxOffset(offset); | 1315 | mSwipeDelegate.setParallaxOffset(offset); |
| 1133 | } | 1316 | } |
| 1317 | + | ||
| 1318 | + /** | ||
| 1319 | + * 设置底层view是否可点击 | ||
| 1320 | + * fragment根布局是否可点击,多用于多个fragment叠加在一个activity,是否可点击下层的fragment,默认是false可以点击下层的 | ||
| 1321 | + * | ||
| 1322 | + * @param isEnable | ||
| 1323 | + */ | ||
| 1324 | + public void setFragmentRootViewCanClickable(boolean isEnable) { | ||
| 1325 | + if (null != mDelegate) { | ||
| 1326 | + mDelegate.setFragmentRootViewCanClickable(isEnable); | ||
| 1327 | + } | ||
| 1328 | + } | ||
| 1134 | } | 1329 | } |
core/base/src/main/java/com/cnlive/core/libs/base/frame/presenter/BasePresenter.java
| 1 | package com.cnlive.core.libs.base.frame.presenter; | 1 | package com.cnlive.core.libs.base.frame.presenter; |
| 2 | 2 | ||
| 3 | +import android.app.Dialog; | ||
| 4 | +import android.content.Context; | ||
| 5 | + | ||
| 6 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 7 | +import com.alibaba.android.arouter.launcher.ARouter; | ||
| 3 | import com.cnlive.core.libs.base.frame.view.BaseView; | 8 | import com.cnlive.core.libs.base.frame.view.BaseView; |
| 9 | +import com.cnlive.core.libs.base.network.manager.RxManager; | ||
| 10 | +import com.cnlive.core.libs.base.util.BaseHelpUtil; | ||
| 11 | +import com.cnlive.core.libs.base.util.SharedPreferencesHelper; | ||
| 4 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; | 12 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 5 | import com.orhanobut.logger.Logger; | 13 | import com.orhanobut.logger.Logger; |
| 6 | 14 | ||
| 7 | import org.greenrobot.eventbus.EventBus; | 15 | import org.greenrobot.eventbus.EventBus; |
| 8 | 16 | ||
| 17 | +import java.util.UUID; | ||
| 18 | + | ||
| 19 | +import io.reactivex.disposables.CompositeDisposable; | ||
| 20 | +import io.reactivex.disposables.Disposable; | ||
| 21 | + | ||
| 9 | /** | 22 | /** |
| 10 | * @param <V> | 23 | * @param <V> |
| 11 | */ | 24 | */ |
| @@ -20,21 +33,98 @@ public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | @@ -20,21 +33,98 @@ public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | ||
| 20 | EventBus.getDefault().postSticky(object); | 33 | EventBus.getDefault().postSticky(object); |
| 21 | } | 34 | } |
| 22 | 35 | ||
| 23 | - public boolean isNull(Object o) { | ||
| 24 | - if (o instanceof String) { | ||
| 25 | - String s = (String) o; | ||
| 26 | - if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | ||
| 27 | - return true; | 36 | + //用于自动取消rxjava |
| 37 | + public final String FLAG = UUID.randomUUID().toString().replaceAll("-", ""); | ||
| 38 | + | ||
| 39 | + private CompositeDisposable destoryDisposable;//生命周期在destory销毁 | ||
| 40 | + private CompositeDisposable pauseDisposable;//生命周期在onPause销毁 | ||
| 41 | + | ||
| 42 | + public BasePresenter() { | ||
| 43 | + //创建订阅映射 | ||
| 44 | + RxManager.getInstance().setCurrentDisposables(FLAG); | ||
| 45 | + initRxjava(); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + private void initRxjava() { | ||
| 49 | + pauseDisposable = new CompositeDisposable(); | ||
| 50 | + destoryDisposable = new CompositeDisposable(); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 添加订阅 | ||
| 55 | + * Pause 销毁 | ||
| 56 | + * | ||
| 57 | + * @param disposable | ||
| 58 | + * @return | ||
| 59 | + */ | ||
| 60 | + public Disposable addPauseDisPosable(Disposable disposable) { | ||
| 61 | + if (null != disposable) { | ||
| 62 | + if (null != pauseDisposable) { | ||
| 63 | + pauseDisposable.add(disposable); | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + return disposable; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 添加订阅 | ||
| 71 | + * Destory 销毁 | ||
| 72 | + * | ||
| 73 | + * @param disposable | ||
| 74 | + * @return | ||
| 75 | + */ | ||
| 76 | + public Disposable addDestoryDisPosable(Disposable disposable) { | ||
| 77 | + if (null != disposable) { | ||
| 78 | + if (null != destoryDisposable) { | ||
| 79 | + destoryDisposable.add(disposable); | ||
| 28 | } | 80 | } |
| 29 | - } else if (null == o) { | ||
| 30 | - return true; | ||
| 31 | } | 81 | } |
| 32 | - return false; | 82 | + return disposable; |
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * 实例化路由-对象 | ||
| 87 | + */ | ||
| 88 | + public <T extends IProvider> T initRouterImpl(String routerPath) { | ||
| 89 | + T obj = null; | ||
| 90 | + try { | ||
| 91 | + obj = (T) ARouter.getInstance().build(routerPath).navigation(); | ||
| 92 | + } catch (Exception ignored) { | ||
| 93 | + } | ||
| 94 | + return obj; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * 销毁 Rx Dispose | ||
| 99 | + */ | ||
| 100 | + protected void disposeRxEvent(Disposable... disposables) { | ||
| 101 | + if (disposables == null) return; | ||
| 102 | + for (Disposable disposable : disposables) { | ||
| 103 | + if (disposable == null) continue; | ||
| 104 | + if (disposable.isDisposed()) continue; | ||
| 105 | + | ||
| 106 | + disposable.dispose(); | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 销毁 Dialog | ||
| 112 | + */ | ||
| 113 | + protected void disposeDialog(Dialog... dialogs) { | ||
| 114 | + if (dialogs == null) return; | ||
| 115 | + for (Dialog dialog : dialogs) if (dialog != null) dialog.dismiss(); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * 获取 SharedPreferencesHelper | ||
| 120 | + */ | ||
| 121 | + protected SharedPreferencesHelper getSP(Context context) { | ||
| 122 | + return SharedPreferencesHelper.getInstance(context); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public boolean isNull(Object... os) { | ||
| 126 | + return BaseHelpUtil.isNull(os); | ||
| 33 | } | 127 | } |
| 34 | - // @Override | ||
| 35 | -// public V getView() { | ||
| 36 | -// return super.getView(); | ||
| 37 | -// } | ||
| 38 | 128 | ||
| 39 | public void logError(String info) { | 129 | public void logError(String info) { |
| 40 | Logger.e(info); | 130 | Logger.e(info); |
| @@ -64,7 +154,22 @@ public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | @@ -64,7 +154,22 @@ public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | ||
| 64 | Logger.xml(xml); | 154 | Logger.xml(xml); |
| 65 | } | 155 | } |
| 66 | 156 | ||
| 67 | - public void onDestory(){}; | 157 | + |
| 158 | + public void onPause() { | ||
| 159 | + //取消订阅 | ||
| 160 | + if (null != pauseDisposable && pauseDisposable.size() > 0) { | ||
| 161 | + pauseDisposable.clear(); | ||
| 162 | + } | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + public void onDestroy() { | ||
| 166 | + //取消订阅 | ||
| 167 | + if (null != destoryDisposable && destoryDisposable.size() > 0) { | ||
| 168 | + destoryDisposable.clear(); | ||
| 169 | + } | ||
| 170 | + //创建订阅映射 | ||
| 171 | + RxManager.getInstance().cancel(FLAG); | ||
| 172 | + } | ||
| 68 | 173 | ||
| 69 | @Override | 174 | @Override |
| 70 | public boolean isViewAttached() { | 175 | public boolean isViewAttached() { |
core/base/src/main/java/com/cnlive/core/libs/base/frame/view/BaseView.java
| 1 | package com.cnlive.core.libs.base.frame.view; | 1 | package com.cnlive.core.libs.base.frame.view; |
| 2 | 2 | ||
| 3 | +import android.app.Dialog; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.graphics.drawable.Drawable; | ||
| 3 | import android.os.Message; | 6 | import android.os.Message; |
| 4 | import android.text.TextUtils; | 7 | import android.text.TextUtils; |
| 8 | +import android.view.View; | ||
| 5 | 9 | ||
| 10 | +import androidx.annotation.ColorRes; | ||
| 11 | +import androidx.annotation.DrawableRes; | ||
| 6 | import androidx.annotation.NonNull; | 12 | import androidx.annotation.NonNull; |
| 7 | - | 13 | +import androidx.annotation.StringRes; |
| 14 | +import androidx.databinding.ViewDataBinding; | ||
| 15 | + | ||
| 16 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 17 | +import com.alibaba.android.arouter.launcher.ARouter; | ||
| 18 | +import com.cnlive.core.libs.base.frame.activity.BaseActivity; | ||
| 19 | +import com.cnlive.core.libs.base.frame.fragment.BaseFragment; | ||
| 20 | +import com.cnlive.core.libs.base.util.AlertUtil; | ||
| 21 | +import com.cnlive.core.libs.base.util.BaseHelpUtil; | ||
| 8 | import com.hannesdorfmann.mosby3.mvp.MvpView; | 22 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 9 | import com.orhanobut.logger.Logger; | 23 | import com.orhanobut.logger.Logger; |
| 10 | 24 | ||
| 11 | import org.greenrobot.eventbus.EventBus; | 25 | import org.greenrobot.eventbus.EventBus; |
| 12 | 26 | ||
| 27 | +import io.reactivex.disposables.CompositeDisposable; | ||
| 28 | +import io.reactivex.disposables.Disposable; | ||
| 29 | + | ||
| 13 | /** | 30 | /** |
| 14 | * @author ys | 31 | * @author ys |
| 15 | * 基类View | 32 | * 基类View |
| 16 | */ | 33 | */ |
| 17 | public class BaseView implements MvpView { | 34 | public class BaseView implements MvpView { |
| 18 | protected final String TAG = this.getClass().getSimpleName(); | 35 | protected final String TAG = this.getClass().getSimpleName(); |
| 36 | + public BaseActivity me; | ||
| 37 | + private CompositeDisposable destoryDisposable;//生命周期在destory销毁 | ||
| 38 | + private CompositeDisposable pauseDisposable;//生命周期在onPause销毁 | ||
| 19 | 39 | ||
| 20 | public final void postEvent(Object object) { | 40 | public final void postEvent(Object object) { |
| 21 | EventBus.getDefault().post(object); | 41 | EventBus.getDefault().post(object); |
| @@ -25,22 +45,92 @@ public class BaseView implements MvpView { | @@ -25,22 +45,92 @@ public class BaseView implements MvpView { | ||
| 25 | EventBus.getDefault().postSticky(object); | 45 | EventBus.getDefault().postSticky(object); |
| 26 | } | 46 | } |
| 27 | 47 | ||
| 48 | + public BaseView() { | ||
| 49 | + initRxjava(); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + private void initRxjava() { | ||
| 53 | + pauseDisposable = new CompositeDisposable(); | ||
| 54 | + destoryDisposable = new CompositeDisposable(); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 添加订阅 | ||
| 59 | + * Pause 销毁 | ||
| 60 | + * | ||
| 61 | + * @param disposable | ||
| 62 | + * @return | ||
| 63 | + */ | ||
| 64 | + public Disposable addPauseDisPosable(Disposable disposable) { | ||
| 65 | + if (null != disposable) { | ||
| 66 | + if (null != pauseDisposable) { | ||
| 67 | + pauseDisposable.add(disposable); | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + return disposable; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * 添加订阅 | ||
| 75 | + * Destory 销毁 | ||
| 76 | + * | ||
| 77 | + * @param disposable | ||
| 78 | + * @return | ||
| 79 | + */ | ||
| 80 | + public Disposable addDestoryDisPosable(Disposable disposable) { | ||
| 81 | + if (null != disposable) { | ||
| 82 | + if (null != destoryDisposable) { | ||
| 83 | + destoryDisposable.add(disposable); | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + return disposable; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * 在Activity的View层直接重写方法获取 | ||
| 91 | + * | ||
| 92 | + * @param baseActivity | ||
| 93 | + * @param baseBinding | ||
| 94 | + */ | ||
| 95 | + public void initActBindingLayout(BaseActivity baseActivity, ViewDataBinding baseBinding) { | ||
| 96 | + this.me = baseActivity; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 在Fragment的View层直接重写方法获取 当前fragment , | ||
| 101 | + * | ||
| 102 | + * @param baseActivity | ||
| 103 | + * @param baseFragment | ||
| 104 | + * @param baseBinding | ||
| 105 | + */ | ||
| 106 | + public void initFragBindingLayout(BaseActivity baseActivity, BaseFragment baseFragment, ViewDataBinding baseBinding) { | ||
| 107 | + this.me = baseActivity; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public void initFragViewLayout(BaseActivity baseActivity, BaseFragment baseFragment, View baseView) { | ||
| 111 | + this.me = baseActivity; | ||
| 112 | + } | ||
| 113 | + | ||
| 28 | public void initView() { | 114 | public void initView() { |
| 29 | } | 115 | } |
| 30 | 116 | ||
| 31 | public void initData() { | 117 | public void initData() { |
| 32 | } | 118 | } |
| 33 | 119 | ||
| 34 | - public boolean isNull(Object o) { | ||
| 35 | - if (o instanceof String) { | ||
| 36 | - String s = (String) o; | ||
| 37 | - if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | ||
| 38 | - return true; | ||
| 39 | - } | ||
| 40 | - } else if (null == o) { | ||
| 41 | - return true; | 120 | + /** |
| 121 | + * 实例化路由-对象 | ||
| 122 | + */ | ||
| 123 | + public <T extends IProvider> T initRouterImpl(String routerPath) { | ||
| 124 | + T obj = null; | ||
| 125 | + try { | ||
| 126 | + obj = (T) ARouter.getInstance().build(routerPath).navigation(); | ||
| 127 | + } catch (Exception ignored) { | ||
| 42 | } | 128 | } |
| 43 | - return false; | 129 | + return obj; |
| 130 | + } | ||
| 131 | + | ||
| 132 | + public boolean isNull(Object... os) { | ||
| 133 | + return BaseHelpUtil.isNull(os); | ||
| 44 | } | 134 | } |
| 45 | 135 | ||
| 46 | public void onReceiveActHandleMessage(@NonNull Message msg) { | 136 | public void onReceiveActHandleMessage(@NonNull Message msg) { |
| @@ -79,5 +169,85 @@ public class BaseView implements MvpView { | @@ -79,5 +169,85 @@ public class BaseView implements MvpView { | ||
| 79 | Logger.xml(xml); | 169 | Logger.xml(xml); |
| 80 | } | 170 | } |
| 81 | 171 | ||
| 82 | - public void onDestory(){}; | 172 | + |
| 173 | + public void onPause() { | ||
| 174 | + //取消订阅 | ||
| 175 | + if (null != pauseDisposable && pauseDisposable.size() > 0) { | ||
| 176 | + pauseDisposable.clear(); | ||
| 177 | + } | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public void onDestory() { | ||
| 181 | + //取消订阅 | ||
| 182 | + if (null != destoryDisposable && destoryDisposable.size() > 0) { | ||
| 183 | + destoryDisposable.clear(); | ||
| 184 | + } | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + /** | ||
| 188 | + * 获取资源颜色 | ||
| 189 | + * | ||
| 190 | + * @param colorId | ||
| 191 | + * @return | ||
| 192 | + */ | ||
| 193 | + public int getResourceColor(@ColorRes int colorId) { | ||
| 194 | + return BaseHelpUtil.getResourceColor(me, colorId); | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + /** | ||
| 198 | + * 获取资源字符串 | ||
| 199 | + * | ||
| 200 | + * @param stringId | ||
| 201 | + * @return | ||
| 202 | + */ | ||
| 203 | + public String getResourceStr(@StringRes int stringId) { | ||
| 204 | + return BaseHelpUtil.getResourceStr(me, stringId); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + /** | ||
| 208 | + * 获取资源 | ||
| 209 | + * | ||
| 210 | + * @param drawableId | ||
| 211 | + * @return | ||
| 212 | + */ | ||
| 213 | + public Drawable getResourceDrawable(@DrawableRes int drawableId) { | ||
| 214 | + return BaseHelpUtil.getResourceDrawable(me, drawableId); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + /** | ||
| 218 | + * 用户提示 | ||
| 219 | + */ | ||
| 220 | + public void showToast(String message) { | ||
| 221 | + AlertUtil.showDeftToast(me, message); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + /** | ||
| 225 | + * 销毁 Dialog | ||
| 226 | + */ | ||
| 227 | + protected void disposeDialog(Dialog... dialogs) { | ||
| 228 | + if (dialogs == null) return; | ||
| 229 | + for (Dialog dialog : dialogs) if (dialog != null) dialog.dismiss(); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + public void onNetworkError(Context context, String errCode, String errMsg, Exception e) { | ||
| 233 | + if (!TextUtils.isEmpty(errMsg)) { | ||
| 234 | + showToast(errMsg); | ||
| 235 | + } else if (!TextUtils.isEmpty(errCode)) { | ||
| 236 | + switch (errCode) { | ||
| 237 | + case "-7001"://当前没有网络 | ||
| 238 | + showToast("请检查当前网络."); | ||
| 239 | + break; | ||
| 240 | + case "-1"://服务端错误 | ||
| 241 | + showToast("服务正在维护当中,请稍候."); | ||
| 242 | + break; | ||
| 243 | + default: | ||
| 244 | + showToast("服务正在升级当中,请稍候."); | ||
| 245 | + break; | ||
| 246 | + } | ||
| 247 | + } else if (e != null) { | ||
| 248 | + showToast("功能正在维护当中,请稍候."); | ||
| 249 | + } else { | ||
| 250 | + showToast("获取信息失败,请稍候."); | ||
| 251 | + } | ||
| 252 | + } | ||
| 83 | } | 253 | } |
core/base/src/main/java/com/cnlive/core/libs/base/listener/Callback.java
0 → 100644
core/base/src/main/java/com/cnlive/core/libs/base/network/manager/SubscriptionManager.java renamed to core/base/src/main/java/com/cnlive/core/libs/base/network/manager/RxManager.java
| @@ -4,6 +4,9 @@ package com.cnlive.core.libs.base.network.manager; | @@ -4,6 +4,9 @@ package com.cnlive.core.libs.base.network.manager; | ||
| 4 | import android.text.TextUtils; | 4 | import android.text.TextUtils; |
| 5 | import android.util.Log; | 5 | import android.util.Log; |
| 6 | 6 | ||
| 7 | + | ||
| 8 | +import com.cnlive.cloud.base.BuildConfig; | ||
| 9 | + | ||
| 7 | import java.util.HashMap; | 10 | import java.util.HashMap; |
| 8 | 11 | ||
| 9 | import io.reactivex.disposables.CompositeDisposable; | 12 | import io.reactivex.disposables.CompositeDisposable; |
| @@ -14,17 +17,18 @@ import io.reactivex.disposables.Disposable; | @@ -14,17 +17,18 @@ import io.reactivex.disposables.Disposable; | ||
| 14 | * | 17 | * |
| 15 | * @author ys | 18 | * @author ys |
| 16 | */ | 19 | */ |
| 17 | -public class SubscriptionManager { | ||
| 18 | - private static SubscriptionManager instance; | 20 | +public class RxManager { |
| 21 | + private static RxManager instance; | ||
| 19 | private HashMap<String, CompositeDisposable> hashDisposable;//所有订阅关系 | 22 | private HashMap<String, CompositeDisposable> hashDisposable;//所有订阅关系 |
| 20 | private HashMap<Integer, String> hashTag;//当前activity | 23 | private HashMap<Integer, String> hashTag;//当前activity |
| 21 | private HashMap<String, Integer> hashTagIndex;//当前activity | 24 | private HashMap<String, Integer> hashTagIndex;//当前activity |
| 22 | private String currentClassName; | 25 | private String currentClassName; |
| 26 | + private final String className = this.getClass().getName(); | ||
| 23 | 27 | ||
| 24 | /** | 28 | /** |
| 25 | * 构造函数 new CompositeDisposable对象 | 29 | * 构造函数 new CompositeDisposable对象 |
| 26 | */ | 30 | */ |
| 27 | - public SubscriptionManager() { | 31 | + public RxManager() { |
| 28 | if (null == hashDisposable) { | 32 | if (null == hashDisposable) { |
| 29 | hashDisposable = new HashMap<>(); | 33 | hashDisposable = new HashMap<>(); |
| 30 | } | 34 | } |
| @@ -41,11 +45,11 @@ public class SubscriptionManager { | @@ -41,11 +45,11 @@ public class SubscriptionManager { | ||
| 41 | * | 45 | * |
| 42 | * @return | 46 | * @return |
| 43 | */ | 47 | */ |
| 44 | - public static SubscriptionManager getInstance() { | 48 | + public synchronized static RxManager getInstance() { |
| 45 | if (instance == null) { | 49 | if (instance == null) { |
| 46 | - synchronized (SubscriptionManager.class) { | 50 | + synchronized (RxManager.class) { |
| 47 | if (instance == null) { | 51 | if (instance == null) { |
| 48 | - instance = new SubscriptionManager(); | 52 | + instance = new RxManager(); |
| 49 | } | 53 | } |
| 50 | } | 54 | } |
| 51 | } | 55 | } |
| @@ -53,79 +57,80 @@ public class SubscriptionManager { | @@ -53,79 +57,80 @@ public class SubscriptionManager { | ||
| 53 | } | 57 | } |
| 54 | 58 | ||
| 55 | public synchronized void setCurrentDisposables(String TAG) { | 59 | public synchronized void setCurrentDisposables(String TAG) { |
| 60 | + currentClassName = TAG; | ||
| 56 | if (null == hashDisposable.get(TAG)) { | 61 | if (null == hashDisposable.get(TAG)) { |
| 57 | - currentClassName = TAG; | ||
| 58 | hashDisposable.put(TAG, new CompositeDisposable()); | 62 | hashDisposable.put(TAG, new CompositeDisposable()); |
| 59 | //存放当前class映射 | 63 | //存放当前class映射 |
| 60 | hashTag.put(hashDisposable.size() - 1, TAG); | 64 | hashTag.put(hashDisposable.size() - 1, TAG); |
| 61 | hashTagIndex.put(TAG, hashTag.size() - 1); | 65 | hashTagIndex.put(TAG, hashTag.size() - 1); |
| 62 | - Log.d(TAG, "初始化: "); | 66 | + logDebug(className, TAG + "初始化订阅映射"); |
| 63 | } | 67 | } |
| 64 | } | 68 | } |
| 65 | 69 | ||
| 66 | /** | 70 | /** |
| 67 | * 取消订阅事件 | 71 | * 取消订阅事件 |
| 68 | */ | 72 | */ |
| 69 | - public synchronized void cancel(String TAG) { | 73 | + public synchronized void cancel(String FLAG) { |
| 70 | try { | 74 | try { |
| 71 | if (null != hashDisposable && hashDisposable.size() > 0) { | 75 | if (null != hashDisposable && hashDisposable.size() > 0) { |
| 72 | - if (null != hashDisposable.get(TAG) && hashDisposable.get(TAG).size() > 0) { | ||
| 73 | - CompositeDisposable mDisposables = hashDisposable.get(TAG); | ||
| 74 | - if (null!=mDisposables&&!mDisposables.isDisposed()) { | ||
| 75 | - Log.e(TAG, "cancel: 解除订阅"); | 76 | + if (null != hashDisposable.get(FLAG) && hashDisposable.get(FLAG).size() > 0) { |
| 77 | + CompositeDisposable mDisposables = hashDisposable.get(FLAG); | ||
| 78 | + if (null != mDisposables && !mDisposables.isDisposed()) { | ||
| 79 | + logDebug(currentClassName, FLAG + "cancel: 解除订阅"); | ||
| 76 | mDisposables.clear(); | 80 | mDisposables.clear(); |
| 77 | } | 81 | } |
| 78 | } | 82 | } |
| 79 | //移除 | 83 | //移除 |
| 80 | - hashDisposable.remove(TAG); | 84 | + hashDisposable.remove(FLAG); |
| 81 | } | 85 | } |
| 82 | - if (null != hashTagIndex.get(TAG)) { | ||
| 83 | - int currentIndex = hashTagIndex.get(TAG); | 86 | + if (null != hashTagIndex.get(FLAG)) { |
| 87 | + int currentIndex = hashTagIndex.get(FLAG); | ||
| 84 | //移除 | 88 | //移除 |
| 85 | if (null != hashTag.get(currentIndex)) { | 89 | if (null != hashTag.get(currentIndex)) { |
| 86 | - Log.e(TAG, "cancel: " + hashTag.get(currentIndex)); | 90 | + logDebug(className, FLAG + "订阅cancel: " + hashTag.get(currentIndex)); |
| 87 | hashTag.remove(currentIndex); | 91 | hashTag.remove(currentIndex); |
| 88 | } | 92 | } |
| 89 | - hashTagIndex.remove(TAG); | 93 | + hashTagIndex.remove(FLAG); |
| 90 | } | 94 | } |
| 91 | } catch (Exception e) { | 95 | } catch (Exception e) { |
| 92 | - Log.d(TAG, "cancel: " + e.getMessage()); | 96 | + logErr(className, FLAG + "订阅cancel异常: " + e.getMessage()); |
| 93 | } | 97 | } |
| 94 | } | 98 | } |
| 95 | 99 | ||
| 96 | /** | 100 | /** |
| 97 | * 订阅事件加入到CompositeDisposable容器中 | 101 | * 订阅事件加入到CompositeDisposable容器中 |
| 102 | + * 可以不写setCurrentDisposables | ||
| 98 | * | 103 | * |
| 99 | * @param disposable 订阅事件 | 104 | * @param disposable 订阅事件 |
| 100 | */ | 105 | */ |
| 101 | - public synchronized void add(Disposable disposable) { | 106 | + public synchronized void add(String FLAG, Disposable disposable) { |
| 107 | + //判断是否已经存在该订阅关系 | ||
| 108 | + if (!TextUtils.isEmpty(FLAG)) { | ||
| 109 | + setCurrentDisposables(FLAG); | ||
| 110 | + } | ||
| 111 | + String tempFlag = ""; | ||
| 112 | + if (TextUtils.isEmpty(FLAG)) { | ||
| 113 | + tempFlag = currentClassName; | ||
| 114 | + } else { | ||
| 115 | + tempFlag = FLAG; | ||
| 116 | + } | ||
| 102 | try { | 117 | try { |
| 103 | if (disposable == null) return; | 118 | if (disposable == null) return; |
| 104 | //每次去除最新的activity进行存放 | 119 | //每次去除最新的activity进行存放 |
| 105 | if (null != hashDisposable && hashDisposable.size() > 0) { | 120 | if (null != hashDisposable && hashDisposable.size() > 0) { |
| 106 | - if (!TextUtils.isEmpty(currentClassName)) { | ||
| 107 | - if (null != hashDisposable.get(currentClassName)) { | 121 | + if (!TextUtils.isEmpty(tempFlag)) { |
| 122 | + if (null != hashDisposable.get(tempFlag)) { | ||
| 108 | //存放当前activity对应的订阅 | 123 | //存放当前activity对应的订阅 |
| 109 | - hashDisposable.get(currentClassName).add(disposable); | ||
| 110 | - Log.d(currentClassName, "add: 添加订阅关系" + hashDisposable.size()); | 124 | + hashDisposable.get(tempFlag).add(disposable); |
| 125 | + logDebug(className, tempFlag + "add: 添加订阅关系" + hashDisposable.get(tempFlag).size()); | ||
| 111 | } | 126 | } |
| 112 | } | 127 | } |
| 113 | } | 128 | } |
| 114 | } catch (Exception e) { | 129 | } catch (Exception e) { |
| 115 | - Log.e("SubscriptionManager", "cancel: " + e.getMessage()); | 130 | + logErr(className, "cancel: " + e.getMessage()); |
| 116 | } | 131 | } |
| 117 | } | 132 | } |
| 118 | 133 | ||
| 119 | -// /** | ||
| 120 | -// * 取消订阅事件 | ||
| 121 | -// * | ||
| 122 | -// * @param disposable 订阅事件 | ||
| 123 | -// */ | ||
| 124 | -// public void cancel(Disposable disposable) { | ||
| 125 | -// if (disposable != null) { | ||
| 126 | -// mDisposables.delete(disposable); | ||
| 127 | -// } | ||
| 128 | -// } | ||
| 129 | 134 | ||
| 130 | /** | 135 | /** |
| 131 | * 清除容器所有 | 136 | * 清除容器所有 |
| @@ -148,7 +153,19 @@ public class SubscriptionManager { | @@ -148,7 +153,19 @@ public class SubscriptionManager { | ||
| 148 | hashTag.clear(); | 153 | hashTag.clear(); |
| 149 | hashTagIndex.clear(); | 154 | hashTagIndex.clear(); |
| 150 | } catch (Exception e) { | 155 | } catch (Exception e) { |
| 151 | - Log.e("SubscriptionManager", "cancelAll: " + e.getMessage()); | 156 | + logErr(className, "清除所有订阅cancelAll: " + e.getMessage()); |
| 157 | + } | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + private void logDebug(String tag, String msg) { | ||
| 161 | + if (BuildConfig.DEBUG) { | ||
| 162 | + Log.d(tag, msg); | ||
| 163 | + } | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + private void logErr(String tag, String msg) { | ||
| 167 | + if (BuildConfig.DEBUG) { | ||
| 168 | + Log.e(tag, msg); | ||
| 152 | } | 169 | } |
| 153 | } | 170 | } |
| 154 | } | 171 | } |
core/base/src/main/java/com/cnlive/core/libs/base/ui/widget/SelectDialog.java
| @@ -12,14 +12,16 @@ import android.widget.Button; | @@ -12,14 +12,16 @@ import android.widget.Button; | ||
| 12 | import android.widget.LinearLayout; | 12 | import android.widget.LinearLayout; |
| 13 | import android.widget.TextView; | 13 | import android.widget.TextView; |
| 14 | 14 | ||
| 15 | +import androidx.annotation.ColorRes; | ||
| 15 | import androidx.annotation.NonNull; | 16 | import androidx.annotation.NonNull; |
| 16 | import androidx.core.content.ContextCompat; | 17 | import androidx.core.content.ContextCompat; |
| 17 | 18 | ||
| 18 | import com.cnlive.cloud.base.R; | 19 | import com.cnlive.cloud.base.R; |
| 20 | +import com.cnlive.core.libs.base.util.DensityUtils; | ||
| 19 | 21 | ||
| 20 | 22 | ||
| 21 | /** | 23 | /** |
| 22 | - * 任务编辑对话框 | 24 | + * 选择对话框 |
| 23 | * | 25 | * |
| 24 | * @author ShinnyYang | 26 | * @author ShinnyYang |
| 25 | * @date 2019/3/27 14:11 | 27 | * @date 2019/3/27 14:11 |
| @@ -51,21 +53,96 @@ public class SelectDialog extends Dialog { | @@ -51,21 +53,96 @@ public class SelectDialog extends Dialog { | ||
| 51 | 53 | ||
| 52 | } | 54 | } |
| 53 | 55 | ||
| 54 | - public void setLeftBtnColor(int textColor) { | ||
| 55 | - if (null != btn_cancel && null != cancelInterface) { | 56 | + public SelectDialog(@NonNull Context context, String tipText, String btnCancelText, String btnOkText) { |
| 57 | + super(context, R.style.MyDialog); | ||
| 58 | + this.context = context; | ||
| 59 | + view = LayoutInflater.from(context).inflate(R.layout.my_dialog_select, null); | ||
| 60 | + initView(view); | ||
| 61 | + layoutParams = new LinearLayout.LayoutParams((int) (getScreenWidth(context) * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT); | ||
| 62 | + ll_child.setLayoutParams(layoutParams); | ||
| 63 | + | ||
| 64 | + tv_dialog_tip.setText(tipText); | ||
| 65 | + btn_cancel.setText(btnCancelText); | ||
| 66 | + btn_ok.setText(btnOkText); | ||
| 67 | + | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public SelectDialog(@NonNull Context context, String tipText) { | ||
| 71 | + super(context, R.style.MyDialog); | ||
| 72 | + this.context = context; | ||
| 73 | + view = LayoutInflater.from(context).inflate(R.layout.my_dialog_select, null); | ||
| 74 | + initView(view); | ||
| 75 | + layoutParams = new LinearLayout.LayoutParams((int) (getScreenWidth(context) * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT); | ||
| 76 | + ll_child.setLayoutParams(layoutParams); | ||
| 77 | + | ||
| 78 | + tv_dialog_tip.setText(tipText); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public SelectDialog(@NonNull Context context) { | ||
| 82 | + super(context, R.style.MyDialog); | ||
| 83 | + this.context = context; | ||
| 84 | + view = LayoutInflater.from(context).inflate(R.layout.my_dialog_select, null); | ||
| 85 | + initView(view); | ||
| 86 | + layoutParams = new LinearLayout.LayoutParams((int) (getScreenWidth(context) * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT); | ||
| 87 | + ll_child.setLayoutParams(layoutParams); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public void setLeftInterface(DialogInterface cancelInterface) { | ||
| 91 | + this.cancelInterface = cancelInterface; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + public void setRightInterface(DialogInterface okInterface) { | ||
| 95 | + this.okInterface = okInterface; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public void setLeftText(String text) { | ||
| 99 | + if (null != btn_cancel) { | ||
| 100 | + btn_cancel.setText(text); | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public void setRightText(String text) { | ||
| 105 | + if (null != btn_ok) { | ||
| 106 | + btn_ok.setText(text); | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public void setLeftBtnColor(@ColorRes int textColor) { | ||
| 111 | + if (null != btn_cancel) { | ||
| 56 | btn_cancel.setTextColor(ContextCompat.getColor(context, textColor)); | 112 | btn_cancel.setTextColor(ContextCompat.getColor(context, textColor)); |
| 57 | } | 113 | } |
| 58 | } | 114 | } |
| 59 | 115 | ||
| 60 | - public void setRightBtnColor(int textColor) { | ||
| 61 | - if (null != btn_ok && null != cancelInterface) { | 116 | + public void setRightBtnColor(@ColorRes int textColor) { |
| 117 | + if (null != btn_ok) { | ||
| 62 | btn_ok.setTextColor(ContextCompat.getColor(context, textColor)); | 118 | btn_ok.setTextColor(ContextCompat.getColor(context, textColor)); |
| 63 | } | 119 | } |
| 64 | } | 120 | } |
| 65 | 121 | ||
| 66 | - public void setTipTextStyle(Typeface typeface){ | 122 | + public void setTipTextStyle(Typeface typeface) { |
| 67 | tv_dialog_tip.setTypeface(typeface); | 123 | tv_dialog_tip.setTypeface(typeface); |
| 68 | } | 124 | } |
| 125 | + | ||
| 126 | + public void setTipGravity(int gravity) { | ||
| 127 | + tv_dialog_tip.setGravity(gravity); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public void setTipTextSize(float textSize) { | ||
| 131 | + tv_dialog_tip.setTextSize(textSize); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + public void setTipTextPaddingLeft(float dp){ | ||
| 135 | + tv_dialog_tip.setPadding(DensityUtils.dp2px(dp),0,0,0); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + public void setLeftTextStyle(Typeface typeface) { | ||
| 139 | + btn_cancel.setTypeface(typeface); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + public void setRightTextStyle(Typeface typeface) { | ||
| 143 | + btn_ok.setTypeface(typeface); | ||
| 144 | + } | ||
| 145 | + | ||
| 69 | public void setTipMessage(String message) { | 146 | public void setTipMessage(String message) { |
| 70 | tv_dialog_tip.setText(message); | 147 | tv_dialog_tip.setText(message); |
| 71 | } | 148 | } |
| @@ -79,8 +156,6 @@ public class SelectDialog extends Dialog { | @@ -79,8 +156,6 @@ public class SelectDialog extends Dialog { | ||
| 79 | @Override | 156 | @Override |
| 80 | protected void onCreate(Bundle savedInstanceState) { | 157 | protected void onCreate(Bundle savedInstanceState) { |
| 81 | super.onCreate(savedInstanceState); | 158 | super.onCreate(savedInstanceState); |
| 82 | - | ||
| 83 | - | ||
| 84 | //显示视图 | 159 | //显示视图 |
| 85 | this.setContentView(view); | 160 | this.setContentView(view); |
| 86 | } | 161 | } |
| @@ -93,14 +168,17 @@ public class SelectDialog extends Dialog { | @@ -93,14 +168,17 @@ public class SelectDialog extends Dialog { | ||
| 93 | btn_cancel.setOnClickListener(new View.OnClickListener() { | 168 | btn_cancel.setOnClickListener(new View.OnClickListener() { |
| 94 | @Override | 169 | @Override |
| 95 | public void onClick(View view) { | 170 | public void onClick(View view) { |
| 96 | - cancelInterface.onClick(SelectDialog.this); | 171 | + if (null != cancelInterface) { |
| 172 | + cancelInterface.onClick(SelectDialog.this); | ||
| 173 | + } | ||
| 97 | } | 174 | } |
| 98 | }); | 175 | }); |
| 99 | btn_ok.setOnClickListener(new View.OnClickListener() { | 176 | btn_ok.setOnClickListener(new View.OnClickListener() { |
| 100 | @Override | 177 | @Override |
| 101 | public void onClick(View view) { | 178 | public void onClick(View view) { |
| 102 | - | ||
| 103 | - okInterface.onClick(SelectDialog.this); | 179 | + if (null != okInterface) { |
| 180 | + okInterface.onClick(SelectDialog.this); | ||
| 181 | + } | ||
| 104 | } | 182 | } |
| 105 | }); | 183 | }); |
| 106 | } | 184 | } |
core/base/src/main/java/com/cnlive/core/libs/base/util/AppManager.java
| @@ -6,6 +6,7 @@ import android.content.Context; | @@ -6,6 +6,7 @@ import android.content.Context; | ||
| 6 | 6 | ||
| 7 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; | 7 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; |
| 8 | 8 | ||
| 9 | +import java.lang.ref.WeakReference; | ||
| 9 | import java.util.Arrays; | 10 | import java.util.Arrays; |
| 10 | import java.util.Collections; | 11 | import java.util.Collections; |
| 11 | import java.util.Iterator; | 12 | import java.util.Iterator; |
| @@ -24,6 +25,7 @@ public class AppManager { | @@ -24,6 +25,7 @@ public class AppManager { | ||
| 24 | private static OnActivityStatusChangeListener onActivityStatusChangeListener; | 25 | private static OnActivityStatusChangeListener onActivityStatusChangeListener; |
| 25 | private static Stack<BaseActivity> activityStack; | 26 | private static Stack<BaseActivity> activityStack; |
| 26 | private static AppManager instance; | 27 | private static AppManager instance; |
| 28 | + private static WeakReference<BaseActivity> activeActivity; | ||
| 27 | 29 | ||
| 28 | private AppManager() { | 30 | private AppManager() { |
| 29 | } | 31 | } |
| @@ -55,6 +57,9 @@ public class AppManager { | @@ -55,6 +57,9 @@ public class AppManager { | ||
| 55 | * 获取当前Activity(堆栈中最后一个压入的) | 57 | * 获取当前Activity(堆栈中最后一个压入的) |
| 56 | */ | 58 | */ |
| 57 | public BaseActivity currentActivity() { | 59 | public BaseActivity currentActivity() { |
| 60 | + if (activityStack == null) { | ||
| 61 | + return null; | ||
| 62 | + } | ||
| 58 | BaseActivity activity = null; | 63 | BaseActivity activity = null; |
| 59 | if (!activityStack.empty()) { | 64 | if (!activityStack.empty()) { |
| 60 | activity = activityStack.lastElement(); | 65 | activity = activityStack.lastElement(); |
| @@ -63,9 +68,21 @@ public class AppManager { | @@ -63,9 +68,21 @@ public class AppManager { | ||
| 63 | } | 68 | } |
| 64 | 69 | ||
| 65 | /** | 70 | /** |
| 71 | + * 获取当前处于活动状态的Activity | ||
| 72 | + * | ||
| 73 | + * @return | ||
| 74 | + */ | ||
| 75 | + public BaseActivity getActiveActivity() { | ||
| 76 | + return activeActivity.get(); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + /** | ||
| 66 | * 结束当前Activity(堆栈中最后一个压入的) | 80 | * 结束当前Activity(堆栈中最后一个压入的) |
| 67 | */ | 81 | */ |
| 68 | public void finishActivity() { | 82 | public void finishActivity() { |
| 83 | + if (activityStack == null) { | ||
| 84 | + return; | ||
| 85 | + } | ||
| 69 | BaseActivity activity = activityStack.lastElement(); | 86 | BaseActivity activity = activityStack.lastElement(); |
| 70 | killActivity(activity); | 87 | killActivity(activity); |
| 71 | } | 88 | } |
| @@ -74,7 +91,7 @@ public class AppManager { | @@ -74,7 +91,7 @@ public class AppManager { | ||
| 74 | * 结束指定的Activity | 91 | * 结束指定的Activity |
| 75 | */ | 92 | */ |
| 76 | public void killActivity(BaseActivity activity) { | 93 | public void killActivity(BaseActivity activity) { |
| 77 | - if (activity != null) { | 94 | + if (activity != null && activityStack != null) { |
| 78 | if (activity != null) { | 95 | if (activity != null) { |
| 79 | activity.finishActivity(); | 96 | activity.finishActivity(); |
| 80 | } | 97 | } |
| @@ -87,6 +104,9 @@ public class AppManager { | @@ -87,6 +104,9 @@ public class AppManager { | ||
| 87 | * 结束指定类名的Activity | 104 | * 结束指定类名的Activity |
| 88 | */ | 105 | */ |
| 89 | public void killActivity(Class<?> cls) { | 106 | public void killActivity(Class<?> cls) { |
| 107 | + if (activityStack == null) { | ||
| 108 | + return; | ||
| 109 | + } | ||
| 90 | Iterator<BaseActivity> iterator = activityStack.iterator(); | 110 | Iterator<BaseActivity> iterator = activityStack.iterator(); |
| 91 | BaseActivity temp = null; | 111 | BaseActivity temp = null; |
| 92 | while (iterator.hasNext()) { | 112 | while (iterator.hasNext()) { |
| @@ -133,14 +153,18 @@ public class AppManager { | @@ -133,14 +153,18 @@ public class AppManager { | ||
| 133 | } | 153 | } |
| 134 | 154 | ||
| 135 | public void deleteActivity(BaseActivity activity) { | 155 | public void deleteActivity(BaseActivity activity) { |
| 136 | - if (activity != null) { | ||
| 137 | - activityStack.remove(activity); | ||
| 138 | - if (onActivityStatusChangeListener != null) { | ||
| 139 | - onActivityStatusChangeListener.onActivityDestroy(activity); | ||
| 140 | - if (activityStack.isEmpty()) { | ||
| 141 | - onActivityStatusChangeListener.onAllActivityClose(); | 156 | + try { |
| 157 | + if (activity != null && activityStack != null) { | ||
| 158 | + activityStack.remove(activity); | ||
| 159 | + if (onActivityStatusChangeListener != null) { | ||
| 160 | + onActivityStatusChangeListener.onActivityDestroy(activity); | ||
| 161 | + if (activityStack.isEmpty()) { | ||
| 162 | + onActivityStatusChangeListener.onAllActivityClose(); | ||
| 163 | + } | ||
| 142 | } | 164 | } |
| 143 | } | 165 | } |
| 166 | + } catch (Exception e) { | ||
| 167 | + | ||
| 144 | } | 168 | } |
| 145 | } | 169 | } |
| 146 | 170 | ||
| @@ -174,6 +198,9 @@ public class AppManager { | @@ -174,6 +198,9 @@ public class AppManager { | ||
| 174 | * @param cls activity | 198 | * @param cls activity |
| 175 | */ | 199 | */ |
| 176 | public BaseActivity getActivityInstance(Class<?> cls) { | 200 | public BaseActivity getActivityInstance(Class<?> cls) { |
| 201 | + if (activityStack == null) { | ||
| 202 | + return null; | ||
| 203 | + } | ||
| 177 | if (!activityStack.empty()) { | 204 | if (!activityStack.empty()) { |
| 178 | Stack<BaseActivity> reverseList = new Stack<BaseActivity>(); | 205 | Stack<BaseActivity> reverseList = new Stack<BaseActivity>(); |
| 179 | reverseList.addAll(activityStack); | 206 | reverseList.addAll(activityStack); |
| @@ -216,4 +243,8 @@ public class AppManager { | @@ -216,4 +243,8 @@ public class AppManager { | ||
| 216 | 243 | ||
| 217 | void onAllActivityClose(); | 244 | void onAllActivityClose(); |
| 218 | } | 245 | } |
| 246 | + | ||
| 247 | + public static void setActiveActivity(BaseActivity activeActivity) { | ||
| 248 | + AppManager.activeActivity = new WeakReference<>(activeActivity); | ||
| 249 | + } | ||
| 219 | } | 250 | } |
core/base/src/main/java/com/cnlive/core/libs/base/util/BaseHelpUtil.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.graphics.drawable.Drawable; | ||
| 5 | +import android.text.TextUtils; | ||
| 6 | + | ||
| 7 | +import androidx.annotation.ColorRes; | ||
| 8 | +import androidx.annotation.DrawableRes; | ||
| 9 | +import androidx.annotation.StringRes; | ||
| 10 | + | ||
| 11 | +/* | ||
| 12 | + *@date:2020/4/11 12:11 | ||
| 13 | + *@author:杨帅 | ||
| 14 | + */public class BaseHelpUtil { | ||
| 15 | + /** | ||
| 16 | + * 获取资源颜色 | ||
| 17 | + * | ||
| 18 | + * @param colorId | ||
| 19 | + * @param context | ||
| 20 | + * @return | ||
| 21 | + */ | ||
| 22 | + public static int getResourceColor(Context context, @ColorRes int colorId) { | ||
| 23 | + return context.getResources().getColor(colorId); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 获取资源 | ||
| 28 | + * | ||
| 29 | + * @param drawableId | ||
| 30 | + * @param context | ||
| 31 | + * @return | ||
| 32 | + */ | ||
| 33 | + public static Drawable getResourceDrawable(Context context, @DrawableRes int drawableId) { | ||
| 34 | + return context.getResources().getDrawable(drawableId); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 获取资源字符串 | ||
| 39 | + * | ||
| 40 | + * @param stringId | ||
| 41 | + * @param context | ||
| 42 | + * @return | ||
| 43 | + */ | ||
| 44 | + public static String getResourceStr(Context context, @StringRes int stringId) { | ||
| 45 | + return context.getResources().getString(stringId); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public static boolean isNull(Object... os) { | ||
| 49 | + | ||
| 50 | + if (null == os) { | ||
| 51 | + return true; | ||
| 52 | + } | ||
| 53 | + for (Object o : os) { | ||
| 54 | + if (null == o) { | ||
| 55 | + return true; | ||
| 56 | + } | ||
| 57 | + if (o instanceof String) { | ||
| 58 | + String s = (String) o; | ||
| 59 | + if (TextUtils.isEmpty(s) || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) | ||
| 60 | + return true; | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + return false; | ||
| 64 | + } | ||
| 65 | +} |
core/base/src/main/java/com/cnlive/core/libs/base/util/GlobalLifeCircleListener.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.cnlive.core.libs.base.frame.activity.BaseActivity; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * Author: @Kongzue | ||
| 8 | + * Github: https://github.com/kongzue/ | ||
| 9 | + * Homepage: http://kongzue.com/ | ||
| 10 | + * Mail: myzcxhh@live.cn | ||
| 11 | + * CreateTime: 2018/9/1 15:44 | ||
| 12 | + */ | ||
| 13 | +public abstract class GlobalLifeCircleListener { | ||
| 14 | + | ||
| 15 | + public abstract void onCreate(BaseActivity me, String className); | ||
| 16 | + | ||
| 17 | + public abstract void onResume(BaseActivity me, String className); | ||
| 18 | + | ||
| 19 | + public abstract void onPause(BaseActivity me, String className); | ||
| 20 | + | ||
| 21 | + public abstract void onDestroy(BaseActivity me, String className); | ||
| 22 | + | ||
| 23 | + public void windowFocus(BaseActivity me, String className, boolean hasFocus) { | ||
| 24 | + | ||
| 25 | + } | ||
| 26 | +} |
core/base/src/main/java/com/cnlive/core/libs/base/util/LifeCircleListener.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Author: @Kongzue | ||
| 5 | + * Github: https://github.com/kongzue/ | ||
| 6 | + * Homepage: http://kongzue.com/ | ||
| 7 | + * Mail: myzcxhh@live.cn | ||
| 8 | + * CreateTime: 2018/8/1 01:36 | ||
| 9 | + */ | ||
| 10 | +public interface LifeCircleListener { | ||
| 11 | + | ||
| 12 | + void onCreate(); | ||
| 13 | + | ||
| 14 | + void onResume(); | ||
| 15 | + | ||
| 16 | + void onPause(); | ||
| 17 | + | ||
| 18 | + void onDestroy(); | ||
| 19 | + | ||
| 20 | +} |
core/base/src/main/java/com/me/yokeyword/fragmentation/SupportFragmentDelegate.java
| @@ -57,7 +57,9 @@ public class SupportFragmentDelegate { | @@ -57,7 +57,9 @@ public class SupportFragmentDelegate { | ||
| 57 | private ISupportActivity mSupport; | 57 | private ISupportActivity mSupport; |
| 58 | boolean mAnimByActivity = true; | 58 | boolean mAnimByActivity = true; |
| 59 | EnterAnimListener mEnterAnimListener; | 59 | EnterAnimListener mEnterAnimListener; |
| 60 | - | 60 | + //fragment根布局是否可点击,多用于多个fragment叠加在一个activity,是否可点击下层的fragment,默认是可以点击下层的 |
| 61 | + private boolean isRootViewCanClickable = false; | ||
| 62 | + private View rootView = null; | ||
| 61 | private boolean mRootViewClickable; | 63 | private boolean mRootViewClickable; |
| 62 | 64 | ||
| 63 | public SupportFragmentDelegate(ISupportFragment support) { | 65 | public SupportFragmentDelegate(ISupportFragment support) { |
| @@ -187,11 +189,15 @@ public class SupportFragmentDelegate { | @@ -187,11 +189,15 @@ public class SupportFragmentDelegate { | ||
| 187 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { | 189 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { |
| 188 | getVisibleDelegate().onActivityCreated(savedInstanceState); | 190 | getVisibleDelegate().onActivityCreated(savedInstanceState); |
| 189 | 191 | ||
| 190 | - View view = mFragment.getView(); | ||
| 191 | - if (view != null) { | ||
| 192 | - mRootViewClickable = view.isClickable(); | ||
| 193 | - view.setClickable(true); | ||
| 194 | - setBackground(view); | 192 | + rootView = mFragment.getView(); |
| 193 | + if (rootView != null) { | ||
| 194 | + //只有设置为可点击的时候才设置 | ||
| 195 | + if (isRootViewCanClickable) { | ||
| 196 | + //解决多个fragment点击无响应的问题 | ||
| 197 | + rootView.setClickable(isRootViewCanClickable); | ||
| 198 | + } | ||
| 199 | + setBackground(rootView); | ||
| 200 | + mRootViewClickable = rootView.isClickable(); | ||
| 195 | } | 201 | } |
| 196 | 202 | ||
| 197 | 203 | ||
| @@ -210,6 +216,32 @@ public class SupportFragmentDelegate { | @@ -210,6 +216,32 @@ public class SupportFragmentDelegate { | ||
| 210 | } | 216 | } |
| 211 | } | 217 | } |
| 212 | 218 | ||
| 219 | + /** | ||
| 220 | + * 获取fragment根布局是否可以点击 | ||
| 221 | + * 如设置可点击,那么,多个fragment使用时,需要注意层级叠加顺序 | ||
| 222 | + * 默认为底层不可点击 | ||
| 223 | + * | ||
| 224 | + * @return | ||
| 225 | + */ | ||
| 226 | + private boolean getRootViewCanClickable() { | ||
| 227 | + return isRootViewCanClickable; | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + /** | ||
| 231 | + * 设置底层view是否可点击 | ||
| 232 | + * | ||
| 233 | + * @param isclick | ||
| 234 | + */ | ||
| 235 | + public void setFragmentRootViewCanClickable(boolean isclick) { | ||
| 236 | + isRootViewCanClickable = isclick; | ||
| 237 | + if (rootView != null) { | ||
| 238 | + mRootViewClickable = isclick; | ||
| 239 | + if (isclick) { | ||
| 240 | + rootView.setClickable(isclick); | ||
| 241 | + } | ||
| 242 | + } | ||
| 243 | + } | ||
| 244 | + | ||
| 213 | public void onResume() { | 245 | public void onResume() { |
| 214 | getVisibleDelegate().onResume(); | 246 | getVisibleDelegate().onResume(); |
| 215 | } | 247 | } |
| @@ -359,9 +391,9 @@ public class SupportFragmentDelegate { | @@ -359,9 +391,9 @@ public class SupportFragmentDelegate { | ||
| 359 | } | 391 | } |
| 360 | 392 | ||
| 361 | /** | 393 | /** |
| 362 | - * 类似 {@link Activity#onActivityResult(int, int, Intent)} | 394 | + * 类似 {@link Activity onActivityResult(int, int, Intent)} |
| 363 | * <p> | 395 | * <p> |
| 364 | - * Similar to {@link Activity#onActivityResult(int, int, Intent)} | 396 | + * Similar to {@link Activity onActivityResult(int, int, Intent)} |
| 365 | * | 397 | * |
| 366 | * @see #startForResult(ISupportFragment, int) | 398 | * @see #startForResult(ISupportFragment, int) |
| 367 | */ | 399 | */ |
| @@ -370,9 +402,9 @@ public class SupportFragmentDelegate { | @@ -370,9 +402,9 @@ public class SupportFragmentDelegate { | ||
| 370 | 402 | ||
| 371 | /** | 403 | /** |
| 372 | * 在start(TargetFragment,LaunchMode)时,启动模式为SingleTask/SingleTop, 回调TargetFragment的该方法 | 404 | * 在start(TargetFragment,LaunchMode)时,启动模式为SingleTask/SingleTop, 回调TargetFragment的该方法 |
| 373 | - * 类似 {@link Activity#onNewIntent(Intent)} | 405 | + * 类似 {@link Activity onNewIntent(Intent)} |
| 374 | * <p> | 406 | * <p> |
| 375 | - * Similar to {@link Activity#onNewIntent(Intent)} | 407 | + * Similar to {@link Activity onNewIntent(Intent)} |
| 376 | * | 408 | * |
| 377 | * @param args putNewBundle(Bundle newBundle) | 409 | * @param args putNewBundle(Bundle newBundle) |
| 378 | * @see #start(ISupportFragment, int) | 410 | * @see #start(ISupportFragment, int) |
core/network/src/main/java/com/cnlive/core/network/HttpConn.java
| 1 | package com.cnlive.core.network; | 1 | package com.cnlive.core.network; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -import com.cnlive.core.libs.base.network.manager.SubscriptionManager; | 4 | +import com.cnlive.core.libs.base.network.manager.RxManager; |
| 5 | import com.cnlive.core.network.interfaces.IBaseResult; | 5 | import com.cnlive.core.network.interfaces.IBaseResult; |
| 6 | import com.cnlive.core.network.model.BaseObserver; | 6 | import com.cnlive.core.network.model.BaseObserver; |
| 7 | import com.cnlive.core.network.model.BaseResult; | 7 | import com.cnlive.core.network.model.BaseResult; |
| @@ -130,7 +130,7 @@ public class HttpConn { | @@ -130,7 +130,7 @@ public class HttpConn { | ||
| 130 | // }); | 130 | // }); |
| 131 | //如果未解除订阅 | 131 | //如果未解除订阅 |
| 132 | if (null != disposable && !disposable.isDisposed()) { | 132 | if (null != disposable && !disposable.isDisposed()) { |
| 133 | - SubscriptionManager.getInstance().add(disposable); | 133 | + RxManager.getInstance().add("",disposable); |
| 134 | } | 134 | } |
| 135 | return disposable; | 135 | return disposable; |
| 136 | } | 136 | } |
gradle.properties
| @@ -15,4 +15,5 @@ android.useAndroidX=true | @@ -15,4 +15,5 @@ android.useAndroidX=true | ||
| 15 | android.enableJetifier=true | 15 | android.enableJetifier=true |
| 16 | android.enableR8=true | 16 | android.enableR8=true |
| 17 | org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" | 17 | org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" |
| 18 | - | 18 | +#修复vivo无法安装debug |
| 19 | +android.injected.testOnly=false |