mac
2023-11-03 9e875b253959eff8f6af567308ad804fe69d0a62
app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java
@@ -8,12 +8,21 @@
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,15 +41,83 @@
            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;
    }
    /**
     * 开始Loading
     */
    protected void showLoading() {
        getLoadingDialog().start();
    }
    /**
     * 开始Loading
     *
     * @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();
        //移除Activity
        AppManagerUtils.getAppManager().removeActivity(this);
    }
    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
@@ -67,7 +144,7 @@
    /**
     * 简单的跳转Activity
     *
     * @param clazz
     * @param clazz _
     */
    protected void startActivity(Class<?> clazz) {
        Intent intent = new Intent(this, clazz);