Search in sources :

Example 1 with ServerSentEvent

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

the class GetBusEventRequest method processResult.

@NonNull
@Override
public ArrayList<ServerSentEvent> processResult(@NonNull String result) {
    ArrayList<ServerSentEvent> eventResponse = new ArrayList<>();
    try {
        JSONObject data = new JSONObject(result);
        JSONArray events = data.getJSONArray("events");
        for (int i = 0; i < events.length(); i++) {
            ServerSentEvent event = new ServerSentEvent(events.getJSONObject(i));
            eventResponse.add(event);
        }
        return eventResponse;
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return eventResponse;
}
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 2 with ServerSentEvent

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

the class BusStopEventBuilder method buildIncompleteReport.

@Override
public void buildIncompleteReport(IncompleteReportEventDrawableItem incompleteReportPanelItem) {
    final ServerSentEvent event = new ServerSentEvent(incompleteReportPanelItem);
    ReportBusListDialog dialog = new ReportBusListDialog();
    dialog.setServices(busStop.getServices());
    dialog.setListener(new CustomArrayAdapter.ItemClickListener<String>() {

        @Override
        public void onItemClick(String service) {
            Log.d("BusStopEventBuilder", service + ", " + event);
            listener.onRequestReady(new BusStopEventRequest(listener, event, busStop, service), busStop.getId());
        }
    });
    dialog.show(context.getSupportFragmentManager(), "services");
}
Also used : ReportBusListDialog(cl.smartcities.isci.transportinspector.dialogs.ReportBusListDialog) CustomArrayAdapter(cl.smartcities.isci.transportinspector.adapters.CustomArrayAdapter) ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent) BusStopEventRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.BusStopEventRequest)

Example 3 with ServerSentEvent

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

the class BusReportDetailsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.detail_fragment_reports_layout);
    Bundle bundle = this.getIntent().getExtras();
    ArrayList<ServerSentEvent> events = bundle.getParcelableArrayList(EVENTS);
    RecyclerView incomingBusesRecyclerView = findViewById(R.id.reports_recycler_view);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    incomingBusesRecyclerView.setLayoutManager(layoutManager);
    incomingBusesRecyclerView.addItemDecoration(new InsetDecoration(this));
    ReportAdapter.ReportClickedListener reportClickedListener = new ReportAdapter.ReportClickedListener() {

        @Override
        public void onApprovalClicked(ServerSentEvent event) {
            EventRequest request = getRequest(event, true);
            request.setRequestToConfirm();
            ServerController.sendRequest(request, null);
        }

        @Override
        public void onDeclinedClicked(ServerSentEvent event) {
            EventRequest request = getRequest(event, false);
            request.setRequestToDecline();
            ServerController.sendRequest(request, null);
        }
    };
    bus = bundle.getParcelable(BUSES);
    /*if (bundle.keySet().contains(IS_USER_BUS)) {
            adapter = new ReportAdapter(events, bus, reportClickedListener, validationClickedListener);
        } else {
            adapter = new ReportAdapter(events, bus, reportClickedListener, validationClickedListener);
        }*/
    adapter = new ReportAdapter(events, bus, reportClickedListener, validationClickedListener);
    incomingBusesRecyclerView.setAdapter(adapter);
}
Also used : ReportAdapter(cl.smartcities.isci.transportinspector.adapters.ReportAdapter) Bundle(android.os.Bundle) ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent) BusEventRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.BusEventRequest) EventRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.EventRequest) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 4 with ServerSentEvent

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

the class BusStopReportFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.detail_fragment_reports_layout, container, false);
    RecyclerView incomingBusesRecyclerView = view.findViewById(R.id.reports_recycler_view);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this.getContext());
    incomingBusesRecyclerView.setLayoutManager(layoutManager);
    incomingBusesRecyclerView.addItemDecoration(new InsetDecoration(getContext()));
    adapter = new ReportAdapter(events, busStop, new ReportAdapter.ReportClickedListener() {

        @Override
        public void onApprovalClicked(ServerSentEvent event) {
            EventRequest request = getRequest(event, true);
            request.setRequestToConfirm();
            ServerController.sendRequest(request, null);
        }

        @Override
        public void onDeclinedClicked(ServerSentEvent event) {
            EventRequest request = getRequest(event, false);
            request.setRequestToDecline();
            ServerController.sendRequest(request, null);
        }
    }, validationClickedListener);
    incomingBusesRecyclerView.setAdapter(adapter);
    return view;
}
Also used : ReportAdapter(cl.smartcities.isci.transportinspector.adapters.ReportAdapter) ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent) BusStopEventRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.BusStopEventRequest) EventRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.EventRequest) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 5 with ServerSentEvent

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

the class UserReportsDetailsActivity method onResponse.

@Override
public void onResponse(ArrayList<ServerSentBus> buses, ArrayList<ServerSentEvent> events) {
    if (isBusStopEvent) {
        for (ServerSentEvent innerEvent : events) {
            if (event.getId().equals(innerEvent.getId())) {
                this.event = innerEvent;
                changeData(event);
                return;
            }
        }
        Toast.makeText(this, "El evento ya no se encuentra en este paradero", Toast.LENGTH_SHORT).show();
    } else {
        for (ServerSentBus mapBus : buses) {
            if (mapBus.getMachineUUID().equals(machineId)) {
                for (ServerSentEvent innerEvent : mapBus.getEvents()) {
                    if (event.getId().equals(innerEvent.getId())) {
                        this.event = innerEvent;
                        changeData(event);
                        return;
                    }
                }
            }
        }
        Toast.makeText(this, "El bus ya no se dirige a este paradero", Toast.LENGTH_SHORT).show();
    }
    finish();
}
Also used : ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent) ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)

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