diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-01-27 13:35:13 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-01-27 13:35:13 +0000 |
commit | 75207a422e195ad26584d6a5d186dfd3e20f38f9 (patch) | |
tree | 6eba414bee018a68c5cd7d4f35d0ca14ce11504c /src | |
parent | da433913ec08182e9f14292021025d271e3c5dd6 (diff) | |
download | southamptonuniversitymap-75207a422e195ad26584d6a5d186dfd3e20f38f9.tar southamptonuniversitymap-75207a422e195ad26584d6a5d186dfd3e20f38f9.tar.gz |
More stuff.
Diffstat (limited to 'src')
-rw-r--r-- | src/net/cbaines/suma/BusRoute.java | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 71 | ||||
-rw-r--r-- | src/net/cbaines/suma/Direction.java | 31 | ||||
-rw-r--r-- | src/net/cbaines/suma/StopView.java | 4 |
4 files changed, 101 insertions, 7 deletions
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index 8c5d955..11ff798 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.List; import android.content.Context; +import android.util.Log; import com.j256.ormlite.android.apptools.OpenHelperManager; import com.j256.ormlite.dao.Dao; @@ -137,6 +138,7 @@ public class BusRoute { } catch (SQLException e) { e.printStackTrace(); } + Log.e("BusRoute", "Error moving in route"); return null; } diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 9d5c3c8..97492ec 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.Iterator; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; @@ -305,6 +306,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme // Handle item selection switch (item.getItemId()) { case R.id.menu_previous_stop: + Log.v(TAG, "Got a request for the previous stop"); if (visibleTimetable.size() != 0) { HashSet<BusRoute> routes = new HashSet<BusRoute>(); @@ -312,18 +314,77 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme routes.add(stop.bus.route); } - // TODO: Most of the following + Log.v(TAG, routes.size() + " routes in the visible timetable"); if (routes.size() == 1) { - try { - routes.iterator().next().moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), new Direction(), 1); - } catch (SQLException e) { - e.printStackTrace(); + 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 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); + Intent i = new Intent(this, BusStopActivity.class); + if (next.id == null) { + Log.e(TAG, "next.id == null"); + } + i.putExtra("busStopID", next.id); + i.putExtra("busStopName", next.description); + startActivity(i); + } catch (SQLException e) { + e.printStackTrace(); + } + } else { + // Show dialog + } + } else { + // Show dialog + } + } break; case R.id.menu_refresh_stop: if (mHandler != null) { // BusTimes are enabled diff --git a/src/net/cbaines/suma/Direction.java b/src/net/cbaines/suma/Direction.java index 1ea0fcd..0bc3396 100644 --- a/src/net/cbaines/suma/Direction.java +++ b/src/net/cbaines/suma/Direction.java @@ -28,4 +28,35 @@ public class Direction { public String toString() { return direction; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((direction == null) ? 0 : direction.hashCode()); + result = prime * result + ((route == null) ? 0 : route.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Direction other = (Direction) obj; + if (direction == null) { + if (other.direction != null) + return false; + } else if (!direction.equals(other.direction)) + return false; + if (route == null) { + if (other.route != null) + return false; + } else if (!route.equals(other.route)) + return false; + return true; + } } diff --git a/src/net/cbaines/suma/StopView.java b/src/net/cbaines/suma/StopView.java index d99c8ba..dc023aa 100644 --- a/src/net/cbaines/suma/StopView.java +++ b/src/net/cbaines/suma/StopView.java @@ -78,10 +78,10 @@ public class StopView extends LinearLayout implements OnClickListener { busDao.refresh(stop.bus); - if (stop.bus != null) { + if (stop.bus.id != null) { onClickMessage = "Bus " + stop.bus.toString() + " at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); } else { - onClickMessage = "Unidentified bus at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); + onClickMessage = "Unidentified bus (" + stop.bus.getName() + ") at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); } } catch (SQLException e) { e.printStackTrace(); |