2020-08-25 10:08:00 +08:00
|
|
|
|
package com.fenghoo.seven.test;
|
2020-08-14 15:12:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 日期:2017.01.03
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
* 作者:xudiwei
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
* 描述:所有MVP模式的Fragment的父类,处理了在MVP里有可能造成内存泄漏的可能
|
|
|
|
|
|
*/
|
|
|
|
|
|
public abstract class BaseMvpFragment<V, P extends BasePresenter<V>> extends BaseFragment {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "BaseMvpFragment";
|
|
|
|
|
|
protected P mPresenter;
|
|
|
|
|
|
|
|
|
|
|
|
public BaseMvpFragment() {
|
|
|
|
|
|
// Required empty public constructor
|
|
|
|
|
|
Log.d(TAG, "constructor");
|
|
|
|
|
|
mPresenter = createPresenter();
|
|
|
|
|
|
mPresenter.attach((V) this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onDestroy() {
|
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
|
mPresenter.detach();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 子类复写此方法,返回BasePresenter的子类
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected abstract P createPresenter();
|
|
|
|
|
|
|
|
|
|
|
|
}
|