package com.example.app;

import android.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.example.app.api.Event;
import com.example.app.api.EventsResponse;
import com.example.app.api.GitHubRequest;
import com.example.app.api.GitHubRequestManager;

/**
 * Created by andy on 3/12/14.
 */
public class EventListFragment extends ListFragment implements Response.Listener<EventsResponse>, Response.ErrorListener {

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        requestEvents();
    }

    private void requestEvents() {
        getActivity().setProgressBarIndeterminateVisibility(true);
        GitHubRequest<EventsResponse> request = GitHubRequestManager.getEventRequest(this, this, "chaione");
        request.setTag(this);
        GithubEventsApp.getRequestQueue().add(request);
    }

    @Override
    public void onResponse(EventsResponse response) {
        getActivity().setProgressBarIndeterminateVisibility(false);
        setListShown(true);
        ArrayAdapter<Event> adapter = new ArrayAdapter<Event>(getActivity(),
                android.R.layout.simple_list_item_1, android.R.id.text1, response);
        getListView().setAdapter(adapter);
    }

    @Override
    public void onErrorResponse(VolleyError volleyError) {
        getActivity().setProgressBarIndeterminateVisibility(false);
        Toast.makeText(getActivity(), R.string.unable_to_fech_events, Toast.LENGTH_SHORT).show();
    }
}

@@ -71,43 +71,142 @@
 oid.
-os.Bundle;%0Aimport android.view.View
+content.Context;%0Aimport android.os.Bundle;%0Aimport android.view.LayoutInflater;%0Aimport android.view.View;%0Aimport android.view.ViewGroup
 ;%0Aim
@@ -235,24 +235,56 @@
 rayAdapter;%0A
+import android.widget.TextView;%0A
 import andro
@@ -545,16 +545,40 @@
 nager;%0A%0A
+import java.util.List;%0A%0A
 /**%0A * C
@@ -1324,35 +1324,29 @@
         
-Array
+Events
 Adapter
-%3CEvent%3E
  adapter
@@ -1356,27 +1356,21 @@
 new 
-Array
+Events
 Adapter
-%3CEvent%3E
 (get
@@ -1435,29 +1435,9 @@
 tem_
-1, android.R.id.text1
+2
 , re
@@ -1739,11 +1739,914 @@
 );%0A    %7D
+%0A%0A    private class EventsAdapter extends ArrayAdapter%3CEvent%3E %7B%0A%0A        public EventsAdapter(Context context, int resource, List%3CEvent%3E objects) %7B%0A            super(context, resource, objects);%0A        %7D%0A%0A        @Override%0A        public View getView(int position, View convertView, ViewGroup parent) %7B%0A            if(convertView == null) %7B%0A                convertView = LayoutInflater.from(getContext())%0A                        .inflate(android.R.layout.simple_list_item_2, parent, false);%0A            %7D%0A%0A            Event event = getItem(position);%0A            String line1 = String.format(%22%25s by %25s%22, event.getType(), event.getActor().getLogin());%0A            TextView.class.cast(convertView.findViewById(android.R.id.text1)).setText(line1);%0A            TextView.class.cast(convertView.findViewById(android.R.id.text2)).setText(event.getCreatedAt());%0A%0A            return convertView;%0A        %7D%0A    %7D
 %0A%7D%0A

Add custom adapter for events list.