From b8209d15d915f72d9abe3a68b76e1f4cfd21eac3 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期六, 23 九月 2023 14:37:00 +0800
Subject: [PATCH] 2023年09月23日14:36:51
---
app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java | 76 +++++++++++++++++++++++++++++++++++++
1 files changed, 75 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..e3b1d84 100644
--- a/app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java
+++ b/app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java
@@ -3,18 +3,26 @@
import android.app.Activity;
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.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
@@ -32,16 +40,82 @@
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
*
--
Gitblit v1.8.0