package com.cooleshow.base.ui.activity;

import com.cooleshow.base.presenter.BasePresenter;

import androidx.viewbinding.ViewBinding;

public abstract class BaseMVPActivity<V extends ViewBinding, P extends BasePresenter> extends BaseActivity<V> {
    protected P presenter;

    @Override
    public void initData() {
        super.initData();
        presenter = createPresenter();
        // presenter 绑定 view
        if (presenter != null) {
            presenter.attachView(this);
        }
    }

    protected abstract P createPresenter();

    @Override
    public void onDestroy() {
        super.onDestroy();
        // Activity 销毁时取消所有的订阅
        if (presenter != null) {
            presenter.detachView();
            presenter = null;
        }
    }

}
