From 8e2005fa2650b142b89799249b07ea72bdbcc906 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 1 Mar 2012 18:12:21 +0000 Subject: Fixed route movement, now tested. --- AndroidManifest.xml | 4 ++-- res/values/strings.xml | 2 +- src/net/cbaines/suma/BusRoute.java | 38 ++++++++++++++++++-------------------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 09fd9e7..89ae86d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="9" + android:versionName="0.6 (alpha)" > About Version - 0.5 (alpha) + 0.6 (alpha) Copyright © 2012, Christopher Baines License diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index e57e49c..793cc24 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -65,8 +65,7 @@ public class BusRoute { String label; /** - * The direction the bus is travelling if it is moving through the route and - * sequence is increasing. + * The direction the bus is travelling if it is moving through the route and sequence is increasing. *
    *
  • U1 = A
  • *
  • U2 = B
  • @@ -77,8 +76,7 @@ public class BusRoute { String forwardDirection; /** - * The direction the bus is travelling if it is moving through the route and - * sequence is decreasing. + * The direction the bus is travelling if it is moving through the route and sequence is decreasing. *
      *
    • U1 = C
    • *
    • U2 = C
    • @@ -94,8 +92,7 @@ public class BusRoute { BusRoute() { } - public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, - boolean uniLink) { + public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, boolean uniLink) { this.id = id.intValue(); this.code = code; this.label = label; @@ -135,8 +132,8 @@ public class BusRoute { } /** - * Return the set of bus stops that can be thought of moveAmount away from - * the busStop. The method returns a set as + * Return the set of bus stops that can be thought of moveAmount away from the busStop. The method returns a set as for some + * movements, the destination stop is ambiguous. * * @param context * @param busStop @@ -165,6 +162,7 @@ public class BusRoute { List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); Collections.sort(routeStopsFound); + // Starting from 1, as the data does :( Set stopIndexs = new HashSet(); for (RouteStop routeStop : routeStopsFound) { @@ -193,18 +191,18 @@ public class BusRoute { busStops.add(busStopWanted); } else { Log.v(TAG, "stopIndex " + stopIndex); - int stopWanted = stopIndex + moveAmount; + int stopWanted = stopIndex + moveAmount; // This will end up as the sequence number of the wanted stop if (stopWanted < 1) { - stopWanted = routeStopsFound.size() - (Math.abs(stopWanted - 1) % routeStopsFound.size()); + stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); } Log.v(TAG, "stopWanted " + stopWanted); - busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); + BusStop wantedBusStop = routeStopsFound.get(stopWanted - 1).busStop; // Need the -1 as sequence starts at 1 + busStopDao.refresh(wantedBusStop); - Log.v(TAG, - "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); + Log.v(TAG, "Moving backwards " + (-1 * moveAmount) + " stops from " + busStop + " to " + wantedBusStop + + " in route " + this); - busStops.add(routeStopsFound.get(stopWanted).busStop); + busStops.add(wantedBusStop); } } @@ -381,8 +379,9 @@ public class BusRoute { } if (moveAmount > 0) { - Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" - + routeStopsFound.size() + ")"); + Log.v(TAG, + "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" + + routeStopsFound.size() + ")"); int stopWanted = stopIndex + moveAmount; if (stopWanted > routeStopsFound.size()) { Log.v(TAG, "Off the end of the route"); @@ -405,9 +404,8 @@ public class BusRoute { Log.v(TAG, "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); - Log.v(TAG, - "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); + Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " + + routeStopsFound.get(stopWanted).busStop + " in route " + this); return routeStopsFound.get(stopWanted).busStop; } -- cgit v1.2.3