package com.kfzs.libs;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

/**
 * Created by guoxin on 2018/3/29.
 */

public abstract class DaggerActivity extends AppCompatActivity implements IDaggerMvp {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setupDaggerComponent();
        onAttachedView();
    }

    @Override
    protected void onDestroy() {
        onDetachedView();
        super.onDestroy();
    }

    @Override
    public void onAttachedView() {
        IPresenter presenter = currentPresenter();
        if (presenter != null) {
            presenter.attachedView(currentIView());
        }
    }

    @Override
    public void onDetachedView() {
        IPresenter presenter = currentPresenter();
        if (presenter != null) {
            presenter.detachedView();
        }
    }


    @Override
    public boolean isActive() {
        return currentIView() != null;
    }

    public abstract IPresenter currentPresenter();
    public abstract IView currentIView();

}
