WEFragment.java 1.1 KB
Newer Older
J
jessyan 已提交
1 2 3 4
package me.jessyan.mvparms.demo.mvp.ui.common;

import com.jess.arms.base.BaseFragment;
import com.jess.arms.mvp.BasePresenter;
J
jessyan 已提交
5
import com.squareup.leakcanary.RefWatcher;
J
jessyan 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

import me.jessyan.mvparms.demo.app.WEApplication;
import me.jessyan.mvparms.demo.di.component.AppComponent;

/**
 * Created by jess on 8/5/16 14:11
 * contact with jess.yan.effort@gmail.com
 */
public abstract class WEFragment<P extends BasePresenter> extends BaseFragment<P> {
    protected WEApplication mWeApplication;
    @Override
    protected void ComponentInject() {
        mWeApplication = (WEApplication)mActivity.getApplication();
        setupFragmentComponent(mWeApplication.getAppComponent());
    }

J
jessyan 已提交
22
    //提供AppComponent(提供所有的单例对象)给子类,进行Component依赖
J
jessyan 已提交
23
    protected abstract void setupFragmentComponent(AppComponent appComponent);
J
jessyan 已提交
24 25 26 27

    @Override
    public void onDestroy() {
        super.onDestroy();
J
jessyan 已提交
28
        RefWatcher watcher = WEApplication.getRefWatcher(getActivity());//使用leakCanary检测fragment的内存泄漏
J
jessyan 已提交
29 30 31
        if (watcher != null) {
            watcher.watch(this);
        }
J
jessyan 已提交
32
        this.mWeApplication =null;
J
jessyan 已提交
33
    }
J
jessyan 已提交
34
}