use of flying.grub.tamtime.data.update.MessageUpdate 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 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(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.update.MessageUpdate 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 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(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);
}
use of flying.grub.tamtime.data.update.MessageUpdate in project TamTime by flyingrub.
the class ReportEvent method setReport.
public void setReport(JSONArray reportJson) {
for (Report r : this.reportList) {
r.removeFromStop();
}
this.reportList = new ArrayList<>();
try {
for (int i = 0; i < reportJson.length(); i++) {
JSONObject reportObjectJson = reportJson.getJSONObject(i);
String msg = reportObjectJson.optString("message");
int confirm = reportObjectJson.getInt("confirm");
int reportId = reportObjectJson.getInt("id");
Calendar date = Calendar.getInstance();
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
date.setTime(sdf.parse(reportObjectJson.getString("date")));
} catch (Exception e) {
e.printStackTrace();
}
StopZone stop = Data.getData().getMap().getStopZoneById(reportObjectJson.getInt("stop"));
if (stop != null) {
Report report = new Report(stop, ReportType.reportFromId(reportObjectJson.getInt("type")), msg, date, confirm, reportId);
this.reportList.add(report);
}
}
EventBus.getDefault().post(new MessageUpdate(MessageUpdate.Type.REPORT_UPDATE));
} catch (JSONException e) {
e.printStackTrace();
}
}
Aggregations