package com.turlir.abakgists.notes;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.turlir.abakgists.base.App;
import com.turlir.abakgists.GistActivity;
import com.turlir.abakgists.base.OnClickListener;
import com.turlir.abakgists.R;
import com.turlir.abakgists.base.SpaceDecorator;
import com.turlir.abakgists.allgists.AllGistAdapter;
import com.turlir.abakgists.base.BaseFragment;
import com.turlir.abakgists.model.Gist;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

public class NotesFragment extends BaseFragment implements OnClickListener {

    @Inject
    NotesPresenter _presenter;

    @BindView(R.id.recycler)
    RecyclerView recycler;

    private AllGistAdapter mAdapter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        App.getComponent().inject(this);
        _presenter.attach(this);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_all_gists, container, false);
        butterKnifeBind(root);

        mAdapter = new AllGistAdapter(getContext(), this);
        recycler.setAdapter(mAdapter);
        RecyclerView.LayoutManager lm
                = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        recycler.setLayoutManager(lm);

        DividerItemDecoration divider =
                new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
        recycler.addItemDecoration(divider);
        recycler.addItemDecoration(new SpaceDecorator(getActivity(), R.dimen.item_offset));

        return root;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        _presenter.loadNotes();
    }

    @Override
    public void onDetach() {
        super.onDetach();
        _presenter.detach();
    }

    @Override
    public void onListItemClick(int position) {
        Gist item = mAdapter.getItemByPosition(position);
        Intent i = GistActivity.getStartIntent(getContext(), item);
        startActivity(i);
    }

    @Override
    public String toString() {
        return "Notes";
    }

    void onNotesLoaded(List<Gist> gistDiff) {
        mAdapter.addGist(gistDiff, mAdapter.getItemCount(), gistDiff.size());
    }

    void onNotesDeleted() {
        mAdapter.removeLastGist();
    }

}

@@ -127,24 +127,77 @@
 n.Nullable;%0A
+import android.support.v4.widget.SwipeRefreshLayout;%0A
 import andro
@@ -1401,16 +1401,45 @@
 ntainer,
+%0A                            
  @Nullab
@@ -1449,37 +1449,24 @@
 Bundle saved
-InstanceState
 ) %7B%0A        
@@ -1534,32 +1534,86 @@
 tainer, false);%0A
+        root.setEnabled(false); // SwipeRefreshLayout%0A
         butterKn

disable swipe to refresh on NotesFragment