wjc
2025-05-07 8814f3f0828e6ac652a29cc9de9f971fd55bca5b
app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java
@@ -3,11 +3,9 @@
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;
import android.view.WindowManager;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
@@ -20,7 +18,12 @@
import com.hdl.photovoltaic.listener.BaseView;
import com.hdl.photovoltaic.other.HdlThreadLogic;
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;
import java.util.Locale;
@@ -46,7 +49,7 @@
            view = inflater.inflate((int) getContentView(), container, false);
        } else if (getContentView() instanceof View) {
            view = (View) getContentView();
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            view.setLayoutParams(layoutParams);
        } else {
            view = null;
@@ -58,6 +61,7 @@
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        view.setClickable(true);
        view.postDelayed(new Runnable() {
            @Override
            public void run() {
@@ -90,7 +94,8 @@
    protected void onLazyInitView(Bundle savedInstanceState) {
        onBindView(savedInstanceState);
//        registerEventBus();
        //注册EventBus
        registerEventBus();
    }
@@ -101,26 +106,32 @@
        isFirst = true;
        //隐藏Loading
        hideLoading();
//        unregisterEventBus();
        //注销EventBus
        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)
//    public void onEventMessage(BaseEvent event) {
//
//    }
    /**
     * 收到EventBUs通知
     *
     * @param eventBus 数据
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMessage(BaseEventBus eventBus) {
    }
    /**
     * 显示View
@@ -164,7 +175,7 @@
     */
    protected LoadingDialog getLoadingDialog() {
        if (loadingDialog == null && _mActivity != null) {
            loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_AlertDialog);
            loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_Dialog);
        }
        return loadingDialog;
    }
@@ -173,6 +184,7 @@
     * 开始Loading
     */
    protected void showLoading() {
        getLoadingDialog().setText("");
        getLoadingDialog().start();
    }