From 48bd94f4e362c8a604017cbaf4c12e08be10c816 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期五, 10 五月 2024 17:25:37 +0800
Subject: [PATCH] 2024年05月10日17:25:30

---
 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 e49c4ff..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,6 +1,7 @@
 package com.hdl.photovoltaic.base;
 
 import android.app.Activity;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
@@ -8,13 +9,25 @@
 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) {
@@ -32,15 +45,92 @@
             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
@@ -67,7 +157,7 @@
     /**
      * 绠�鍗曠殑璺宠浆Activity
      *
-     * @param clazz
+     * @param clazz _
      */
     protected void startActivity(Class<?> clazz) {
         Intent intent = new Intent(this, clazz);

--
Gitblit v1.8.0