From 975b91521a04e159f45fb34fc7b55afbf455f7f5 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 28 六月 2023 16:53:34 +0800
Subject: [PATCH] 2023年06月28日16:53:33

---
 app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java |  148 +++++++++++++++----------------------------------
 1 files changed, 45 insertions(+), 103 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java b/app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java
index 8854588..82120dc 100644
--- a/app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java
+++ b/app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java
@@ -6,7 +6,6 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.WindowManager;
 import android.widget.FrameLayout;
 
 import androidx.annotation.NonNull;
@@ -15,9 +14,16 @@
 import androidx.fragment.app.FragmentActivity;
 import androidx.lifecycle.Lifecycle;
 
+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.widget.LoadingDialog;
+
 
 import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
 
 import java.util.Locale;
 
@@ -26,15 +32,14 @@
     private boolean isFirst = true;
     protected FragmentActivity _mActivity;
     protected View mContainerView;
-//    private LoadingDialog loadingDialog;
-//    private LoadingDialog loadingGetDataDialog;
-//    private DeviceLoadingDialog deviceLoadingDialog;
+    private LoadingDialog loadingDialog;
 
     @Override
     public void onAttach(@NonNull Context context) {
         super.onAttach(context);
         _mActivity = getActivity();
     }
+
 
     @Nullable
     @Override
@@ -88,7 +93,8 @@
 
     protected void onLazyInitView(Bundle savedInstanceState) {
         onBindView(savedInstanceState);
-//        registerEventBus();
+        //娉ㄥ唽EventBus
+        registerEventBus();
     }
 
 
@@ -97,7 +103,10 @@
         super.onDestroyView();
         _mActivity = null;
         isFirst = true;
-//        unregisterEventBus();
+        //闅愯棌Loading
+        hideLoading();
+        //娉ㄩ攢EventBus
+        unregisterEventBus();
     }
 
 
@@ -113,15 +122,15 @@
         }
     }
 
-//    @Subscribe(threadMode = ThreadMode.MAIN)
-//    public void onEventMessage(BaseEvent event) {
-//
-//    }
+    @Subscribe(threadMode = ThreadMode.MAIN)
+    public void onEventMessage(BaseEventBus eventBus) {
+
+    }
 
     /**
      * 鏄剧ずView
      *
-     * @param view
+     * @param view -
      */
     public void setViewVisible(View view) {
         if (view.getVisibility() != View.VISIBLE && _mActivity != null) {
@@ -132,7 +141,7 @@
     /**
      * 闅愯棌View
      *
-     * @param view
+     * @param view -
      */
     protected void setViewGone(View view) {
         if (view.getVisibility() != View.GONE && _mActivity != null) {
@@ -143,7 +152,7 @@
     /**
      * 绠�鍗曠殑璺宠浆Activity
      *
-     * @param clazz
+     * @param clazz -
      */
     protected void startActivity(Class<?> clazz) {
         if (_mActivity != null) {
@@ -152,118 +161,51 @@
         }
     }
 
-    /* *//**
+
+    /**
      * 鑾峰彇LoadingDialog
      *
-     * @return
-     *//*
+     * @return LoadingDialog
+     */
     protected LoadingDialog getLoadingDialog() {
         if (loadingDialog == null && _mActivity != null) {
-            loadingDialog = new LoadingDialog(_mActivity, R.style.loading_dialog);
+            loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_Dialog);
         }
         return loadingDialog;
     }
 
-    public LoadingDialog getLoadingGetDataDialog() {
-        if (loadingGetDataDialog == null && _mActivity != null) {
-            loadingGetDataDialog = new LoadingDialog(_mActivity, R.style.loading_dialog);
-        }
-        return loadingGetDataDialog;
-    }
-
-
-    *//**
-     * 鑾峰彇DeviceLoadingDialog
-     *
-     * @return
-     *//*
-    protected DeviceLoadingDialog getDeviceLoadingDialog() {
-        if (deviceLoadingDialog == null && _mActivity != null) {
-            deviceLoadingDialog = new DeviceLoadingDialog(_mActivity, R.style.loading_dialog);
-        }
-        return deviceLoadingDialog;
-    }
-
-    *//**
+    /**
      * 寮�濮婰oading
-     *//*
-    public void showLoading() {
+     */
+    protected void showLoading() {
         getLoadingDialog().start();
     }
 
-    *//**
+    /**
      * 寮�濮婰oading
-     *//*
-    public void showDeviceLoading() {
-        getDeviceLoadingDialog().start();
-    }
-
-
-    *//**
-     * 寮�濮婰oading
-     *//*
+     *
+     * @param mes 鑷畾涔夋枃鏈�
+     */
     protected void showLoading(String mes) {
         getLoadingDialog().start();
         getLoadingDialog().setText(mes);
     }
 
-
-    *//**
-     * 寮�濮婰oading
-     *//*
-    protected void showGetDataLoading(String mes) {
-        getLoadingGetDataDialog().startTouchNotGone();
-        getLoadingGetDataDialog().setText(mes);
-    }
-
-
-    *//**
-     * 寮�濮婰oading
-     *//*
-    protected void showDeviceLoading(String mes) {
-        getDeviceLoadingDialog().start();
-        getDeviceLoadingDialog().setText(mes);
-    }
-
-    *//**
-     * 鍋滄闅愯棌Loading
-     *//*
-    protected void hideLoading() {
-        if (loadingDialog != null && loadingDialog.isShowing()) {
-            loadingDialog.stop();
-        }
-    }
-
-    *//**
-     * 鍋滄闅愯棌Loading
-     *//*
-    protected void hideGetDataLoading() {
-        if (loadingGetDataDialog != null && loadingGetDataDialog.isShowing()) {
-            loadingGetDataDialog.stop();
-        }
-    }
-
-    */
-
     /**
      * 鍋滄闅愯棌Loading
-     *//*
-    protected void hideDeviceLoading() {
-        if (deviceLoadingDialog != null && deviceLoadingDialog.isShowing()) {
-            deviceLoadingDialog.stop();
-        }
-    }*/
-
-    //鐢ㄤ簬popwindow鏄剧ず闅愯棌鏃跺�欒儗鏅殑棰滆壊鏇存崲
-    protected void backgroundAlpha(float bgAlpha) {
-        if (_mActivity != null) {
-            WindowManager.LayoutParams lp = _mActivity.getWindow().getAttributes();
-            _mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
-            lp.alpha = bgAlpha; //0.0-1.0
-            _mActivity.getWindow().setAttributes(lp);
-        }
+     */
+    protected void hideLoading() {
+        HdlThreadLogic.runMainThread(new Runnable() {
+            @Override
+            public void run() {
+                if (loadingDialog != null && loadingDialog.isShowing()) {
+                    loadingDialog.stop();
+                }
+            }
+        }, null, null);
     }
 
+
     public static boolean isZh(Context context) {
         Locale locale = context.getResources().getConfiguration().locale;
         String language = locale.getLanguage();

--
Gitblit v1.8.0