Search in sources :

Example 1 with JsonArrayReq

use of flying.grub.tamtime.data.connection.JsonArrayReq in project TamTime by flyingrub.

the class ReportEvent method getReports.

public void getReports() {
    JsonArrayReq req = new JsonArrayReq(Request.Method.GET, GET_REPORTS, null, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            setReport(response);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, "Error: " + error.getMessage());
        }
    });
    VolleyApp.getInstance(context).addToRequestQueue(req);
}
Also used : Response(com.android.volley.Response) NetworkResponse(com.android.volley.NetworkResponse) VolleyError(com.android.volley.VolleyError) JSONArray(org.json.JSONArray) JsonArrayReq(flying.grub.tamtime.data.connection.JsonArrayReq)

Example 2 with JsonArrayReq

use of flying.grub.tamtime.data.connection.JsonArrayReq in project TamTime by flyingrub.

the class RealTimes method updateLine.

public void updateLine(Line line) {
    JSONObject data = null;
    try {
        data = lineToJSON(line);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    JsonArrayReq req = new JsonArrayReq(Request.Method.POST, JSON_REALTIME_LINE, data, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            for (int i = 0; i < response.length(); i++) {
                try {
                    JSONObject stop = response.getJSONObject(i);
                    int tam_id = stop.getInt("tam_stop_id");
                    int cityway_id = stop.getInt("cityway_stop_id");
                    JSONArray timesJSON = stop.getJSONArray("stop_next_time");
                    ArrayList<Time> times = new ArrayList<>();
                    for (int j = 0; j < timesJSON.length(); j++) {
                        JSONObject timeJSON = timesJSON.getJSONObject(j);
                        String waiting_time = timeJSON.getString("waiting_time");
                        int hour = timeJSON.getInt("passing_hour");
                        int min = timeJSON.getInt("passing_minute");
                        times.add(new Time(waiting_time, hour, min));
                    }
                    Data.getData().getMap().addTimeToStop(tam_id, cityway_id, times);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            EventBus.getDefault().post(new MessageUpdate(MessageUpdate.Type.TIMES_UPDATE));
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, "error :" + error.networkResponse);
        }
    });
    VolleyApp.getInstance(context).addToRequestQueue(req);
}
Also used : VolleyError(com.android.volley.VolleyError) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) MessageUpdate(flying.grub.tamtime.data.update.MessageUpdate) JsonArrayReq(flying.grub.tamtime.data.connection.JsonArrayReq) Response(com.android.volley.Response) JSONObject(org.json.JSONObject)

Example 3 with JsonArrayReq

use of flying.grub.tamtime.data.connection.JsonArrayReq in project TamTime by flyingrub.

the class RealTimes method updateStops.

public void updateStops(ArrayList<Stop> stops) {
    JSONObject data = null;
    try {
        data = stopsToJSON(stops);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    JsonArrayReq req = new JsonArrayReq(Request.Method.POST, JSON_REALTIME_STOPS, data, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            for (int i = 0; i < response.length(); i++) {
                try {
                    JSONObject stop = response.getJSONObject(i);
                    int tam_id = stop.getInt("tam_stop_id");
                    int cityway_id = stop.getInt("cityway_stop_id");
                    JSONArray timesJSON = stop.getJSONArray("stop_next_time");
                    ArrayList<Time> times = new ArrayList<>();
                    for (int j = 0; j < timesJSON.length(); j++) {
                        JSONObject timeJSON = timesJSON.getJSONObject(j);
                        String waiting_time = timeJSON.getString("waiting_time");
                        int hour = timeJSON.getInt("passing_hour");
                        int min = timeJSON.getInt("passing_minute");
                        times.add(new Time(waiting_time, hour, min));
                    }
                    Data.getData().getMap().addTimeToStop(tam_id, cityway_id, times);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            EventBus.getDefault().post(new MessageUpdate(MessageUpdate.Type.TIMES_UPDATE));
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, "error :" + error);
        }
    });
    VolleyApp.getInstance(context).addToRequestQueue(req);
}
Also used : VolleyError(com.android.volley.VolleyError) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) MessageUpdate(flying.grub.tamtime.data.update.MessageUpdate) JsonArrayReq(flying.grub.tamtime.data.connection.JsonArrayReq) Response(com.android.volley.Response) JSONObject(org.json.JSONObject)

Aggregations

Response (com.android.volley.Response)3 VolleyError (com.android.volley.VolleyError)3 JsonArrayReq (flying.grub.tamtime.data.connection.JsonArrayReq)3 JSONArray (org.json.JSONArray)3 MessageUpdate (flying.grub.tamtime.data.update.MessageUpdate)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 NetworkResponse (com.android.volley.NetworkResponse)1