Search in sources :

Example 6 with ServerSentEvent

use of cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent in project androidApp by InspectorIncognito.

the class ReportAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    switch(holder.getItemViewType()) {
        case SIMPLE_ITEM:
            holder.setEmpty(false);
            ServerSentEvent event = events.get(position);
            holder.setData(event);
            ReportCooldownData data = CooldownController.getCooldownData(String.format(Locale.getDefault(), "%s|%s", event.getCooldownId(), cooldownSuffix));
            if (eventsLocked) {
                holder.lockedButtons();
            } else {
                holder.setupCooldownData(data, event);
            }
            break;
        case EMPTY_ITEM:
            holder.setEmpty(true);
            break;
    }
}
Also used : ReportCooldownData(cl.smartcities.isci.transportinspector.reportCooldown.ReportCooldownData) ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent)

Example 7 with ServerSentEvent

use of cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent in project androidApp by InspectorIncognito.

the class EventRequest method processResult.

@NonNull
@Override
public Pair<ArrayList<ServerSentEvent>, String> processResult(@NonNull String result) {
    ArrayList<ServerSentEvent> eventResponse = new ArrayList<>();
    String message = TranSappApplication.getAppContext().getString(R.string.success_response_event);
    try {
        JSONObject data = new JSONObject(result);
        long deltaScore = TranSappAccountManager.updateUserData(data.getJSONObject("gamificationData"));
        if (deltaScore > 0) {
            message = TranSappApplication.getAppContext().getString(R.string.success_response_event_score, deltaScore);
        }
        JSONArray events = data.getJSONArray("events");
        for (int i = 0; i < events.length(); i++) {
            ServerSentEvent event = new ServerSentEvent(events.getJSONObject(i));
            eventResponse.add(event);
        }
        addCooldown();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return Pair.create(eventResponse, message);
}
Also used : JSONObject(org.json.JSONObject) ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) NonNull(android.support.annotation.NonNull)

Example 8 with ServerSentEvent

use of cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent in project androidApp by InspectorIncognito.

the class BusEventBuilder method buildCompleteReport.

@Override
public void buildCompleteReport(CompleteReportEventDrawableItem completeReportPanelItem) {
    ServerSentEvent event = new ServerSentEvent(completeReportPanelItem);
    listener.onRequestReady(new BusEventRequest(listener, event, bus), bus.getId());
}
Also used : BusEventRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.BusEventRequest) ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent)

Example 9 with ServerSentEvent

use of cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent in project androidApp by InspectorIncognito.

the class BusStopEventBuilder method buildCompleteReport.

@Override
public void buildCompleteReport(CompleteReportEventDrawableItem completeReportPanelItem) {
    ServerSentEvent event = new ServerSentEvent(completeReportPanelItem);
    listener.onRequestReady(new BusStopEventRequest(listener, event, busStop), busStop.getId());
}
Also used : ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent) BusStopEventRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.BusStopEventRequest)

Example 10 with ServerSentEvent

use of cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent in project androidApp by InspectorIncognito.

the class BusStopPlugin method onResponse.

private void onResponse(ArrayList<ServerSentBus> buses, ArrayList<ServerSentEvent> events, final BusStopLoadingLayerTask loaderTask, final Thread thread) {
    buses = filterBuses(buses);
    updateBusSource(buses);
    for (ServerSentEvent event : events) {
        event.finishInitialization();
    }
    ((BusStopMarker) selectedBusStop).setEvents(events);
    ArrayList<IconBuilder> buildingList = new ArrayList<>();
    buildingList.add(new BusStopIconsBuilder(FeatureCollection.fromFeatures(new Feature[] { selectedBusStop })).toBuilder());
    buildingList.add(new MapBusIconsBuilder(FeatureCollection.fromFeatures(busesFeatures.getFeatures())).toBuilder());
    GenerateViewIconTask task = new GenerateViewIconTask(new GenerateViewIconTask.ImageLoaderListener() {

        @Override
        public void onImageGenResult(HashMap<String, View> viewMap, HashMap<String, Bitmap> bitmapHashMap) {
            if (selectedBusStop == null) {
                return;
            }
            Log.d(BusStopPlugin.class.getSimpleName(), "onImageGenResult");
            if (mapboxMap != null) {
                mapboxMap.addImages(bitmapHashMap);
            } else {
                return;
            }
            selectedBusStop.addBooleanProperty(BusStopMarker.PROPERTY_LOADING, false);
            if (loaderTask != null && thread != null) {
                loaderTask.stop();
                thread.interrupt();
            }
            refreshBusStopSource();
            refreshBusSource();
            if (!busesFeatures.getFeatures().isEmpty()) {
                Collections.sort(busesFeatures.getFeatures(), new Comparator<Feature>() {

                    @Override
                    public int compare(Feature bus1, Feature bus2) {
                        BusMarker m1 = (BusMarker) bus1;
                        BusMarker m2 = (BusMarker) bus2;
                        return m1.getBus().getDistanceToBusStop() < m2.getBus().getDistanceToBusStop() ? -1 : (m1.getBus().getDistanceToBusStop() == m2.getBus().getDistanceToBusStop() ? 0 : 1);
                    }
                });
                Feature busFeature = busesFeatures.getFeatures().get(0);
                LatLngBounds.Builder latLngBoundsBuilder = new LatLngBounds.Builder();
                latLngBoundsBuilder.include(MapboxUtil.convertToLatLng(busFeature));
                latLngBoundsBuilder.include(MapboxUtil.getRotatePoint(busFeature, selectedBusStop, busFeature.getNumberProperty(BusMarker.PROPERTY_BEARING).doubleValue()));
                CameraUpdate update = CameraUpdateFactory.newLatLngBounds(latLngBoundsBuilder.build(), 100, 100, 100, 100);
                if (loaderTask != null && thread != null) {
                    MapboxUtil.animateCameraToNewCameraPosition(update.getCameraPosition(mapboxMap), mapboxMap);
                    // mapboxMap.animateCamera(update, 1000);
                    periodicRequestHandler.startPeriodicRequest();
                    final BusStop busStop = ((BusStopMarker) selectedBusStop).getBusStop();
                    listener.onBusStopSelected(busStop);
                }
            }
        }
    }, viewMap, buildingList);
    ((BusStopMarker) selectedBusStop).getBusStop().setIncomingBuses(buses);
    task.execute();
}
Also used : GenerateViewIconTask(cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) BusStopIconsBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder) MapBusIconsBuilder(cl.smartcities.isci.transportinspector.map.model.bus.MapBusIconsBuilder) ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent) BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker) ArrayList(java.util.ArrayList) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Feature(com.mapbox.services.commons.geojson.Feature) View(android.view.View) Comparator(java.util.Comparator) Bitmap(android.graphics.Bitmap) MapBusIconsBuilder(cl.smartcities.isci.transportinspector.map.model.bus.MapBusIconsBuilder) BusMarker(cl.smartcities.isci.transportinspector.map.model.bus.BusMarker) BusStopIconsBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder) CameraUpdate(com.mapbox.mapboxsdk.camera.CameraUpdate) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Aggregations

ServerSentEvent (cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent)10 BusStopEventRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.BusStopEventRequest)3 ArrayList (java.util.ArrayList)3 NonNull (android.support.annotation.NonNull)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ReportAdapter (cl.smartcities.isci.transportinspector.adapters.ReportAdapter)2 BusEventRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.BusEventRequest)2 EventRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.EventRequest)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Bitmap (android.graphics.Bitmap)1 Bundle (android.os.Bundle)1 CustomArrayAdapter (cl.smartcities.isci.transportinspector.adapters.CustomArrayAdapter)1 BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)1 ReportBusListDialog (cl.smartcities.isci.transportinspector.dialogs.ReportBusListDialog)1 BusMarker (cl.smartcities.isci.transportinspector.map.model.bus.BusMarker)1 MapBusIconsBuilder (cl.smartcities.isci.transportinspector.map.model.bus.MapBusIconsBuilder)1