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);
}
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));
}
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;
}
Aggregations