Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/adapters/PalinaAdapter.java
| Show All 13 Lines | BusTO (backend components) | ||||
| You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | ||||
| along with this program. If not, see <http://www.gnu.org/licenses/>. | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
| */ | */ | ||||
| package it.reyboz.bustorino.adapters; | package it.reyboz.bustorino.adapters; | ||||
| import android.content.Context; | import android.content.Context; | ||||
| import android.content.res.Resources; | import android.content.res.Resources; | ||||
| import android.graphics.drawable.Drawable; | |||||
| import android.widget.ImageView; | |||||
| import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
| import androidx.cardview.widget.CardView; | import androidx.cardview.widget.CardView; | ||||
| import androidx.core.content.res.ResourcesCompat; | import androidx.core.content.res.ResourcesCompat; | ||||
| import androidx.preference.PreferenceManager; | import androidx.preference.PreferenceManager; | ||||
| import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||
| import android.view.Gravity; | import android.view.Gravity; | ||||
| import android.os.Build; | import android.os.Build; | ||||
| Show All 28 Lines | |||||
| */ | */ | ||||
| public class PalinaAdapter extends RecyclerView.Adapter<PalinaAdapter.PalinaViewHolder> implements SharedPreferences.OnSharedPreferenceChangeListener { | public class PalinaAdapter extends RecyclerView.Adapter<PalinaAdapter.PalinaViewHolder> implements SharedPreferences.OnSharedPreferenceChangeListener { | ||||
| private static final int ROW_LAYOUT = R.layout.entry_bus_line_passage; | private static final int ROW_LAYOUT = R.layout.entry_bus_line_passage; | ||||
| private static final int metroBg = R.drawable.route_background_metro; | private static final int metroBg = R.drawable.route_background_metro; | ||||
| private static final int busBg = R.drawable.route_background_bus; | private static final int busBg = R.drawable.route_background_bus; | ||||
| private static final int extraurbanoBg = R.drawable.route_background_bus_long_distance; | private static final int extraurbanoBg = R.drawable.route_background_bus_long_distance; | ||||
| private static final int busIcon = R.drawable.bus; | private static final int busIcon = R.drawable.ic_bus_small; | ||||
| 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.ic_tram_24; | ||||
| private final String KEY_CAPITALIZE; | private final String KEY_CAPITALIZE; | ||||
| private Capitalize capit; | private Capitalize capit; | ||||
| private final List<Route> mRoutes; | private final List<Route> mRoutes; | ||||
| private final PalinaClickListener mRouteListener; | private final PalinaClickListener mRouteListener; | ||||
| @NonNull | @NonNull | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public void onBindViewHolder(@NonNull @NotNull PalinaViewHolder vh, int position) { | ||||
| dest = utils.toTitleCase(route.destinazione, true); | dest = utils.toTitleCase(route.destinazione, true); | ||||
| break; | break; | ||||
| case DO_NOTHING: | case DO_NOTHING: | ||||
| default: | default: | ||||
| } | } | ||||
| vh.rowRouteDestination.setText(dest); | vh.rowRouteDestination.setText(dest); | ||||
| } | } | ||||
| Drawable drawable = null; | |||||
| final var resources = con.getResources(); | |||||
| switch (route.type) { | switch (route.type) { | ||||
| //UNKNOWN = BUS for the moment | //UNKNOWN = BUS for the moment | ||||
| case UNKNOWN: | case UNKNOWN: | ||||
| case BUS: | case BUS: | ||||
| default: | default: | ||||
| // convertView could contain another background, reset it | // convertView could contain another background, reset it | ||||
| //vh.rowStopIcon.setBackgroundResource(busBg); | //vh.rowStopIcon.setBackgroundResource(busBg); | ||||
| //drawable = ResourcesCompat.getDrawable(con.getResources(), busIcon, con.getTheme()); | |||||
| vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(busIcon, 0, 0, 0); | //vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(busIcon, 0, 0, 0); | ||||
| vh.busIcon.setImageDrawable(ResourcesCompat.getDrawable(resources, busIcon, con.getTheme())); | |||||
| break; | break; | ||||
| case LONG_DISTANCE_BUS: | case LONG_DISTANCE_BUS: | ||||
| //vh.rowStopIcon.setBackgroundResource(extraurbanoBg); | //vh.rowStopIcon.setBackgroundResource(extraurbanoBg); | ||||
| vh.routeCard.setCardBackgroundColor(ResourcesCompat.getColor(res, R.color.extraurban_bus_bg, null)); | vh.routeCard.setCardBackgroundColor(ResourcesCompat.getColor(res, R.color.extraurban_bus_bg, null)); | ||||
| vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(busIcon, 0, 0, 0); | vh.busIcon.setImageDrawable(ResourcesCompat.getDrawable(resources, extraurbanoBg, con.getTheme())); | ||||
| break; | break; | ||||
| case METRO: | case METRO: | ||||
| //vh.rowStopIcon.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); | //vh.rowStopIcon.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); | ||||
| //vh.rowStopIcon.setBackgroundResource(metroBg); | //vh.rowStopIcon.setBackgroundResource(metroBg); | ||||
| vh.routeIDTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); | vh.routeIDTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); | ||||
| vh.routeCard.setCardBackgroundColor(ResourcesCompat.getColor(res, R.color.metro_bg, null)); | vh.routeCard.setCardBackgroundColor(ResourcesCompat.getColor(res, R.color.metro_bg, null)); | ||||
| vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(trainIcon, 0, 0, 0); | // vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(trainIcon, 0, 0, 0); | ||||
| vh.busIcon.setImageDrawable(ResourcesCompat.getDrawable(resources, trainIcon, con.getTheme())); | |||||
| break; | break; | ||||
| case RAILWAY: | case RAILWAY: | ||||
| //vh.rowStopIcon.setBackgroundResource(busBg); | //vh.rowStopIcon.setBackgroundResource(busBg); | ||||
| vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(trainIcon, 0, 0, 0); | //vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(trainIcon, 0, 0, 0); | ||||
| vh.busIcon.setImageDrawable(ResourcesCompat.getDrawable(resources, trainIcon, con.getTheme())); | |||||
| break; | break; | ||||
| case TRAM: // never used but whatever. | case TRAM: // never used but whatever. | ||||
| //vh.rowStopIcon.setBackgroundResource(busBg); | //vh.rowStopIcon.setBackgroundResource(busBg); | ||||
| vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(tramIcon, 0, 0, 0); | drawable = ResourcesCompat.getDrawable(resources, trainIcon, con.getTheme()); | ||||
| assert drawable != null; | |||||
| drawable.setTint(resources.getColor(R.color.black_icon_text, con.getTheme()) ); | |||||
| //vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(tramIcon, 0, 0, 0); | |||||
| vh.busIcon.setImageDrawable(ResourcesCompat.getDrawable(resources, tramIcon, con.getTheme())); | |||||
| break; | break; | ||||
| } | } | ||||
| List<Passaggio> passaggi = route.passaggi; | List<Passaggio> passaggi = route.passaggi; | ||||
| //TODO: Sort the passaggi with realtime first if source is GTTJSONFetcher | //TODO: Sort the passaggi with realtime first if source is GTTJSONFetcher | ||||
| if(passaggi.size() == 0) { | if(passaggi.size() == 0) { | ||||
| vh.rowRouteTimetable.setText(R.string.no_passages); | vh.rowRouteTimetable.setText(R.string.no_passages); | ||||
| Show All 12 Lines | public class PalinaAdapter extends RecyclerView.Adapter<PalinaAdapter.PalinaViewHolder> implements SharedPreferences.OnSharedPreferenceChangeListener { | ||||
| // hey look, a pattern! | // hey look, a pattern! | ||||
| public static class PalinaViewHolder extends RecyclerView.ViewHolder { | public static class PalinaViewHolder extends RecyclerView.ViewHolder { | ||||
| //final TextView rowStopIcon; | //final TextView rowStopIcon; | ||||
| final TextView routeIDTextView; | final TextView routeIDTextView; | ||||
| final CardView routeCard; | final CardView routeCard; | ||||
| final TextView rowRouteDestination; | final TextView rowRouteDestination; | ||||
| final TextView rowRouteTimetable; | final TextView rowRouteTimetable; | ||||
| final ImageView busIcon; | |||||
| public PalinaViewHolder(@NonNull @NotNull View view) { | public PalinaViewHolder(@NonNull @NotNull View view) { | ||||
| super(view); | super(view); | ||||
| /* | |||||
| convertView.findViewById(R.id.routeID); | |||||
| vh.rowRouteDestination = (TextView) convertView.findViewById(R.id.routeDestination); | |||||
| vh.rowRouteTimetable = (TextView) convertView.findViewById(R.id.routesThatStopHere); | |||||
| */ | |||||
| //rowStopIcon = view.findViewById(R.id.routeID); | |||||
| routeIDTextView = view.findViewById(R.id.routeNameTextView); | routeIDTextView = view.findViewById(R.id.routeNameTextView); | ||||
| routeCard = view.findViewById(R.id.routeCard); | routeCard = view.findViewById(R.id.routeCard); | ||||
| rowRouteDestination = view.findViewById(R.id.routeDestination); | rowRouteDestination = view.findViewById(R.id.routeDestination); | ||||
| rowRouteTimetable = view.findViewById(R.id.routesThatStopHere); | rowRouteTimetable = view.findViewById(R.id.routesThatStopHere); | ||||
| busIcon = view.findViewById(R.id.arrivalsBusIcon); | |||||
| } | } | ||||
| } | } | ||||
| private static Capitalize getCapitalize(SharedPreferences shPr, String key){ | private static Capitalize getCapitalize(SharedPreferences shPr, String key){ | ||||
| String capitalize = shPr.getString(key, ""); | String capitalize = shPr.getString(key, ""); | ||||
| switch (capitalize.trim()){ | switch (capitalize.trim()){ | ||||
| case "KEEP": | case "KEEP": | ||||
| return Capitalize.DO_NOTHING; | return Capitalize.DO_NOTHING; | ||||
| ▲ Show 20 Lines • Show All 91 Lines • Show Last 20 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