package com.sipai.jspatrol.Base;

import java.lang.ref.WeakReference;

/**
 * created by lvliming on 2020/3/23
 */
public abstract class BaseFragmentPresenter<V extends BaseFragmentView,M extends BaseFragmentModel,CONTRACT> {
    protected M m;

    //绑定View层弱引用
    private WeakReference<V> vWeakReference;

    public BaseFragmentPresenter() {
        m = getModel();
    }

    public void bindView(V v) {
        vWeakReference = new WeakReference<>(v);
    }

    public void unBindView(){
        if (vWeakReference!=null){
            vWeakReference.clear();
            vWeakReference = null;
            System.gc();
        }
    }

    public V getView(){
        if (vWeakReference!=null){
            return vWeakReference.get();
        }
        return null;
    }

    public abstract CONTRACT getContract();

    public abstract M getModel();
}
