From 07ccc78892b26dabc976363c874c177230f9bbcb Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期三, 07 六月 2023 21:26:57 +0800 Subject: [PATCH] 2023年06月07日21:26:48 --- app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java | 143 +++++++++++++---------------------------------- 1 files changed, 40 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..1cd2301 100644 --- a/app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java +++ b/app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -15,9 +16,11 @@ import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.Lifecycle; +import com.hdl.photovoltaic.R; import com.hdl.photovoltaic.listener.BaseView; +import com.hdl.photovoltaic.other.HdlThreadLogic; +import com.hdl.photovoltaic.widget.LoadingDialog; -import org.greenrobot.eventbus.EventBus; import java.util.Locale; @@ -26,15 +29,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 @@ -97,20 +99,22 @@ super.onDestroyView(); _mActivity = null; isFirst = true; + //闅愯棌Loading + hideLoading(); // unregisterEventBus(); } protected void unregisterEventBus() { - if (EventBus.getDefault().isRegistered(this)) { - EventBus.getDefault().unregister(this); - } +// if (EventBus.getDefault().isRegistered(this)) { +// EventBus.getDefault().unregister(this); +// } } protected void registerEventBus() { - if (!EventBus.getDefault().isRegistered(this)) { - EventBus.getDefault().register(this); - } +// if (!EventBus.getDefault().isRegistered(this)) { +// EventBus.getDefault().register(this); +// } } // @Subscribe(threadMode = ThreadMode.MAIN) @@ -121,7 +125,7 @@ /** * 鏄剧ずView * - * @param view + * @param view - */ public void setViewVisible(View view) { if (view.getVisibility() != View.VISIBLE && _mActivity != null) { @@ -132,7 +136,7 @@ /** * 闅愯棌View * - * @param view + * @param view - */ protected void setViewGone(View view) { if (view.getVisibility() != View.GONE && _mActivity != null) { @@ -143,7 +147,7 @@ /** * 绠�鍗曠殑璺宠浆Activity * - * @param clazz + * @param clazz - */ protected void startActivity(Class<?> clazz) { if (_mActivity != null) { @@ -152,118 +156,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_AlertDialog); } 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