Search in sources :

Example 1 with Event

use of cl.smartcities.isci.transportinspector.backend.Event 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)

Example 2 with Event

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

the class EventAdapterTest method setUp.

@Before
public void setUp() throws Exception {
    ArrayList<Event> events = new ArrayList<>();
    title = "507";
    // code = "GGWP00";
    code = "550e8400-e29b-41d4-a716-446655440000";
    event1 = new Event("1", "evento 1", "10:54", 0, 0);
    event2 = new Event("2", "evento 2", "00:00", 5, 0);
    event3 = new Event("3", "evento 3", "13:32", 0, 3);
    event4 = new Event("4", "evento 4", "07:23", 15, 3);
    events.add(event1);
    events.add(event2);
    events.add(event3);
    events.add(event4);
    mAdapter = spy(new EventAdapter(rule.getActivity(), code, new EventAdapter.EventClickedListener() {

        @Override
        public void positiveClick(Event event, EventAdapter.ResultListener innerListener) {
        }

        @Override
        public void negativeClick(Event event, EventAdapter.ResultListener innerListener) {
        }
    }, events, "Bus", false));
}
Also used : ArrayList(java.util.ArrayList) Event(cl.smartcities.isci.transportinspector.backend.Event) EventAdapter(cl.smartcities.isci.transportinspector.adapters.dialogAdapters.EventAdapter) Before(org.junit.Before)

Example 3 with Event

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

the class EventAdapter method getView.

@NonNull
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
    final ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.row_event_layout, parent, false);
        holder = new ViewHolder();
        holder.event_icon = convertView.findViewById(R.id.event_icon);
        holder.description = convertView.findViewById(R.id.description);
        holder.time = convertView.findViewById(R.id.event_time);
        holder.yes_counter = convertView.findViewById(R.id.yes_counter);
        holder.no_counter = convertView.findViewById(R.id.no_counter);
        holder.yesIcon = convertView.findViewById(R.id.yes_icon);
        holder.noIcon = convertView.findViewById(R.id.no_icon);
        holder.true_text = convertView.findViewById(R.id.true_text);
        holder.false_text = convertView.findViewById(R.id.false_text);
        holder.ticket_font_green = convertView.findViewById(R.id.ticket_font_green);
        holder.ticket_font_red = convertView.findViewById(R.id.ticket_font_red);
        holder.confirm_button_layout = convertView.findViewById(R.id.confirm_button_layout);
        holder.decline_button_layout = convertView.findViewById(R.id.decline_button_layout);
        Typeface robotoRegular = Typeface.createFromAsset(this.getContext().getAssets(), this.context.getString(R.string.roboto_regular_font));
        Typeface robotoBold = Typeface.createFromAsset(this.getContext().getAssets(), this.context.getString(R.string.roboto_bold_font));
        Typeface iconFont = Typeface.createFromAsset(this.getContext().getAssets(), this.context.getString(R.string.icon_font));
        holder.setHolderTypefaceRegular(robotoRegular);
        holder.setHolderTypefaceBold(robotoBold);
        holder.setHolderIconFont(iconFont);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    final Event event = this.events.get(position);
    // Descripcion del evento
    String description = event.getDescription();
    holder.description.setText(description);
    // Time del evento
    String date = event.getTime();
    holder.time.setText(date);
    // Confirmaciones del evento
    String confirms = event.getConfirms() + "";
    holder.yes_counter.setText(confirms);
    // Negaciones del evento
    String declines = event.getDeclines() + "";
    holder.no_counter.setText(declines);
    // Event icon
    int resDrawableId = event.getResDrawableId();
    holder.event_icon.setImageResource(resDrawableId);
    // id del evento
    holder.decline_button_layout.setVisibility(View.VISIBLE);
    holder.decline_button_layout.setVisibility(View.VISIBLE);
    if (getLastStateAccordingToPosition(position).equals(State.ONLY_CONFIRM)) {
        holder.decline_button_layout.setVisibility(View.GONE);
    }
    if (getLastStateAccordingToPosition(position).equals(State.ONLY_DECLINE)) {
        holder.confirm_button_layout.setVisibility(View.GONE);
    }
    holder.ticket_font_green.setVisibility(View.GONE);
    holder.ticket_font_red.setVisibility(View.GONE);
    holder.decline_button_layout.setVisibility(View.VISIBLE);
    holder.confirm_button_layout.setVisibility(View.VISIBLE);
    if (!eventsLocked) {
        ReportCooldownData data = CooldownController.getCooldownData(String.format(Locale.getDefault(), "%s|%s", event.getCooldownId(), cooldownSuffix));
        if (data.inCooldown()) {
            switch(data.vote) {
                case 0:
                    disableButton(holder.yesIcon);
                    disableButton(holder.noIcon);
                    break;
                case 1:
                    holder.decline_button_layout.setVisibility(View.GONE);
                    holder.ticket_font_green.setVisibility(View.VISIBLE);
                    break;
                case 2:
                    holder.confirm_button_layout.setVisibility(View.GONE);
                    holder.ticket_font_red.setVisibility(View.VISIBLE);
                    break;
            }
            View.OnClickListener listener = new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Toast.makeText(context, context.getString(R.string.report_on_cooldown), Toast.LENGTH_SHORT).show();
                }
            };
            holder.yesIcon.setOnClickListener(listener);
            holder.noIcon.setOnClickListener(listener);
        } else {
            holder.yesIcon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    listener.positiveClick(event, new ResultListener() {

                        @Override
                        public void resultConfirmed() {
                            Map<String, String> attributes = new HashMap<>();
                            attributes.put("Event name", event.getName());
                            attributes.put("BusStop/Service Code", code);
                            TranSappApplication.addLog("Event confirmed", attributes);
                            setCurrentState(position, State.ONLY_CONFIRM);
                            confirmEvent(holder, event);
                            holder.decline_button_layout.setVisibility(View.GONE);
                            holder.ticket_font_green.setVisibility(View.VISIBLE);
                        }
                    });
                }
            });
            holder.noIcon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    listener.negativeClick(event, new ResultListener() {

                        @Override
                        public void resultConfirmed() {
                            Map<String, String> attributes = new HashMap<>();
                            attributes.put("Event name", event.getName());
                            attributes.put("BusStop/Service Code", code);
                            TranSappApplication.addLog("Event denied", attributes);
                            setCurrentState(position, State.ONLY_DECLINE);
                            denyEvent(holder, event);
                            holder.confirm_button_layout.setVisibility(View.GONE);
                            holder.ticket_font_red.setVisibility(View.VISIBLE);
                        }
                    });
                }
            });
        }
    } else {
        disableButton(holder.yesIcon);
        disableButton(holder.noIcon);
    }
    /* save holder onStopListener convertView */
    if (position % 2 == 0) {
        convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.even_row));
    } else {
        convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.odd_row));
    }
    return convertView;
}
Also used : Typeface(android.graphics.Typeface) HashMap(java.util.HashMap) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ReportCooldownData(cl.smartcities.isci.transportinspector.reportCooldown.ReportCooldownData) Event(cl.smartcities.isci.transportinspector.backend.Event) NonNull(android.support.annotation.NonNull)

Aggregations

Event (cl.smartcities.isci.transportinspector.backend.Event)3 NonNull (android.support.annotation.NonNull)2 ArrayList (java.util.ArrayList)2 Typeface (android.graphics.Typeface)1 Pair (android.support.v4.util.Pair)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 EventAdapter (cl.smartcities.isci.transportinspector.adapters.dialogAdapters.EventAdapter)1 MapBus (cl.smartcities.isci.transportinspector.backend.MapBus)1 ReportCooldownData (cl.smartcities.isci.transportinspector.reportCooldown.ReportCooldownData)1 HashMap (java.util.HashMap)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Before (org.junit.Before)1