package is.genki.bigredapp.android;

import android.app.Activity;
import android.app.ListFragment;
import android.content.Context;
import android.os.Bundle;

import org.json.JSONObject;

import java.text.SimpleDateFormat;

/**
 * Fragment to show the open status of Cornell's libraries
 * Source for information: http://mannservices.mannlib.cornell.edu/LibServices/showAllLibraryHoursForAcademicSemester.do?output=json
 */
public class LibraryFragment extends ListFragment {

    private Activity mContext;

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

        mContext = getActivity();

    }

    // Gets and returns the json object for library hours
    private JSONObject fetchLibraryHours(){
        return null;
    }


    /**Parses JSON for a library to generate its hours object.
     * Sets closeUnix to null if the library is closed today either normall or due
     * to a special circumstance.
     */
    private HoursObject grabTodaysHours(JSONObject lib){

        return null;
    }

    //Checks to see if a library is currently open based on its hours object
    private boolean isOpen(HoursObject lib){
        return false;
    }

    //Holds the open time for a library today
    private class HoursObject {
        //Set these as null if the library is closed.
        Long openUnix;
        Long closeUnix;

        public HoursObject(Long openUnix, Long closeUnix){
            this.openUnix = openUnix;
            this.closeUnix = closeUnix;
        }
    }

}

@@ -162,62 +162,350 @@
 ort 
-org.json.JSONObject;%0A%0Aimport java.text.SimpleDateForma
+com.android.volley.Request;%0Aimport com.android.volley.Response;%0Aimport com.android.volley.toolbox.JsonObjectRequest;%0A%0Aimport org.json.JSONArray;%0Aimport org.json.JSONException;%0Aimport org.json.JSONObject;%0A%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.ArrayList;%0Aimport java.util.Calendar;%0Aimport java.util.Iterator;%0Aimport java.util.Lis
 t;%0A%0A
@@ -757,16 +757,169 @@
 ment %7B%0A%0A
+    public static final String HOURS_URL = %22http://mannservices.mannlib.cornell.edu/LibServices/showAllLibraryHoursForAcademicSemester.do?output=json%22;%0A%0A
     priv
@@ -1086,24 +1086,54 @@
 ctivity();%0A%0A
+        fetchLibraryHours();%0A%0A
     %7D%0A%0A    /
@@ -1143,22 +1143,24 @@
 ets and 
-return
+processe
 s the js
@@ -1203,60 +1203,1405 @@
 ate 
-JSONObject fetchLibraryHours()%7B%0A        return null;
+void fetchLibraryHours()%7B%0A        if (SingletonRequestQueue.isConnected(mContext)) %7B%0A            JsonObjectRequest jsonObjectRequest = (JsonObjectRequest)%0A                    new JsonObjectRequest(Request.Method.GET, HOURS_URL,%0A                            new Response.Listener%3CJSONObject%3E() %7B%0A                                @Override%0A                                public void onResponse(JSONObject response) %7B%0A                                    try %7B%0A                                        ArrayList%3CHoursObject%3E allHours = new ArrayList%3C%3E();%0A                                        Iterator%3CString%3E libNames = response.keys();%0A                                        while (libNames.hasNext()) %7B%0A                                            String current = libNames.next();%0A                                            allHours.add(grabTodaysHours(response.getJSONObject(current)));%0A                                        %7D%0A                                    %7D catch (JSONException e)%7B%0A                                        e.printStackTrace();%0A                                    %7D%0A                                %7D%0A                            %7D, SingletonRequestQueue.getErrorListener(mContext))%0A                            .setRetryPolicy(SingletonRequestQueue.getRetryPolicy());%0A            SingletonRequestQueue.getInstance(mContext).addToRequestQueue(jsonObjectRequest);%0A        %7D%0A
 %0A   
@@ -2742,17 +2742,16 @@
 r normal
-l
  or due%0A
@@ -2849,17 +2849,16 @@
 t lib)%7B%0A
-%0A
         
@@ -3011,20 +3011,144 @@
     
-return false
+long now = Calendar.getInstance().getTimeInMillis();%0A        return (lib.closeUnix == null %7C%7C lib.openUnix %3E now %7C%7C lib.closeUnix %3C now)
 ;%0A  
@@ -3330,16 +3330,37 @@
 oseUnix;
+%0A        String name;
 %0A%0A      
@@ -3409,16 +3409,29 @@
 loseUnix
+, String name
 )%7B%0A     
@@ -3495,32 +3495,62 @@
 ix = closeUnix;%0A
+            this.name = name;%0A
         %7D%0A    %7D%0A

Implement some libraryfragment functions