package com.naijab.nextzytimeline.ui.main.home;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import com.naijab.nextzytimeline.R;
import com.naijab.nextzytimeline.base.BaseMvpFragment;
import com.naijab.nextzytimeline.ui.main.home.adapter.PeopleAdapter;
import com.naijab.nextzytimeline.ui.people.model.PeopleManager;
import com.naijab.nextzytimeline.ui.people.model.PeopleModel;

import java.util.ArrayList;
import java.util.List;

import io.realm.Realm;
import io.realm.RealmResults;

public class HomeFragment extends BaseMvpFragment<HomeFragmentInterface.Presenter>
        implements HomeFragmentInterface.View{

    private RecyclerView recyclerView;
    private RealmResults<PeopleModel> realmResults;
    private Realm realm;
    private List<PeopleModel> peopleItem;
    private PeopleAdapter adapter;

    public HomeFragment() {
        super();
    }

    public static HomeFragment newInstance() {
        HomeFragment fragment = new HomeFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public HomeFragmentInterface.Presenter createPresenter(){
        return HomeFragmentPresenter.create();
    }

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

    @Override
    public void bindView( View view ){
        recyclerView = (RecyclerView) view.findViewById(R.id.recycler_people);
    }

    @Override
    public void setupInstance(){
        realm = Realm.getDefaultInstance();
        realmResults = PeopleManager.getInstance().getPeople();
        peopleItem = new ArrayList<>();
        peopleItem.addAll(realmResults.subList(0, realmResults.size()));
        adapter = new PeopleAdapter(getActivity(), peopleItem);
        LinearLayoutManager llm = new LinearLayoutManager(getActivity());
        llm.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(llm);
        recyclerView.setAdapter(adapter);
//        for (int i = 0; i < realmResults.size(); i++) {
//            PeopleModel items = new PeopleModel();
//            items.setId(PeopleManager.getInstance().getPeople().get(i).getId());
//            items.setName(PeopleManager.getInstance().getPeople().get(i).getName());
//        }
    }

    @Override
    public void setupView(){

    }

    @Override
    public void initialize(){

    }

    @Override
    public void restoreView( Bundle savedInstanceState ){

    }

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

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


@@ -191,24 +191,54 @@
 .view.View;%0A
+import android.widget.Toast;%0A%0A
 import com.n
@@ -643,16 +643,24 @@
 Fragment
+%0A       
  extends
@@ -754,16 +754,17 @@
 ace.View
+ 
 %7B%0A%0A    p
@@ -1282,16 +1282,17 @@
 senter()
+ 
 %7B%0A      
@@ -1383,16 +1383,17 @@
 utView()
+ 
 %7B%0A      
@@ -1471,17 +1471,16 @@
 indView(
- 
 View vie
@@ -1480,18 +1480,18 @@
 iew view
- 
 )
+ 
 %7B%0A      
@@ -1615,16 +1615,558 @@
 stance()
+ %7B%0A        setupRealm();%0A    %7D%0A%0A    @Override%0A    public void setupView() %7B%0A        setupRecyclerView();%0A    %7D%0A%0A    @Override%0A    public void initialize() %7B%0A%0A    %7D%0A%0A    @Override%0A    public void restoreView(Bundle savedInstanceState) %7B%0A%0A    %7D%0A%0A    @Override%0A    public void onSaveInstanceState(Bundle outState) %7B%0A        super.onSaveInstanceState(outState);%0A    %7D%0A%0A    @Override%0A    public void onRestoreInstanceState(Bundle savedInstanceState) %7B%0A        super.onRestoreInstanceState(savedInstanceState);%0A    %7D%0A%0A    private void setupRealm() 
 %7B%0A      
@@ -2376,24 +2376,70 @@
 s.size()));%0A
+    %7D%0A%0A    private void setupRecyclerView() %7B%0A
         adap
@@ -2519,18 +2519,28 @@
 anager l
-lm
+ayoutManager
  = new L
@@ -2583,18 +2583,28 @@
        l
-lm
+ayoutManager
 .setOrie
@@ -2681,18 +2681,28 @@
 anager(l
-lm
+ayoutManager
 );%0A     
@@ -2738,26 +2738,24 @@
 apter);%0A
-//
         
 for (int
@@ -2750,745 +2750,376 @@
     
-for (int i = 0; i %3C realmResults.size(); i++) %7B%0A//            PeopleModel items = new PeopleModel();%0A//            items.setId(PeopleManager.getInstance().getPeople().get(i).getId());%0A//            items.setName(PeopleManager.getInstance().getPeople().get(i).getName());%0A//        %7D%0A    %7D%0A%0A    @Override%0A    public void setupView()%7B%0A%0A    %7D%0A%0A    @Override%0A    public void initialize()%7B%0A%0A    %7D%0A%0A    @Override%0A    public void restoreView( Bundle savedInstanceState )%7B%0A%0A
+onClick();%0A    %7D%0A%0A    private void onClick() %7B%0A        adapter.setOnClickPeopleItem(new PeopleAdapter.OnAdapterListener() %7B%0A            @Override%0A            public void onClickAdapter(List%3CPeopleModel%3E item, int position) %7B%0A  
     
-%7D%0A%0A
     
-@Override%0A    public void onSaveInstanceState( Bundle outState )%7B%0A        super.onSaveInstanceState( outState 
+      Toast.makeText(getActivity(), %22%22 + item.get(position).getName() + position, Toast.LENGTH_SHORT).show(
 );%0A    
-%7D%0A%0A
     
-@Override%0A    public void onRestoreInstanceState( Bundle savedInstanceState )%7B%0A        super.onRestoreInstanceState( savedInstanceState 
+    %7D%0A        %7D
 );%0A 
@@ -3123,11 +3123,13 @@
 ;%0A    %7D%0A
+%0A%0A
 %7D%0A%0A

Add on click listener recycler view