package pl.vehicle_history.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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 pl.vehicle_history.Search;
import pl.vehicle_history.activity.MainActivity;
import pl.vehicle_history.adapter.HistoryAdapter;
import pl.vehicle_history.adapter.HistoryAdapter.OnHistoryItemClickListener;
import pl.vehicle_history.database.SearchHistoryDb;
import pl.vehicle_history.historiapojazdu.R;

/**
 * @author Piotr Makowski (<a href=\"mailto:Piotr.Makowski@allegrogroup.pl\">Piotr.Makowski@allegrogroup.pl</a>)
 */
public class SearchHistoryFragment extends Fragment implements OnHistoryItemClickListener {

    private static final String ARG_SECTION_NUMBER = "section_number";

    public static SearchHistoryFragment newInstance(int sectionNumber) {
        SearchHistoryFragment fragment = new SearchHistoryFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }

    public SearchHistoryFragment() {
        //nop
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_search_history, container, false);

        setupRecyclerView(rootView);

        return rootView;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        ((MainActivity) activity).onSectionAttached(getArguments().getInt(ARG_SECTION_NUMBER));
    }

    @Override
    public void onHistoryItemClick(Search search) {
        //TODO implement me
    }

    private void setupRecyclerView(View rootView) {
        RecyclerView recycler = (RecyclerView) rootView.findViewById(R.id.history_recycler);

        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recycler.setLayoutManager(layoutManager);

        HistoryAdapter historyAdapter = new HistoryAdapter(new SearchHistoryDb(getActivity()), this);
        recycler.setAdapter(historyAdapter);
    }
}

@@ -321,16 +321,139 @@
 Group;%0A%0A
+import pl.vehicle_history.PerformSearchDelegate;%0Aimport pl.vehicle_history.PerformSearchDelegate.OnSearchFinishedListener;%0A
 import p
@@ -1958,27 +1958,362 @@
     
-//TODO implement me
+new PerformSearchDelegate(getActivity()).performSearch(search, new OnSearchFinishedListener() %7B%0A%0A            @Override%0A            public void onSearchFinished() %7B%0A                //TODO implement me%0A            %7D%0A%0A            @Override%0A            public void onSearchError(String message) %7B%0A                //TODO implement me%0A            %7D%0A        %7D);
 %0A   

Use PerformSearchDelegate in SearchHistoryFragment.