<commit_before>package com.localhop.swipe.eventlist;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SearchView;

import com.localhop.activities.event.ActivityEventSelection;
import com.localhop.network.HttpRequest;
import com.localhop.network.HttpServerRequest;
import com.localhop.objects.Event;
import com.localhop.R;
import com.localhop.utils.ViewUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Date;

/**
 * Controls the custom Swipe View on the Events List tab.  The user will be given the ability
 * to swipe between Past, Today, and Future events.
 */
public class EventListSwipe extends Fragment {

    private int mCurrentPage;                  //< The current view of the swipe tabs
    private ArrayList<Event> mEvents;          //< All events associated to a user (Past, Today, and Future)
    private View mEventListView;               //< The event list view for the swipe view
    private SwipeRefreshLayout mRefreshLayout; // Swipe to refresh the events, ooooh, aaaah...

    @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Getting the arguments to the Bundle object
        Bundle data = getArguments();

        // Getting integer data of the key current_page from the bundle
        mCurrentPage = data.getInt("current_page", 0);

    } // end of function onCreate()

    @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        // Create the view for the event list items to be returned
        mEventListView = inflater.inflate(R.layout.tab_event_list_view, container, false);
        mRefreshLayout = ViewUtils.findViewById(mEventListView, R.id.srl_events);

        // Get all events for a user and split them up based on type of event?
        getAllUserEvents();

        return mEventListView;
    } // end of function onCreateView()

    /**
     * Retrieves all events associated to a user from the DB
     */
    private void getAllUserEvents() {

        // TODO: Extract this query into its own class of queries
        // TODO: Note, onPostExecute may run into issues. Be Creative (:
            new HttpServerRequest<Activity, ArrayList<Event>>(getActivity(), HttpRequest.GET) {

                @Override protected ArrayList<Event> onResponse(final String response) {
                    try {
                        final JSONArray arr = new JSONObject(response).getJSONArray("text");

                        ArrayList<Event> events = new ArrayList<Event>();
                        for (int i = 0; i < arr.length(); ++i) {
                            final JSONObject obj = arr.getJSONObject(i);
                            events.add(Event.fromJSON(obj));
                        }

                        return events;
                    } catch (JSONException e) {
                        e.printStackTrace();
                        return null; // TODO: null voodoo
                    }
                }

                @Override protected void onPostExecute(ArrayList<Event> events) {
                    super.onPostExecute(events);
                    setEvents(events);
                    layoutFragment();
                    mRefreshLayout.setRefreshing(false);
                }

            }.execute("http://2172.16.58.3/get/user/events/2");

    } // end of function getAllUserEvents()


    /**
     * Layouts the view for the fragment
     */
    public void layoutFragment() {

        if( mEvents != null )
        {
            // Split up the events based on Event Type (i.e. Past, Today, or Future)
            ArrayList<Event> pastEvents = new ArrayList<Event>();
            ArrayList<Event> todayEvents = new ArrayList<Event>();
            ArrayList<Event> futureEvents = new ArrayList<Event>();
            Event tempEvent;
            for(int i = 0; i < mEvents.size(); i++)
            {
                tempEvent = mEvents.get(i);
                if( tempEvent.getType() == Event.EventType.Past )
                {
                    pastEvents.add(tempEvent);
                }<commit_msg>Dismiss refresh icon when error occurs<commit_after>package com.localhop.swipe.eventlist;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SearchView;

import com.localhop.activities.event.ActivityEventSelection;
import com.localhop.network.HttpRequest;
import com.localhop.network.HttpServerRequest;
import com.localhop.objects.Event;
import com.localhop.R;
import com.localhop.utils.ViewUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Date;

/**
 * Controls the custom Swipe View on the Events List tab.  The user will be given the ability
 * to swipe between Past, Today, and Future events.
 */
public class EventListSwipe extends Fragment {

    private int mCurrentPage;                  //< The current view of the swipe tabs
    private ArrayList<Event> mEvents;          //< All events associated to a user (Past, Today, and Future)
    private View mEventListView;               //< The event list view for the swipe view
    private SwipeRefreshLayout mRefreshLayout; // Swipe to refresh the events, ooooh, aaaah...

    @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Getting the arguments to the Bundle object
        Bundle data = getArguments();

        // Getting integer data of the key current_page from the bundle
        mCurrentPage = data.getInt("current_page", 0);

    } // end of function onCreate()

    @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        // Create the view for the event list items to be returned
        mEventListView = inflater.inflate(R.layout.tab_event_list_view, container, false);
        mRefreshLayout = ViewUtils.findViewById(mEventListView, R.id.srl_events);

        // Get all events for a user and split them up based on type of event?
        getAllUserEvents();

        return mEventListView;
    } // end of function onCreateView()

    /**
     * Retrieves all events associated to a user from the DB
     */
    private void getAllUserEvents() {

        // TODO: Extract this query into its own class of queries
        // TODO: Note, onPostExecute may run into issues. Be Creative (:
            new HttpServerRequest<Activity, ArrayList<Event>>(getActivity(), HttpRequest.GET) {

                @Override protected ArrayList<Event> onResponse(final String response) {
                    try {
                        final JSONArray arr = new JSONObject(response).getJSONArray("text");

                        ArrayList<Event> events = new ArrayList<Event>();
                        for (int i = 0; i < arr.length(); ++i) {
                            final JSONObject obj = arr.getJSONObject(i);
                            events.add(Event.fromJSON(obj));
                        }

                        return events;
                    } catch (JSONException e) {
                        e.printStackTrace();
                        return null; // TODO: null voodoo
                    }
                }

                @Override protected void onPostExecute(ArrayList<Event> events) {
                    super.onPostExecute(events);
                    setEvents(events);
                    layoutFragment();
                    mRefreshLayout.setRefreshing(false);
                }
                
                @Override protected void onCancelled() {
                    mRefreshLayout.setRefreshing(false);
                }

            }.execute("http://24.124.60.119/get/user/events/2");

    } // end of function getAllUserEvents()


    /**
     * Layouts the view for the fragment
     */
    public void layoutFragment() {

        if( mEvents != null )
        {
            // Split up the events based on Event Type (i.e. Past, Today, or Future)
            ArrayList<Event> pastEvents = new ArrayList<Event>();
            ArrayList<Event> todayEvents = new ArrayList<Event>();
            ArrayList<Event> futureEvents = new ArrayList<Event>();
            Event tempEvent;
            for(int i = 0; i < mEvents.size(); i++)
            {
                tempEvent = mEvents.get(i);
                if( tempEvent.getType() == Event.EventType.Past )
                {
                    pastEvents.add(tempEvent);
                }
{'fraction_non_alphanumeric': 0.08925673482635509, 'fraction_numerical': 0.003353889429838797, 'mean_word_length': 2.145287512759442, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1081545', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2248, 'n_words': 698}