From 32b5f366ceaad4aa9a33eccf0b109eef24175495 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期二, 10 十月 2023 14:55:01 +0800 Subject: [PATCH] 2023年10月10日14:54:56 --- app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java | 78 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 76 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java b/app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java index e49c4ff..e3b1d84 100644 --- a/app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java @@ -8,18 +8,26 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import com.hdl.photovoltaic.R; +import com.hdl.photovoltaic.bean.BaseEventBus; import com.hdl.photovoltaic.listener.BaseView; +import com.hdl.photovoltaic.other.HdlThreadLogic; import com.hdl.photovoltaic.utils.AppManagerUtils; +import com.hdl.photovoltaic.widget.LoadingDialog; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; public abstract class BaseActivity extends AppCompatActivity implements BaseView { + private LoadingDialog loadingDialog; protected Activity _mActivity; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - _mActivity = this; Object content = getContentView(); //娣诲姞Activity鍒板爢鏍� @@ -32,15 +40,81 @@ throw new RuntimeException("getContentView() should be a @LayoutRes or a View"); } onBindView(savedInstanceState); + //娉ㄥ唽EventBus + registerEventBus(); + } + + /** + * 鑾峰彇LoadingDialog + * + * @return LoadingDialog + */ + protected LoadingDialog getLoadingDialog() { + if (loadingDialog == null && _mActivity != null) { + loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_Dialog); + } + return loadingDialog; + } + + /** + * 寮�濮婰oading + */ + protected void showLoading() { + getLoadingDialog().start(); + } + + /** + * 寮�濮婰oading + * + * @param mes 鑷畾涔夋枃鏈� + */ + protected void showLoading(String mes) { + getLoadingDialog().start(); + getLoadingDialog().setText(mes); + } + + /** + * 鍋滄闅愯棌Loading + */ + protected void hideLoading() { + HdlThreadLogic.runMainThread(new Runnable() { + @Override + public void run() { + if (loadingDialog != null && loadingDialog.isShowing()) { + loadingDialog.stop(); + } + } + }, null, null); } @Override protected void onDestroy() { super.onDestroy(); + //闅愯棌Loading + hideLoading(); + //娉ㄩ攢EventBus + unregisterEventBus(); } + + protected void unregisterEventBus() { + if (EventBus.getDefault().isRegistered(this)) { + EventBus.getDefault().unregister(this); + } + } + + protected void registerEventBus() { + if (!EventBus.getDefault().isRegistered(this)) { + EventBus.getDefault().register(this); + } + } + + @Subscribe(threadMode = ThreadMode.POSTING) + public void onEventMessage(BaseEventBus eventBus) { + } + /** * 鏄剧ずView @@ -67,7 +141,7 @@ /** * 绠�鍗曠殑璺宠浆Activity * - * @param clazz + * @param clazz _ */ protected void startActivity(Class<?> clazz) { Intent intent = new Intent(this, clazz); -- Gitblit v1.8.0