package com.nilhcem.droidcontn.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import butterknife.ButterKnife;

public abstract class BaseActivity<P extends BaseActivityPresenter> extends AppCompatActivity {

    protected P presenter;

    protected abstract P newPresenter();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        presenter = newPresenter();
    }

    @Override
    protected void onPostCreate(@Nullable Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        presenter.onPostCreate(savedInstanceState);
    }

    @Override
    protected void onResume() {
        super.onResume();
        presenter.onResume();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        presenter.onSaveInstanceState(outState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        presenter.onRestoreInstanceState(savedInstanceState);
    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);
        ButterKnife.bind(this);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                Intent upIntent = NavUtils.getParentActivityIntent(this);
                if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                    NavUtils.navigateUpFromSameTask(this);
                } else {
                    onBackPressed();
                }
                NavUtils.navigateUpFromSameTask(this);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        if (presenter.onBackPressed()) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    protected void onDestroy() {
        presenter = null;
        super.onDestroy();
    }
}

@@ -1590,14 +1590,10 @@
     
-switch
+if
  (it
@@ -1610,28 +1610,11 @@
 Id()
-) %7B%0A            case
+ ==
  and
@@ -1631,11 +1631,12 @@
 home
-:%0A 
+) %7B%0A
     
@@ -1643,19 +1643,16 @@
         
-   
 Intent u
@@ -1709,28 +1709,24 @@
             
-    
 if (NavUtils
@@ -1774,36 +1774,32 @@
                 
- 
-   
 NavUtils.navigat
@@ -1833,20 +1833,16 @@
         
-    
 %7D else %7B
@@ -1858,20 +1858,16 @@
         
- 
-   
 onBackPr
@@ -1883,34 +1883,26 @@
             
-    %7D%0A    
+%7D%0A
             
@@ -1932,36 +1932,32 @@
 SameTask(this);%0A
-    
             retu

Replace switch statement by 'if' statement to increase readability