From a67980d23f9e2d27345fd12e7a889f4cc52695f7 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期一, 25 三月 2024 13:36:50 +0800 Subject: [PATCH] 2024年03月25日13:24:47 --- app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java | 92 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 91 insertions(+), 1 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 04b2ce1..6d4493e 100644 --- a/app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java @@ -1,25 +1,38 @@ package com.hdl.photovoltaic.base; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.util.Log; import android.view.View; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import com.hdl.photovoltaic.R; +import com.hdl.photovoltaic.config.UserConfigManage; import com.hdl.photovoltaic.listener.BaseView; +import com.hdl.photovoltaic.other.HdlThreadLogic; import com.hdl.photovoltaic.utils.AppManagerUtils; +import com.hdl.photovoltaic.utils.LocalManageUtil; +import com.hdl.photovoltaic.widget.LoadingDialog; +import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; + +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,16 +45,93 @@ throw new RuntimeException("getContentView() should be a @LayoutRes or a View"); } onBindView(savedInstanceState); + //娉ㄥ唽EventBus + registerEventBus(); + } + + @Override + protected void attachBaseContext(Context newBase) { + //app涓嫳鏂囪缃� + LocalManageUtil.changeAppLanguage(UserConfigManage.getInstance().getCurrentAppLanguage(), newBase); + super.attachBaseContext(newBase); + + + } + + /** + * 鑾峰彇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(); + //绉婚櫎Activity + AppManagerUtils.getAppManager().removeActivity(this); + //娉ㄩ攢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 * -- Gitblit v1.8.0