package com.nucc.hackwinds.models;


import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.nucc.hackwinds.utilities.ServiceHandler;

import org.json.JSONException;
import org.json.JSONObject;

public class CameraModel {

    // Constants
    private final String HACKWINDS_API_URL = "http://blog.mpiannucci.com/static/hackwinds_camera_locations.json";
    private final String NEEDS_RELOAD_KEY = "NeedCameraLocationFetch";

    // Member variables
    private Context mContext;
    private static CameraModel mInstance;
    private boolean mForceReload;

    public static JSONObject cameraLocations;

    public static CameraModel getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new CameraModel(context);
        }
        return mInstance;
    }

    public static JSONObject getCameraLocations() {
        return cameraLocations;
    }

    private CameraModel(Context context) {
        // Initialize the context
        mContext = context.getApplicationContext();
        mForceReload = false;
    }

    public boolean fetchCameraURLs() {
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
        boolean needsReload = sharedPrefs.getBoolean(NEEDS_RELOAD_KEY, true);

        if (!needsReload && !mForceReload) {
            return true;
        }

        ServiceHandler sh = new ServiceHandler();
        String rawData = sh.makeServiceCall(HACKWINDS_API_URL, ServiceHandler.GET);

        try {
            JSONObject jsonResp = new JSONObject(rawData);
            cameraLocations = jsonResp.getJSONObject("camera_locations");
        } catch (JSONException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    public boolean forceFetchCameraURLs() {
        mForceReload = true;
        return fetchCameraURLs();
    }
}

@@ -1545,16 +1545,53 @@
 er.GET);
+%0A        JSONObject narragansettCams;
 %0A%0A      
@@ -1731,16 +1731,94 @@
 ions%22);%0A
+            narragansettCams = cameraLocations.getJSONObject(%22Narragansett%22);%0A
         
@@ -1900,24 +1900,24 @@
 turn false;%0A
-
         %7D%0A  
@@ -1906,32 +1906,635 @@
 alse;%0A        %7D%0A
+%0A        if (narragansettCams.length() %3E 3) %7B%0A            try %7B%0A                String pjURL = narragansettCams.getString(%22Point Judith%22);%0A                String rawPJData = sh.makeServiceCall(pjURL, ServiceHandler.GET);%0A                JSONObject pjResp = new JSONObject(rawPJData);%0A                JSONObject pjStreamData = (JSONObject)pjResp.getJSONObject(%22streamInfo%22).getJSONArray(%22stream%22).get(0);%0A                narragansettCams.put(%22Point Judith%22, pjStreamData);%0A            %7D catch (JSONException e) %7B%0A                e.printStackTrace();%0A                return true;%0A            %7D%0A        %7D%0A%0A
         return t

Add point judith handling to camera model