diff --git a/res/layout/entry_bus_line_passage.xml b/res/layout/entry_bus_line_passage.xml
index b3d579b..1736a80 100644
--- a/res/layout/entry_bus_line_passage.xml
+++ b/res/layout/entry_bus_line_passage.xml
@@ -1,49 +1,55 @@
+ android:textSize="21sp">
-
-
-
-
-
+ android:layout_alignTop="@+id/routeID"
+ android:layout_toEndOf="@id/routeID"
+ android:layout_toRightOf="@id/routeID"
+ android:orientation="vertical"
+ android:gravity="top|start">
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/entry_bus_stop.xml b/res/layout/entry_bus_stop.xml
index b7ceaae..58a203e 100644
--- a/res/layout/entry_bus_stop.xml
+++ b/res/layout/entry_bus_stop.xml
@@ -1,84 +1,84 @@
\ No newline at end of file
diff --git a/src/it/reyboz/bustorino/backend/Palina.java b/src/it/reyboz/bustorino/backend/Palina.java
index 3d207a8..65920a3 100644
--- a/src/it/reyboz/bustorino/backend/Palina.java
+++ b/src/it/reyboz/bustorino/backend/Palina.java
@@ -1,217 +1,218 @@
/*
BusTO (backend components)
Copyright (C) 2016 Ludovico Pavesi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
package it.reyboz.bustorino.backend;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Iterator;
/**
* Timetable for multiple routes.
*
* Apparently "palina" and a bunch of other terms can't really be translated into English.
* Not in a way that makes sense and keeps the code readable, at least.
*/
public class Palina {
private ArrayList routes;
public Palina() {
this.routes = new ArrayList<>();
}
/**
* Adds a route to the timetable.
*
* @param routeID name
* @param destinazione end of line\terminus (underground stations have the same ID for both directions)
* @return array index for this route
+ * @see RouteInternal
*/
public int addRoute(String routeID, String destinazione) {
this.routes.add(new RouteInternal(routeID, destinazione));
return this.routes.size() - 1; // last inserted element and pray that direct access to ArrayList elements really is direct
}
/**
* Adds a timetable entry to a route.
*
* @param TimeGTT time in GTT format (e.g. "11:22*")
* @param arrayIndex position in the array for this route (returned by addRoute)
*/
public void addPassaggio(String TimeGTT, int arrayIndex) {
this.routes.get(arrayIndex).addPassaggio(TimeGTT);
}
/**
* Clears a route timetable (or creates an empty route) and returns its index
*
* @param routeID name
* @param destinazione end of line\terminus
* @return array index for this route
*/
public int updateRoute(String routeID, String destinazione) {
int s = this.routes.size();
RouteInternal r;
for(int i = 0; i < s; i++) {
r = routes.get(i);
if(r.name.compareTo(routeID) == 0 && r.destinazione.compareTo(destinazione) == 0) {
// TODO: capire se è possibile che ci siano stessa linea e stessa destinazione su 2 righe diverse del sito e qui una sovrascrive l'altra (probabilmente no)
r.updateFlag();
r.deletePassaggio();
return i;
}
}
return this.addRoute(routeID, destinazione);
}
/**
* Deletes routes marked as "not updated" (= disappeared from the GTT website\API\whatever).
* Sets all remaining routes to "not updated" because that's how this contraption works.
*/
public void finishUpdatingRoutes() {
RouteInternal r;
for(Iterator itr = this.routes.iterator(); itr.hasNext(); ) {
r = itr.next();
if(r.unupdateFlag()) {
itr.remove();
}
}
}
/**
* Gets the current timetable for a route. Returns null if the route doesn't exist.
* This is slower than queryRouteByIndex.
*
* @return timetable (passaggi)
*/
public List queryRoute(String routeID) {
for(RouteInternal route : this.routes) {
if(routeID.equals(route.name)) {
return route.getPassaggi();
}
}
return null;
}
/**
* Gets the current timetable for this route, from its index in the array.
*
* @return timetable (passaggi)
*/
public List queryRouteByIndex(int index) {
return this.routes.get(index).getPassaggi();
}
// TODO: ponder on the usefulness/uselessness of having separate Route and RouteInternal classes just for this method
/**
* Gets timetables for every route.
*
* @return routes and timetables.
*/
public List queryAllRoutes() {
List list = new LinkedList<>();
for(RouteInternal r : this.routes) {
list.add(new Route(r.name, r.destinazione, r.passaggi));
}
return list;
}
/**
* Route with terminus (destinazione) and timetables (passaggi), internal implementation.
*
* Contains mostly the same data as the Route public class, but methods are quite different and extending Route doesn't really work, here.
*/
private final class RouteInternal {
public final String name;
public final String destinazione;
private boolean updated;
private List passaggi; // TODO: capire se con "final" si intende che copia la lista ogni volta che la modifico, o che non modifico la reference ma la lista è modificabile
/**
* Creates a new route and marks it as "updated", since it's new.
*
* @param routeID name
* @param destinazione end of line\terminus
*/
public RouteInternal(String routeID, String destinazione) {
this.name = routeID;
this.destinazione = destinazione;
this.passaggi = new LinkedList<>();
this.updated = true;
}
/**
* Adds a time (passaggio) to the timetable for this route
*
* @param TimeGTT time in GTT format (e.g. "11:22*")
*/
public void addPassaggio(String TimeGTT) {
this.passaggi.add(new Passaggio(TimeGTT));
}
/**
* Deletes al times (passaggi) from the timetable.
*/
public void deletePassaggio() {
this.passaggi = new LinkedList<>();
this.updated = true;
}
/**
* Sets the "updated" flag to false.
*
* @return previous state
*/
public boolean unupdateFlag() {
if(this.updated) {
this.updated = false;
return true;
} else {
return false;
}
}
/**
* Sets the "updated" flag to true.
*
* @return previous state
*/
public boolean updateFlag() {
if(this.updated) {
return true;
} else {
this.updated = true;
return false;
}
}
/**
* Exactly what it says on the tin.
*
* @return times from the timetable
*/
public List getPassaggi() {
return this.passaggi;
}
}
}
\ No newline at end of file
diff --git a/src/it/reyboz/bustorino/lab/adapters/AdapterBusLines.java b/src/it/reyboz/bustorino/lab/adapters/AdapterBusLines.java
index 45e5989..7bdd1a3 100644
--- a/src/it/reyboz/bustorino/lab/adapters/AdapterBusLines.java
+++ b/src/it/reyboz/bustorino/lab/adapters/AdapterBusLines.java
@@ -1,77 +1,77 @@
/*
BusTO - Arrival times for Turin public transports.
Copyright (C) 2014 Valerio Bozzolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
package it.reyboz.bustorino.lab.adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import it.reyboz.bustorino.R;
import it.reyboz.bustorino.lab.GTTSiteSucker.BusLine;
/**
* ListView Adapter for BusLine[].
*
* Thanks to Framentos developers for the guide:
* http://www.framentos.com/en/android-tutorial/2012/07/16/listview-in-android-using-custom-listadapter-and-viewcache/#
*
* @author Valerio Bozzolan
*/
public class AdapterBusLines extends ArrayAdapter {
private LayoutInflater layoutInflater;
private Context context;
private int resource;
public AdapterBusLines(Context context, int resource, BusLine busLines[]) {
super(context, resource, busLines);
layoutInflater = LayoutInflater.from(context);
this.context = context;
this.resource = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Create a new view of my layout and inflate it in the row
convertView = layoutInflater.inflate(resource, null);
// Extract the busLine object to show
BusLine busLine = getItem( position );
// Take the TextView from layout and set the busLine name
- TextView busLineIconTextView = (TextView) convertView.findViewById(R.id.busLineIcon);
+ TextView busLineIconTextView = (TextView) convertView.findViewById(R.id.routeID);
busLineIconTextView.setText(busLine.getBusLineName());
// Vehicle icon
TextView busLineVehicleIcon = (TextView) convertView.findViewById(R.id.vehicleIcon);
// Take the TextView from layout and set the BusLine's passages
- TextView busLinePassagesTextView = (TextView) convertView.findViewById(R.id.busLineNames);
+ TextView busLinePassagesTextView = (TextView) convertView.findViewById(R.id.routeTimetable);
String timePassages = busLine.getTimePassagesString();
if(timePassages != null) {
busLinePassagesTextView.setText(timePassages);
} else {
busLinePassagesTextView.setText(R.string.no_passages);
busLineVehicleIcon.setVisibility(View.INVISIBLE);
}
return convertView;
}
}
diff --git a/src/it/reyboz/bustorino/lab/adapters/AdapterBusStops.java b/src/it/reyboz/bustorino/lab/adapters/AdapterBusStops.java
index 4ba02c5..e95d1b8 100644
--- a/src/it/reyboz/bustorino/lab/adapters/AdapterBusStops.java
+++ b/src/it/reyboz/bustorino/lab/adapters/AdapterBusStops.java
@@ -1,96 +1,96 @@
/*
BusTO - Arrival times for Turin public transports.
Copyright (C) 2014 Valerio Bozzolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
package it.reyboz.bustorino.lab.adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import it.reyboz.bustorino.R;
import it.reyboz.bustorino.lab.GTTSiteSucker.BusLine;
import it.reyboz.bustorino.lab.GTTSiteSucker.BusStop;
/**
* ListView Adapter for BusStop[].
*
* @author Valerio Bozzolan
*/
public class AdapterBusStops extends ArrayAdapter {
private LayoutInflater layoutInflater;
private Context context;
private int resource;
public AdapterBusStops(Context context, int resource, BusStop busStops[]) {
super(context, resource, busStops);
layoutInflater = LayoutInflater.from(context);
this.context = context;
this.resource = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Create a new view of my layout and inflate it in the row
convertView = layoutInflater.inflate(resource, null);
// Extract the busStop object to show
BusStop busStop = getItem( position );
// Take the TextView from layout and set the BusStop ID
TextView busStopIDTextView = (TextView) convertView.findViewById(R.id.busStopID);
busStopIDTextView.setText(busStop.getBusStopID());
// Take the TextView from layout and set the busStop name
TextView busStopNameTextView = (TextView) convertView.findViewById(R.id.busStopName);
if(busStop.getBusStopUsername() != null) {
busStopNameTextView.setText(busStop.getBusStopUsername());
} else {
busStopNameTextView.setText(busStop.getBusStopName());
}
// Vehicle icon
TextView busLineVehicleIcon = (TextView) convertView.findViewById(R.id.vehicleIcon);
// Take the TextView from layout and set the busStop locality
- TextView busStopLinesTextView = (TextView) convertView.findViewById(R.id.busLineNames);
+ TextView busStopLinesTextView = (TextView) convertView.findViewById(R.id.routeTimetable);
if(busStop.getBusLines() != null) {
String busLines = "";
for(BusLine busLine: busStop.getBusLines()) {
if(busLines.length() > 0) {
busLines += ", ";
}
busLines += busLine.getBusLineName();
}
busStopLinesTextView.setText(busLines);
} else {
busStopLinesTextView.setVisibility(View.GONE);
busLineVehicleIcon.setVisibility(View.INVISIBLE);
}
TextView busStopLocaLityTextView = (TextView) convertView.findViewById(R.id.busStopLocality);
if (busStop.getBusStopLocality() != null) {
busStopLocaLityTextView.setText(busStop.getBusStopLocality());
} else {
busStopLocaLityTextView.setVisibility(View.GONE);
}
return convertView;
}
}
diff --git a/src/it/reyboz/bustorino/middleware/PalinaAdapter.java b/src/it/reyboz/bustorino/middleware/PalinaAdapter.java
index 95d302c..86e1ffd 100644
--- a/src/it/reyboz/bustorino/middleware/PalinaAdapter.java
+++ b/src/it/reyboz/bustorino/middleware/PalinaAdapter.java
@@ -1,112 +1,122 @@
/*
BusTO - Arrival times for Turin public transports.
Copyright (C) 2014 Valerio Bozzolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
package it.reyboz.bustorino.middleware;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
+import java.util.Objects;
import it.reyboz.bustorino.R;
import it.reyboz.bustorino.backend.Palina;
import it.reyboz.bustorino.backend.Passaggio;
import it.reyboz.bustorino.backend.Route;
/**
* This once was a ListView Adapter for BusLine[].
*
* Thanks to Framentos developers for the guide:
* http://www.framentos.com/en/android-tutorial/2012/07/16/listview-in-android-using-custom-listadapter-and-viewcache/#
*
* @author Valerio Bozzolan
* @author Ludovico Pavesi
*/
public class PalinaAdapter extends ArrayAdapter {
private LayoutInflater li;
private static int row_layout = R.layout.entry_bus_line_passage;
+ private static final int busIcon = R.drawable.bus;
+ private static final int subwayIcon = R.drawable.subway;
+ //private static final int tramIcon = R.drawable.tram;
+ //private static final int cityIcon = R.drawable.city;
// hey look, a pattern!
static class ViewHolder {
- TextView busLineIconTextView;
- TextView busLineVehicleIcon;
- TextView busLinePassagesTextView;
+ TextView rowStopIcon;
+ TextView rowRouteDestination;
+ TextView rowRouteTimetable;
}
public PalinaAdapter(Context context, Palina p) {
// TODO: find a more efficient way if there's one
super(context, row_layout, p.queryAllRoutes());
li = LayoutInflater.from(context);
}
/**
* Some parts taken from the AdapterBusLines class.
* Some parts inspired by these enlightening tutorials:
* http://www.simplesoft.it/android/guida-agli-adapter-e-le-listview-in-android.html
* https://www.codeofaninja.com/2013/09/android-viewholder-pattern-example.html
* And some other bits and bobs TIRATI FUORI DAL NULLA CON L'INTUIZIONE INTELLETTUALE PERCHÉ
* SEMBRA CHE NESSUNO ABBIA LA MINIMA IDEA DI COME FUNZIONA UN ADAPTER SU ANDROID.
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder vh;
// TODO: determine why this is called twice with null and twice with a convertView, to display 2 rows.
if(convertView == null) {
// INFLATE!
// setting a parent here is not supported and causes a fatal exception, apparently.
convertView = li.inflate(row_layout, null);
// STORE TEXTVIEWS!
vh = new ViewHolder();
- vh.busLineIconTextView = (TextView) convertView.findViewById(R.id.busLineIcon);
- vh.busLineVehicleIcon = (TextView) convertView.findViewById(R.id.vehicleIcon);
- vh.busLinePassagesTextView = (TextView) convertView.findViewById(R.id.busLineNames);
+ vh.rowStopIcon = (TextView) convertView.findViewById(R.id.routeID);
+ vh.rowRouteDestination = (TextView) convertView.findViewById(R.id.routeDestination);
+ vh.rowRouteTimetable = (TextView) convertView.findViewById(R.id.routeTimetable);
- // STORE VIEWHOLDER IN\ON\OVER\UNDER\ABOVE\BESIDES THE VIEW!
+ // STORE VIEWHOLDER IN\ON\OVER\UNDER\ABOVE\BESIDE THE VIEW!
convertView.setTag(vh);
} else {
// RECOVER THIS STUFF!
vh = (ViewHolder) convertView.getTag();
}
Route route = getItem(position);
- // Take the TextView from layout and set the busLine name
- // TODO: pezza temporanea da sistemare
- vh.busLineIconTextView.setText(route.name + " > " + route.destinazione);
+ vh.rowStopIcon.setText(route.name);
+ vh.rowRouteDestination.setText(route.destinazione);
+
+ // TODO: decide if we really need\want this
+ if(route.name.equals("METRO") || route.name.equals("FTC") || route.name.equals("CAN")) {
+ vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(subwayIcon, 0, 0, 0);
+ } else {
+ vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(busIcon, 0, 0, 0);
+ }
List passaggi = route.passaggi;
if(passaggi.size() == 0) {
- vh.busLinePassagesTextView.setText(R.string.no_passages);
- vh.busLineVehicleIcon.setVisibility(View.INVISIBLE);
+ vh.rowRouteTimetable.setText(R.string.no_passages);
} else {
String resultString = "";
for(Passaggio passaggio : passaggi) {
// "+" calls concat() and some other stuff internally, this should be faster
resultString = resultString.concat(passaggio.toString()).concat(" ");
}
- vh.busLinePassagesTextView.setText(resultString);
+ vh.rowRouteTimetable.setText(resultString);
}
return convertView;
}
}