package com.andrey7mel.testrx.view.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
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 android.widget.Button;
import android.widget.EditText;

import com.andrey7mel.testrx.R;
import com.andrey7mel.testrx.presenter.BasePresenterImpl;
import com.andrey7mel.testrx.presenter.RepoListPresenter;
import com.andrey7mel.testrx.presenter.vo.Repository;
import com.andrey7mel.testrx.view.ActivityCallback;
import com.andrey7mel.testrx.view.adapters.RepoListAdapterNew;

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

import butterknife.Bind;
import butterknife.ButterKnife;

public class RepoListFragment extends BaseFragment implements RepoListView {

    private RepoListPresenter presenter = new RepoListPresenter(this);

    @Bind(R.id.recycler_view)
    RecyclerView recyclerView;

    @Bind(R.id.edit_text)
    EditText editText;

    private RepoListPresenter presenter = new RepoListPresenter(this);
    @Bind(R.id.button_search)
    Button searchButton;
    private RepoListAdapterNew adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_repo_list, container, false);
        ButterKnife.bind(this, view);

        LinearLayoutManager llm = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(llm);
        adapter = new RepoListAdapterNew(new ArrayList<>(), presenter);
        recyclerView.setAdapter(adapter);

        searchButton.setOnClickListener(v -> presenter.onSearchButtonClick());

        presenter.onCreate(savedInstanceState);

        return view;
    }


    private void makeToast(String text) {
        Snackbar.make(recyclerView, text, Snackbar.LENGTH_LONG).show();
    }

    @Override
    protected BasePresenterImpl getPresenter() {
        return presenter;
    }


    @Override
    public void showError(Throwable e) {
        makeToast(e.getMessage());
    }

    @Override
    public void showRepoList(List<Repository> repoList) {
        adapter.setRepoList(repoList);
    }

    @Override
    public void startRepoInfoFragment(Repository repository) {
        ((ActivityCallback) getActivity()).startRepoInfoFragment(repository);
    }

    @Override
    public void showEmptyList() {
        makeToast(getActivity().getString(R.string.empty_list));
    }

    @Override
    public String getUserName() {
        return editText.getText().toString();
    }

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

}

@@ -924,80 +924,8 @@
  %7B%0A%0A
-    private RepoListPresenter presenter = new RepoListPresenter(this);%0A%0A
     
@@ -1031,16 +1031,70 @@
 itText;%0A
+    @Bind(R.id.button_search)%0A    Button searchButton;
 %0A    pri
@@ -1161,63 +1161,8 @@
 s);%0A
-    @Bind(R.id.button_search)%0A    Button searchButton;%0A
     

Version 2.1, fix code