package com.naijab.nextzytimeline.ui.people.detail;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.widget.TextView;

import com.naijab.nextzytimeline.R;
import com.naijab.nextzytimeline.base.BaseActivity;
import com.naijab.nextzytimeline.ui.people.detail.fragment.DetailPeopleFragment;

public class DetailPeopleActivity extends BaseActivity {

    private static final String ID_PEOPLE = "id";

    private Toolbar toolbar;
    private TextView toolbarTitle;
    private int id;

    @Override
    public int getLayoutView() {
        return R.layout.activity_detail;
    }

    @Override
    public void bindView() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_tv_title);
    }

    @Override
    public void setupInstance() {
        Intent intent = getIntent();
        id = intent.getIntExtra(ID_PEOPLE, 0);
    }

    @Override
    public void setupView() {
        setupToolbar();
        toolbarTitle.setText(getString(R.string.detail_people));
    }

    private void setupToolbar() {
        setSupportActionBar(toolbar);
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null) {
            actionbar.setDisplayHomeAsUpEnabled(true);
            actionbar.setDisplayShowHomeEnabled(true);
            actionbar.setDisplayShowTitleEnabled(false);
        }
    }

    @Override
    public void initialize() {
        setupFragment();
    }

    private void setupFragment() {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.container, DetailPeopleFragment.newInstance(id))
                .commit();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_edit_people, menu);
        return true;
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt(ID_PEOPLE, id);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        id = savedInstanceState.getInt(ID_PEOPLE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        
    }
}


@@ -97,20 +97,85 @@
 id.os.Bu
-ndle
+ild;%0Aimport android.os.Bundle;%0Aimport android.support.v4.app.Fragment
 ;%0Aimport
@@ -247,24 +247,49 @@
 et.Toolbar;%0A
+import android.util.Log;%0A
 import andro
@@ -646,16 +646,140 @@
  = %22id%22;
+%0A    private static final String TAG_FRAGMENT_DETAIL = %22DetailFragment%22;%0A    public static final int REQUEST_ID_PEOPLE = 19;
 %0A%0A    pr
@@ -1866,24 +1866,75 @@
 ragment() %7B%0A
+        Log.i(%22DetailActivity%22, %22Fragment born %22);%0A
         getS
@@ -1997,15 +1997,11 @@
    .
-replace
+add
 (R.i
@@ -2049,16 +2049,37 @@
 ance(id)
+, TAG_FRAGMENT_DETAIL
 )%0A      
@@ -2834,24 +2834,25 @@
  data);%0A
+%0A
         
 %0A    %7D%0A%7D
@@ -2843,16 +2843,479 @@
         
+if (Build.VERSION.SDK_INT %3C Build.VERSION_CODES.JELLY_BEAN_MR2) %7B%0A            if (requestCode == REQUEST_ID_PEOPLE && resultCode == RESULT_OK) %7B%0A                id = data.getIntExtra(ID_PEOPLE, 0);%0A                Log.i(%22IDActivity%22, %22onActivityResult: %22 + id);%0A                Fragment fragment = getSupportFragmentManager().findFragmentByTag(TAG_FRAGMENT_DETAIL);%0A                fragment.onActivityResult(requestCode, resultCode, data);%0A            %7D%0A        %7D
 %0A    %7D%0A%7D

Add if check build version SDK < 18