aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/BusActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/BusActivity.java')
-rw-r--r--src/net/cbaines/suma/BusActivity.java94
1 files changed, 31 insertions, 63 deletions
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java
index 85ed9f7..368d514 100644
--- a/src/net/cbaines/suma/BusActivity.java
+++ b/src/net/cbaines/suma/BusActivity.java
@@ -30,15 +30,15 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
final static String TAG = "BusActivity";
private TextView busIDTextView;
- private TextView busDestTextView;
+ // private TextView busDestTextView;
private TextView busContentMessage;
private LinearLayout busActivityContentLayout;
- /**
- * The bus this activity is focused on
- */
- private Bus bus;
+ private String busID;
+
+ private BusRoute busRoute;
+
/**
* The bus stop this activity is working from
*/
@@ -67,8 +67,6 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
setContentView(R.layout.bus_activity);
instance = this;
- String busID;
-
if (getIntent().getDataString().startsWith("http://data")) {
String[] uriParts = getIntent().getDataString().split("/");
busID = uriParts[uriParts.length - 1].replace(".html", "");
@@ -78,21 +76,10 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
}
String busStopID = getIntent().getExtras().getString("busStopID");
+ int busRouteID = getIntent().getExtras().getInt("busRouteID");
try {
final DatabaseHelper helper = getHelper();
- List<Bus> buses = helper.getBusDao().queryForEq(Bus.ID_FIELD_NAME, busID);
-
- bus = null;
- if (buses.size() == 0) {
- Log.e(TAG, "Bus " + busID + " not found!");
- } else if (buses.size() == 1) {
- bus = buses.get(0);
- } else if (buses.size() > 1) {
- Log.e(TAG, "Found more than one bus? " + busID);
- }
-
- helper.getBusRouteDao().refresh(bus.route);
busStop = null;
if (busStopID != null) {
@@ -107,53 +94,36 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
}
busIDTextView = (TextView) findViewById(R.id.busActivityBusID);
- busDestTextView = (TextView) findViewById(R.id.busActivityBusDestination);
+ // busDestTextView = (TextView) findViewById(R.id.busActivityBusDestination);
busContentMessage = (TextView) findViewById(R.id.busActivityMessage);
busActivityContentLayout = (LinearLayout) findViewById(R.id.busActivityContentLayout);
timetableView = (ListView) findViewById(R.id.busActivityTimes);
- if (bus.id != null) {
- // Log.i(TAG, "Bus id is not null (" + bus.id +
- // ") setting busIDTextView");
- getHelper().getBusRouteDao().refresh(bus.route);
- busIDTextView.setText(bus.id + " " + bus.route.label);
- } else {
- Log.w(TAG, "Bus id is null?");
- // Might not ever happen
- busIDTextView.setText("Unidentified");
- }
-
- if (bus.destinationString != null) {
- // Log.i(TAG, "Bus destination string is " +
- // bus.destinationString);
- busDestTextView
- .setText(getResources().getString(R.string.bus_activity_destination_label) + bus.destinationString);
- busDestTextView.setVisibility(View.VISIBLE);
- } else {
- // Log.i(TAG, "Bus destination string is null");
- busDestTextView.setText(getResources().getString(R.string.bus_activity_no_destination_message));
- busDestTextView.setVisibility(View.VISIBLE);
- }
-
- busStops = bus.route.getRouteBusStops(this);
+ // Log.i(TAG, "Bus id is not null (" + bus.id +
+ // ") setting busIDTextView");
+ busRoute = getHelper().getBusRouteDao().queryForId(busRouteID);
+ busIDTextView.setText(busID + " " + busRoute.label);
+
+ // if (bus.destinationString != null) {
+ // // Log.i(TAG, "Bus destination string is " +
+ // // bus.destinationString);
+ // busDestTextView
+ // .setText(getResources().getString(R.string.bus_activity_destination_label) + bus.destinationString);
+ // busDestTextView.setVisibility(View.VISIBLE);
+ // } else {
+ // // Log.i(TAG, "Bus destination string is null");
+ // busDestTextView.setText(getResources().getString(R.string.bus_activity_no_destination_message));
+ // busDestTextView.setVisibility(View.VISIBLE);
+ // }
+
+ busStops = busRoute.getRouteBusStops(this);
busStopRoutePositions = new ArrayList<Integer>();
for (int i = 0; i < busStops.size(); i++) {
busStopRoutePositions.add(i);
}
// Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus");
- if (bus.route.id == 326 && !bus.direction.equals("E")) {
- Log.i(TAG, "Removing extra U1 stops");
- for (int i = 35; i < 50; i++) {
- Log.i(TAG, "Removing " + busStops.get(35).description);
- busStops.remove(35);
- busStopRoutePositions.remove(35);
- }
- } else {
- Log.i(TAG, "Not removing extra U1 stops");
- }
-
refreshData = new Runnable() {
public void run() {
Log.v(TAG, "Refreshing data " + (System.currentTimeMillis() - timeOfLastRefresh));
@@ -192,10 +162,8 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
// Remove the old time from the timetable
synchronized (timetable) {
- timetable.set(
- index,
- new StopLoading(bus, busStops.get(index), timetable.get(index).arivalTime, new Date(System
- .currentTimeMillis() - 21000), false));
+ timetable.set(index, new StopLoading(timetable.get(index).bus, busStops.get(index),
+ timetable.get(index).arivalTime, new Date(System.currentTimeMillis() - 21000), false));
displayTimetable();
}
@@ -229,8 +197,8 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
for (int i = 0; i < busStops.size(); i++) {
// Add a loading stop, with a fetch time such that it will
// be fetched
- timetable
- .add(new StopLoading(bus, busStops.get(i), null, new Date(System.currentTimeMillis() - 21000), false));
+ timetable.add(new StopLoading(null, busStops.get(i), null, new Date(System.currentTimeMillis() - 21000),
+ false));
}
// Log.v(TAG, "Finished adding placeholder stops");
} else {
@@ -309,9 +277,9 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
try {
// Log.i(TAG, "Fetching stop for busStop " + busStop.description);
- stop = DataManager.getStop(instance, bus, busStopRoutePositions.get(busStopIndex));
+ stop = DataManager.getStop(instance, busID, busRoute, busStopRoutePositions.get(busStopIndex));
if (stop == null) {
- stop = new Stop(bus, busStop, null, new Date(System.currentTimeMillis()), false);
+ stop = new Stop(null, busStop, null, new Date(System.currentTimeMillis()), false);
}
// Log.i(TAG, "Finished fetching stop for busStop " + stop.busStop.description + " " + busStop.description);
} catch (SQLException e) {