wjc
2023-06-28 975b91521a04e159f45fb34fc7b55afbf455f7f5
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;
    }
    *//**
    /**
     * 开始Loading
     *//*
    public void showLoading() {
     */
    protected void showLoading() {
        getLoadingDialog().start();
    }
    *//**
    /**
     * 开始Loading
     *//*
    public void showDeviceLoading() {
        getDeviceLoadingDialog().start();
    }
    *//**
     * 开始Loading
     *//*
     *
     * @param mes 自定义文本
     */
    protected void showLoading(String mes) {
        getLoadingDialog().start();
        getLoadingDialog().setText(mes);
    }
    *//**
     * 开始Loading
     *//*
    protected void showGetDataLoading(String mes) {
        getLoadingGetDataDialog().startTouchNotGone();
        getLoadingGetDataDialog().setText(mes);
    }
    *//**
     * 开始Loading
     *//*
    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();