Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/adapters/StopAdapter.java
| Show All 12 Lines | BusTO (backend components) | ||||
| GNU General Public License for more details. | GNU General Public License for more details. | ||||
| 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.widget.ImageView; | |||||
| import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
| import android.view.LayoutInflater; | import android.view.LayoutInflater; | ||||
| import android.view.View; | import android.view.View; | ||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||
| import android.widget.ArrayAdapter; | import android.widget.ArrayAdapter; | ||||
| import android.widget.TextView; | import android.widget.TextView; | ||||
| import java.util.List; | import java.util.List; | ||||
| import it.reyboz.bustorino.R; | import it.reyboz.bustorino.R; | ||||
| import it.reyboz.bustorino.backend.Stop; | import it.reyboz.bustorino.backend.Stop; | ||||
| /** | /** | ||||
| * @see PalinaAdapter | * @see PalinaAdapter | ||||
| */ | */ | ||||
| public class StopAdapter extends ArrayAdapter<Stop> { | public class StopAdapter extends ArrayAdapter<Stop> { | ||||
| private LayoutInflater li; | private LayoutInflater li; | ||||
| private static final int row_layout = R.layout.entry_bus_stop; | private static final int row_layout = R.layout.entry_bus_stop; | ||||
| 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 static class ViewHolder { | private static class ViewHolder { | ||||
| TextView busStopIDTextView; | final TextView busStopIDTextView; | ||||
| TextView busStopNameTextView; | final TextView busStopNameTextView; | ||||
| //TextView busLineVehicleIcon; | //TextView busLineVehicleIcon; | ||||
| TextView busStopLinesTextView; | final TextView busStopLinesTextView; | ||||
| TextView busStopLocaLityTextView; | final TextView busStopLocaLityTextView; | ||||
| ViewHolder(View view) { | |||||
| busStopIDTextView = view.findViewById(R.id.busStopID); | |||||
| busStopNameTextView = view.findViewById(R.id.busStopName); | |||||
| busStopLinesTextView = view.findViewById(R.id.routesThatStopHere); | |||||
| busStopLocaLityTextView = view.findViewById(R.id.busStopLocality); | |||||
| } | |||||
| } | } | ||||
| public StopAdapter(Context context, List<Stop> stops) { | public StopAdapter(Context context, List<Stop> stops) { | ||||
| super(context, row_layout, stops); | super(context, row_layout, stops); | ||||
| li = LayoutInflater.from(context); | li = LayoutInflater.from(context); | ||||
| } | } | ||||
| @NonNull | @NonNull | ||||
| @Override | @Override | ||||
| public View getView(int position, View convertView, @NonNull ViewGroup parent) { | public View getView(int position, View convertView, @NonNull ViewGroup parent) { | ||||
| ViewHolder vh; | ViewHolder vh; | ||||
| if(convertView == null) { | if(convertView == null) { | ||||
| convertView = li.inflate(row_layout, null); | convertView = li.inflate(row_layout, null); | ||||
| vh = new ViewHolder(); | vh = new ViewHolder(convertView); | ||||
| vh.busStopIDTextView = (TextView) convertView.findViewById(R.id.busStopID); | |||||
| vh.busStopNameTextView = (TextView) convertView.findViewById(R.id.busStopName); | |||||
| vh.busStopLinesTextView = (TextView) convertView.findViewById(R.id.routesThatStopHere); | |||||
| vh.busStopLocaLityTextView = (TextView) convertView.findViewById(R.id.busStopLocality); | |||||
| convertView.setTag(vh); | convertView.setTag(vh); | ||||
| } else { | } else { | ||||
| vh = (ViewHolder) convertView.getTag(); | vh = (ViewHolder) convertView.getTag(); | ||||
| } | } | ||||
| Stop stop = getItem(position); | Stop stop = getItem(position); | ||||
| vh.busStopIDTextView.setText(stop.ID); | vh.busStopIDTextView.setText(stop.ID); | ||||
| // NOTE: intentionally ignoring stop username in search results: if it's in the favorites, why are you searching for it? | // NOTE: intentionally ignoring stop username in search results: if it's in the favorites, why are you searching for it? | ||||
| 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 | ||||
| } | } | ||||
| /* | |||||
| // DEPRECATED CODE: ALWAYS USE BUS STOP ICON | |||||
| 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) { | if (stop.location == null) { | ||||
| vh.busStopLocaLityTextView.setVisibility(View.GONE); | vh.busStopLocaLityTextView.setVisibility(View.GONE); | ||||
| } else { | } else { | ||||
| vh.busStopLocaLityTextView.setText(stop.location); | vh.busStopLocaLityTextView.setText(stop.location); | ||||
| 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 | ||||
| } | } | ||||
| return convertView; | return convertView; | ||||
| } | } | ||||
| } | } | ||||
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