Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/adapters/StopRecyclerAdapter.java
| Show All 31 Lines | |||||
| import it.reyboz.bustorino.R; | import it.reyboz.bustorino.R; | ||||
| import it.reyboz.bustorino.backend.Stop; | import it.reyboz.bustorino.backend.Stop; | ||||
| public class StopRecyclerAdapter extends RecyclerView.Adapter<StopRecyclerAdapter.ViewHolder> { | public class StopRecyclerAdapter extends RecyclerView.Adapter<StopRecyclerAdapter.ViewHolder> { | ||||
| private List<Stop> stops; | private List<Stop> stops; | ||||
| private static final int ITEM_LAYOUT_FAVORITES = R.layout.entry_bus_stop; | private static final int ITEM_LAYOUT_FAVORITES = R.layout.entry_bus_stop; | ||||
| private static final int ITEM_LAYOUT_LINES = R.layout.stop_line_element; | private static final int ITEM_LAYOUT_LINES = R.layout.stop_line_element; | ||||
| private static final int busIcon = R.drawable.bus; | private static final int busIcon = R.drawable.ic_bus; | ||||
| private static final int trainIcon = R.drawable.subway; | private static final int trainIcon = R.drawable.subway; | ||||
| private static final int tramIcon = R.drawable.tram; | private static final int tramIcon = R.drawable.tram; | ||||
| private static final int cityIcon = R.drawable.city; | private static final int cityIcon = R.drawable.city; | ||||
| private NameCapitalize capitalizeLocation = NameCapitalize.DO_NOTHING; | private NameCapitalize capitalizeLocation = NameCapitalize.DO_NOTHING; | ||||
| private final Use usedFor; | private final Use usedFor; | ||||
| private final StopAdapterListener listener; | private final StopAdapterListener listener; | ||||
| ▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | public void onBindViewHolder(@NonNull StopRecyclerAdapter.ViewHolder vh, int position) { | ||||
| vh.busStopNameTextView.setText(stop.getStopDisplayName()); | vh.busStopNameTextView.setText(stop.getStopDisplayName()); | ||||
| String whatStopsHere = stop.routesThatStopHereToString(); | String whatStopsHere = stop.routesThatStopHereToString(); | ||||
| if(whatStopsHere == null) { | if(whatStopsHere == null) { | ||||
| vh.busStopLinesTextView.setVisibility(View.GONE); | vh.busStopLinesTextView.setVisibility(View.GONE); | ||||
| } else { | } else { | ||||
| vh.busStopLinesTextView.setText(whatStopsHere); | vh.busStopLinesTextView.setText(whatStopsHere); | ||||
| vh.busStopLinesTextView.setVisibility(View.VISIBLE); // might be GONE due to View Holder Pattern | vh.busStopLinesTextView.setVisibility(View.VISIBLE); // might be GONE due to View Holder Pattern | ||||
| } | } | ||||
| /* | |||||
| //This is deprecated, always showing a bus | |||||
| if(stop.type == null) { | if(stop.type == null) { | ||||
| vh.busStopLinesTextView.setCompoundDrawablesWithIntrinsicBounds(busIcon, 0, 0, 0); | vh.busStopLinesTextView.setCompoundDrawablesWithIntrinsicBounds(busIcon, 0, 0, 0); | ||||
| } else { | } else { | ||||
| switch(stop.type) { | switch(stop.type) { | ||||
| case BUS: | case BUS: | ||||
| default: | default: | ||||
| vh.busStopLinesTextView.setCompoundDrawablesWithIntrinsicBounds(busIcon, 0, 0, 0); | vh.busStopLinesTextView.setCompoundDrawablesWithIntrinsicBounds(busIcon, 0, 0, 0); | ||||
| break; | break; | ||||
| case METRO: | case METRO: | ||||
| case RAILWAY: | case RAILWAY: | ||||
| vh.busStopLinesTextView.setCompoundDrawablesWithIntrinsicBounds(trainIcon, 0, 0, 0); | vh.busStopLinesTextView.setCompoundDrawablesWithIntrinsicBounds(trainIcon, 0, 0, 0); | ||||
| break; | break; | ||||
| case TRAM: | case TRAM: | ||||
| vh.busStopLinesTextView.setCompoundDrawablesWithIntrinsicBounds(tramIcon, 0, 0, 0); | vh.busStopLinesTextView.setCompoundDrawablesWithIntrinsicBounds(tramIcon, 0, 0, 0); | ||||
| break; | break; | ||||
| case LONG_DISTANCE_BUS: | case LONG_DISTANCE_BUS: | ||||
| // è l'opposto della città ma va beh, dettagli. | // è l'opposto della città ma va beh, dettagli. | ||||
| vh.busStopLinesTextView.setCompoundDrawablesWithIntrinsicBounds(cityIcon, 0, 0, 0); | vh.busStopLinesTextView.setCompoundDrawablesWithIntrinsicBounds(cityIcon, 0, 0, 0); | ||||
| } | } | ||||
| } | } | ||||
| */ | |||||
| if (stop.location == null || stop.location.toLowerCase(Locale.ROOT).equals("null")) { | if (stop.location == null || stop.location.toLowerCase(Locale.ROOT).equals("null")) { | ||||
| vh.busStopLocaLityTextView.setVisibility(View.GONE); | vh.busStopLocaLityTextView.setVisibility(View.GONE); | ||||
| } else { | } else { | ||||
| vh.busStopLocaLityTextView.setText(NameCapitalize.capitalizePass(stop.location, capitalizeLocation)); | vh.busStopLocaLityTextView.setText(NameCapitalize.capitalizePass(stop.location, capitalizeLocation)); | ||||
| vh.busStopLocaLityTextView.setVisibility(View.VISIBLE); // might be GONE due to View Holder Pattern | vh.busStopLocaLityTextView.setVisibility(View.VISIBLE); // might be GONE due to View Holder Pattern | ||||
| } | } | ||||
| //trick to set the position | //trick to set the position | ||||
| vh.itemView.setOnLongClickListener(view -> { | vh.itemView.setOnLongClickListener(view -> { | ||||
| Show All 26 Lines | |||||
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register