package com.thebluealliance.androidclient.fragments.event;

import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.thebluealliance.androidclient.R;
import com.thebluealliance.androidclient.adapters.ListViewAdapter;
import com.thebluealliance.androidclient.binders.DistrictPointsListBinder;
import com.thebluealliance.androidclient.fragments.DatafeedFragment;
import com.thebluealliance.androidclient.listitems.ListItem;
import com.thebluealliance.androidclient.models.NoDataViewParams;
import com.thebluealliance.androidclient.subscribers.DistrictPointsListSubscriber;
import com.thebluealliance.androidclient.views.NoDataView;

import java.util.List;

import rx.Observable;

public class EventDistrictPointsFragment
        extends DatafeedFragment<JsonElement, List<ListItem>, DistrictPointsListSubscriber, DistrictPointsListBinder> {
    private static final String KEY = "event_key";

    private String mEventKey;
    private Parcelable mListState;
    private ListViewAdapter mAdapter;

    private ListView mListView;

    public static EventDistrictPointsFragment newInstance(String eventKey) {
        EventDistrictPointsFragment f = new EventDistrictPointsFragment();
        Bundle data = new Bundle();
        data.putString(KEY, eventKey);
        f.setArguments(data);
        return f;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        if (getArguments() != null) {
            mEventKey = getArguments().getString(KEY, "");
        }
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
        mSubscriber.setEventKey(mEventKey);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.district_point_math, menu);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.list_view_with_spinner, null);
        mListView = (ListView) v.findViewById(R.id.list);
        ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.progress);
        TextView nonDistrictWarning = (TextView) v.findViewById(R.id.info_container);
        if (mAdapter != null) {
            mListView.setAdapter(mAdapter);
            mListView.onRestoreInstanceState(mListState);
            progressBar.setVisibility(View.GONE);
        }
        mBinder.listView = mListView;
        mBinder.progressBar = progressBar;
        mBinder.nonDistrictWarning = nonDistrictWarning;

        mBinder.setNoDataView((NoDataView) v.findViewById(R.id.no_data));

        //disable touch feedback (you can't click the elements here...)
        mListView.setCacheColorHint(getResources().getColor(android.R.color.transparent));
        mListView.setSelector(R.drawable.transparent);
        return v;
    }

    @Override
    public void onPause() {
        super.onPause();
        if (mListView != null) {
            mAdapter = (ListViewAdapter) mListView.getAdapter();
            mListState = mListView.onSaveInstanceState();
        }
    }

    @Override
    protected void inject() {
        mComponent.inject(this);
    }

    @Override
    protected Observable<JsonObject> getObservable(String tbaCacheHeader) {
        return mDatafeed.fetchEventDistrictPoints(mEventKey, tbaCacheHeader);
    }

    @Override
    protected String getRefreshTag() {
        return String.format("eventDistrictPoints_%1$s", mEventKey);
    }

    @Override
    protected NoDataViewParams getNoDataParams() {
        return new NoDataViewParams(R.drawable.ic_recent_actors_black_48dp, R.string.no_district_points);
    }
}

@@ -2285,16 +2285,48 @@
  null);%0A
+        mBinder.setRootView(v);%0A
         
@@ -2738,89 +2738,8 @@
   %7D%0A
-        mBinder.listView = mListView;%0A        mBinder.progressBar = progressBar;%0A
     

Integrate ButterKnife into DistrictPoints