From e667851ae9869167677aa5e6e4c20707417cc687 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 15 Mar 2012 13:42:44 +0000 Subject: Progress with the Bus activiy. --- src/net/cbaines/suma/DataManager.java | 52 +++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'src/net/cbaines/suma/DataManager.java') 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 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; -- cgit v1.2.3