Search in sources :

Example 1 with ReportCooldownData

use of cl.smartcities.isci.transportinspector.reportCooldown.ReportCooldownData 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 2 with ReportCooldownData

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

Example 3 with ReportCooldownData

use of cl.smartcities.isci.transportinspector.reportCooldown.ReportCooldownData in project androidApp by InspectorIncognito.

the class EventRequest method addCooldown.

private void addCooldown() {
    List<ReportCooldownData> data = new ArrayList<>();
    for (String id : event.getCooldownIds()) {
        int vote = 0;
        if (id.equals(event.getId())) {
            vote = selectedVote.equals(CONFIRM_VOTE) ? 1 : 2;
        }
        data.add(new ReportCooldownData(getSpecificCooldownId(id), vote));
    }
    CooldownController.setEventOnCooldown(data);
}
Also used : ReportCooldownData(cl.smartcities.isci.transportinspector.reportCooldown.ReportCooldownData) ArrayList(java.util.ArrayList)

Aggregations

ReportCooldownData (cl.smartcities.isci.transportinspector.reportCooldown.ReportCooldownData)3 Typeface (android.graphics.Typeface)1 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Event (cl.smartcities.isci.transportinspector.backend.Event)1 ServerSentEvent (cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1