From d876842e13fccca41ddaf05e9ff8c58ce7e7444b Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期三, 03 七月 2024 10:53:55 +0800 Subject: [PATCH] 2024年07月03日10:52:29 --- app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 42 insertions(+), 8 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 55f0f95..6d4493e 100644 --- a/app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java @@ -2,25 +2,25 @@ import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; -import android.graphics.drawable.ColorDrawable; import android.os.Bundle; -import android.util.Log; -import android.view.KeyEvent; import android.view.View; -import android.view.WindowManager; -import android.widget.TextView; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; 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 { @@ -28,9 +28,11 @@ private LoadingDialog loadingDialog; protected Activity _mActivity; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + _mActivity = this; Object content = getContentView(); //娣诲姞Activity鍒板爢鏍� @@ -43,6 +45,17 @@ 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); + } @@ -53,7 +66,7 @@ */ protected LoadingDialog getLoadingDialog() { if (loadingDialog == null && _mActivity != null) { - loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_AlertDialog); + loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_Dialog); } return loadingDialog; } @@ -95,9 +108,30 @@ 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