Search in sources :

Example 1 with MapBus

use of cl.smartcities.isci.transportinspector.backend.MapBus in project androidApp by InspectorIncognito.

the class GetBusesRequest method processResult.

@NonNull
@Override
public Pair<ArrayList<MapBus>, ArrayList<Event>> processResult(@NonNull String result) {
    ArrayList<MapBus> busResponse = new ArrayList<>();
    ArrayList<Event> eventResponse = new ArrayList<>();
    try {
        JSONObject response = new JSONObject(result);
        JSONArray buses = response.getJSONArray("servicios");
        JSONArray events = response.getJSONArray("eventos");
        Log.d("Callback events", events.toString());
        for (int i = 0; i < buses.length(); i++) {
            try {
                MapBus bus = new MapBus(buses.getJSONObject(i));
                busResponse.add(bus);
            } catch (JSONException ignored) {
            }
        }
        for (int i = 0; i < events.length(); i++) {
        // Event event = new Event(events.getJSONObject(i));
        // eventResponse.add(event);
        }
        return new Pair<>(busResponse, eventResponse);
    } catch (JSONException e) {
        e.printStackTrace();
        Log.e("GetBusesRequest", result);
    }
    return new Pair<>(busResponse, eventResponse);
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Event(cl.smartcities.isci.transportinspector.backend.Event) JSONException(org.json.JSONException) MapBus(cl.smartcities.isci.transportinspector.backend.MapBus) Pair(android.support.v4.util.Pair) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)1 Pair (android.support.v4.util.Pair)1 Event (cl.smartcities.isci.transportinspector.backend.Event)1 MapBus (cl.smartcities.isci.transportinspector.backend.MapBus)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1