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.java71
1 files changed, 37 insertions, 34 deletions
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java
index f68c051..d632298 100644
--- a/src/net/cbaines/suma/BusActivity.java
+++ b/src/net/cbaines/suma/BusActivity.java
@@ -60,7 +60,7 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
private Context instance;
// BusStops and if they are being updated by the handler
- ArrayList<BusStop> busStops;
+ List<BusStop> busStops;
ArrayList<Boolean> busStopsActive;
private HashMap<BusStop, GetTimetableStopTask> tasks = new HashMap<BusStop, GetTimetableStopTask>();
@@ -89,14 +89,16 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
helper.getBusRouteDao().refresh(bus.route);
- List<BusStop> busStops = helper.getBusStopDao().queryForEq(BusStop.ID_FIELD_NAME, busStopID);
busStop = null;
- if (busStops.size() == 0) {
- Log.e(TAG, "BusStop " + busStopID + " not found!");
- } else if (busStops.size() == 1) {
- busStop = busStops.get(0);
- } else if (busStops.size() > 1) {
- Log.e(TAG, "Found more than one busStop? " + busStopID);
+ if (busStopID != null) {
+ List<BusStop> busStops = helper.getBusStopDao().queryForEq(BusStop.ID_FIELD_NAME, busStopID);
+ if (busStops.size() == 0) {
+ Log.e(TAG, "BusStop " + busStopID + " not found!");
+ } else if (busStops.size() == 1) {
+ busStop = busStops.get(0);
+ } else if (busStops.size() > 1) {
+ Log.e(TAG, "Found more than one busStop? " + busStopID);
+ }
}
U1RouteTextView = (TextView) findViewById(R.id.busActivityU1);
@@ -151,11 +153,12 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
e.printStackTrace();
}
- busStops = new ArrayList<BusStop>();
- busStops.add(busStop);
-
- busStopsActive = new ArrayList<Boolean>();
- busStopsActive.add(false);
+ busStops = bus.route.getRouteSection(instance, bus.direction);
+ Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus");
+ busStopsActive = new ArrayList<Boolean>(busStops.size());
+ for (int i = 0; i < busStops.size(); i++) {
+ busStopsActive.add(false);
+ }
if (bus.destination != null) {
Log.i(TAG, "Bus destination is " + bus.destination);
@@ -163,21 +166,15 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
Log.i(TAG, "Bus destination is null");
}
- for (int i = 0;; i++) {
- BusStop nextStop = bus.route.moveInRoute(instance, busStops.get(i), bus.direction, 1);
-
- if (nextStop.equals(busStop) || (bus.destination != null && bus.destination.equals(nextStop))) {
- break;
- }
-
- busStops.add(nextStop);
- busStopsActive.add(false);
-
- if (busStops.size() > 50) {
- Log.e(TAG, "Got more than 50 bus stops");
- break;
- }
- }
+ /*
+ * for (int i = 0;; i++) { BusStop nextStop = bus.route.moveInRoute(instance, busStops.get(i), bus.direction, 1);
+ *
+ * if (nextStop.equals(busStop) || (bus.destination != null && bus.destination.equals(nextStop))) { break; }
+ *
+ * busStops.add(nextStop); busStopsActive.add(false);
+ *
+ * if (busStops.size() > 50) { Log.e(TAG, "Got more than 50 bus stops"); break; } }
+ */
refreshData = new Runnable() {
@Override
@@ -189,20 +186,22 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
GetTimetableStopTask task = tasks.get(busStops.get(num));
if (stop.timeOfFetch == null || (stop.timeOfFetch.getTime() - System.currentTimeMillis()) > 20000) {
+ if (task != null) {
+ if (task.getStatus() == AsyncTask.Status.FINISHED) {
+ task = null;
+ }
+ }
+
if (task == null) {
task = new GetTimetableStopTask();
BusStop[] str = { stop.busStop };
task.execute(str);
- } else {
- if (task.getStatus() == AsyncTask.Status.FINISHED) {
- BusStop[] str = { stop.busStop };
- task.execute(str);
- }
+ tasks.put(stop.busStop, task);
}
}
}
}
- handler.postDelayed(refreshData, 20000);
+ handler.postDelayed(refreshData, 50000);
}
};
@@ -336,6 +335,10 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
} else {
adapter = new BusSpecificTimetableAdapter(this, visibleTimetable);
timetableView.setAdapter(adapter);
+ if (busStop != null) {
+ Log.i(TAG, "Moving to position of " + busStop.description + " which is " + busStops.indexOf(busStop));
+ timetableView.setSelection(busStops.indexOf(busStop));
+ }
}
busActivityContentLayout.setGravity(Gravity.TOP);
}