package com.smartalk.gank.ui.base;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;

import com.smartalk.gank.presenter.BasePresenter;
import com.umeng.analytics.MobclickAgent;

import butterknife.ButterKnife;

/**
 * 基础Activity
 * Created by panl on 15/12/24.
 */
public abstract class BaseActivity<T extends BasePresenter> extends AppCompatActivity {

  protected String TAG = this.getClass().getSimpleName();
  protected T presenter;


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(provideContentViewId());
    ButterKnife.bind(this);
    initPresenter();
    Log.i(TAG, "onCreate");
  }

  protected abstract int provideContentViewId();

  protected abstract void initPresenter();


  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        onBackPressed();
        break;
    }
    return super.onOptionsItemSelected(item);
  }

  @Override
  protected void onRestart() {
    super.onRestart();
    Log.i(TAG, "onRestart");

  }

  @Override
  protected void onStart() {
    super.onStart();
    Log.i(TAG, "onStart");

  }

  @Override
  protected void onResume() {
    super.onResume();
    MobclickAgent.onResume(this);
    Log.i(TAG, "onResume");

  }

  @Override
  protected void onPause() {
    super.onPause();
    MobclickAgent.onPause(this);
    Log.i(TAG, "onPause");

  }

  @Override
  protected void onStop() {
    super.onStop();
    Log.i(TAG, "onStop");

  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    ButterKnife.unbind(this);
    Log.i(TAG, "onDestroy");

  }
}
