package com.duben.microtribe.mvp.presenters;

import com.duben.microtribe.MintsApplication;
import com.duben.microtribe.mvp.views.BaseView;
import com.duben.microtribe.net.LoanService;

import rx.Subscription;

/**
 * 描述：BasePresenter
 * 作者：孟崔广
 * 时间：2018/1/10 17:51
 * 邮箱：mengcuiguang@cashbang.cn
 */
public class BasePresenter<V extends BaseView> implements Presenter<V> {

    protected MintsApplication loanApplication;
    protected LoanService loanService;

    protected V view;
    protected Subscription subscription;

    @Override
    public void attachView(V v) {
        view = v;
        loanApplication = view.getBaseApplication();
        loanService = loanApplication.getLoanService();
    }

    @Override
    public void detachView() {
        view = null;
        if (subscription != null && !subscription.isUnsubscribed()) {
            subscription.unsubscribe();
        }
    }

    /**
     * 判断view是否与activity关联
     *
     * @return true是未关联   false是关联
     */
    public boolean isLinkView() {
        return view == null;
    }
}
