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);
}
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);
}
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);
}
Aggregations