diff options
Diffstat (limited to 'src/net/cbaines/suma/DataManager.java')
-rw-r--r-- | src/net/cbaines/suma/DataManager.java | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index bdfedb5..99da450 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -890,8 +890,8 @@ public class DataManager { return stop; } - public static Stop getStop(Context context, Bus bus, int busStopRouteIndex) throws SQLException, ClientProtocolException, - IOException, JSONException { + public static Stop getStop(Context context, Bus bus, int busStopRouteIndex) throws SQLException, + ClientProtocolException, IOException, JSONException { if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); @@ -900,8 +900,53 @@ public class DataManager { if (busStopDao == null) busStopDao = helper.getBusStopDao(); + busRouteDao.refresh(bus.route); + BusRoute route = bus.route; + + List<BusStop> busStops = route.getRouteBusStops(context); + + BusStop busStop = busStops.get(busStopRouteIndex); + String file = getFileFromServer(busStopUrl + busStop.id + ".json"); + String direction = ""; + + if (route.id == 326) { // U1 + if (bus.direction.equals("E")) { + direction = "E"; + } else { + if (busStopRouteIndex >= 1 && busStopRouteIndex <= 36) { + direction = route.forwardDirection; + } else if (busStopRouteIndex >= 51 && busStopRouteIndex <= 88) { + direction = route.reverseDirection; + } else { + Log.e(TAG, "For U1 route, error with busStopRouteIndex " + busStopRouteIndex); + } + } + } else if (route.id == 468) { // U1N + // Nothing to do + } else if (route.id == 329) { // U2 + if (busStopRouteIndex >= 1 && busStopRouteIndex <= 22) { + direction = route.forwardDirection; + } else if (busStopRouteIndex >= 23 && busStopRouteIndex <= 43) { + direction = route.reverseDirection; + } else { + Log.e(TAG, "For U2 route, error with busStopRouteIndex " + busStopRouteIndex); + } + } else if (route.id == 327) { // U6 + if (busStopRouteIndex >= 1 && busStopRouteIndex <= 44) { + direction = route.forwardDirection; + } else if (busStopRouteIndex >= 45 && busStopRouteIndex <= 93) { + direction = route.reverseDirection; + } else { + Log.e(TAG, "For U6 route, error with busStopRouteIndex " + busStopRouteIndex); + } + } else if (route.id == 354) { // U9 + // Arggghh!!!! + } else { + Log.e(TAG, "Error, unrecognised route " + route.id); + } + JSONObject data = new JSONObject(file); JSONArray stopsArray = data.getJSONArray("stops"); @@ -921,7 +966,8 @@ public class DataManager { JSONObject stopObj = stopsArray.getJSONObject(stopNum); // Log.v(TAG, "stopObj: " + stopObj); - if (stopObj.has("vehicle") && stopObj.getString("vehicle").equals(bus.id)) { + if (stopObj.has("vehicle") && stopObj.getString("vehicle").equals(bus.id) + && stopObj.getString("name").equals(bus.route.code + direction)) { stop = getStop(context, stopObj, busRoutes, busStop, age); break; |