aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/BusStopActivity.java
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-01-29 23:46:01 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-01-29 23:46:01 +0000
commite78d1fa40d32a97018e2831fd0592d6b6c1b3d7e (patch)
treee8cd9065c2dc756a7357ebb8ee49cb21fbe41287 /src/net/cbaines/suma/BusStopActivity.java
parent75207a422e195ad26584d6a5d186dfd3e20f38f9 (diff)
downloadsouthamptonuniversitymap-e78d1fa40d32a97018e2831fd0592d6b6c1b3d7e.tar
southamptonuniversitymap-e78d1fa40d32a97018e2831fd0592d6b6c1b3d7e.tar.gz
Changed the icons, updated the database, and implemented more of the next/previous stop movement stuff, needs more work though.
Diffstat (limited to 'src/net/cbaines/suma/BusStopActivity.java')
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java76
1 files changed, 23 insertions, 53 deletions
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index 97492ec..699ec2d 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -209,6 +209,9 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
} else {
Log.i(TAG, "Displaying previous timetable");
displayTimetable(timetable);
+ if (System.currentTimeMillis() - timetable.fetchTime.getTime() > 20000) {
+ mHandler.post(refreshData);
+ }
}
} else {
@@ -304,9 +307,8 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
- switch (item.getItemId()) {
- case R.id.menu_previous_stop:
- Log.v(TAG, "Got a request for the previous stop");
+ if (item.getItemId() == R.id.menu_previous_stop || item.getItemId() == R.id.menu_next_stop) {
+ Log.v(TAG, "Got a request for the stop movement");
if (visibleTimetable.size() != 0) {
HashSet<BusRoute> routes = new HashSet<BusRoute>();
@@ -317,7 +319,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
Log.v(TAG, routes.size() + " routes in the visible timetable");
if (routes.size() == 1) {
- HashSet<Direction> directions = new HashSet<Direction>();
+ HashSet<String> directions = new HashSet<String>();
for (Stop stop : visibleTimetable) {
directions.add(stop.bus.direction);
@@ -325,55 +327,22 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
Log.v(TAG, directions.size() + " directions in the visible timetable");
- if (directions.size() == 1) {
+ if (directions.size() <= 1) {
try {
- BusStop previous = routes.iterator().next()
- .moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), directions.iterator().next(), 1);
- Intent i = new Intent(this, BusStopActivity.class);
- i.putExtra("busStopID", previous.id);
- i.putExtra("busStopName", previous.description);
- startActivity(i);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- } else {
- // Show dialog
- }
- } else {
- // Show dialog
- }
- }
- break;
- case R.id.menu_next_stop:
- Log.v(TAG, "Got a request for the next stop");
- if (visibleTimetable.size() != 0) {
- HashSet<BusRoute> routes = new HashSet<BusRoute>();
-
- for (Stop stop : visibleTimetable) {
- routes.add(stop.bus.route);
- }
-
- Log.v(TAG, routes.size() + " routes in the visible timetable");
-
- if (routes.size() == 1) {
- HashSet<Direction> directions = new HashSet<Direction>();
-
- for (Stop stop : visibleTimetable) {
- directions.add(stop.bus.direction);
- }
-
- Log.v(TAG, directions.size() + " directions in the visible timetable");
-
- if (directions.size() == 1) {
- try {
- BusStop next = routes.iterator().next()
- .moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), directions.iterator().next(), 1);
+ BusStop stop;
+ if (item.getItemId() == R.id.menu_next_stop) {
+ stop = routes.iterator().next()
+ .moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), directions.iterator().next(), 1);
+ } else {
+ stop = routes.iterator().next()
+ .moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), directions.iterator().next(), -1);
+ }
Intent i = new Intent(this, BusStopActivity.class);
- if (next.id == null) {
+ if (stop.id == null) {
Log.e(TAG, "next.id == null");
}
- i.putExtra("busStopID", next.id);
- i.putExtra("busStopName", next.description);
+ i.putExtra("busStopID", stop.id);
+ i.putExtra("busStopName", stop.description);
startActivity(i);
} catch (SQLException e) {
e.printStackTrace();
@@ -382,11 +351,13 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
// Show dialog
}
} else {
+ // if (all routes point to the same (next/previous) stop) {
+ // move to that stop
+ // else
// Show dialog
}
}
- break;
- case R.id.menu_refresh_stop:
+ } else if (item.getItemId() == R.id.menu_refresh_stop) {
if (mHandler != null) { // BusTimes are enabled
mHandler.removeCallbacks(refreshData);
timetableTask.cancel(true);
@@ -396,8 +367,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
} else {
// TODO: Toast here...
}
- break;
- default:
+ } else {
Log.e(TAG, "No known menu option selected");
return super.onOptionsItemSelected(item);
}