diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-02-27 23:26:34 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-02-27 23:26:34 +0000 |
commit | a6dcb82b21325934ae3f4df9cfc5aad04d414653 (patch) | |
tree | 505d19676af1aca93683f2ab30556b323db69b56 /src/net/cbaines/suma/BusStopActivity.java | |
parent | 9b09f1286a8a003f0d24f745f648748cd3c2f2e2 (diff) | |
download | southamptonuniversitymap-a6dcb82b21325934ae3f4df9cfc5aad04d414653.tar southamptonuniversitymap-a6dcb82b21325934ae3f4df9cfc5aad04d414653.tar.gz |
Really cool uri stuff, needs more thinking about, but its really cool :)
Diffstat (limited to 'src/net/cbaines/suma/BusStopActivity.java')
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index bc8e22e..dbed3ee 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -75,9 +75,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme protected Timetable timetable; private Timetable visibleTimetable; - protected String busStopID; - private String busStopName; - private Dao<BusStop, String> busStopDao; private BusStop busStop; @@ -106,15 +103,29 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme super.onCreate(savedInstanceState); setContentView(R.layout.bus_stop_activity); + Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString()); + + String busStopID; + + if (getIntent().getDataString().startsWith("http://data")) { + + String[] uriParts = getIntent().getDataString().split("/"); + + busStopID = uriParts[uriParts.length - 1].replace(".html", ""); + + } else { + + String[] uriParts = getIntent().getDataString().split("/"); + + busStopID = uriParts[uriParts.length - 1]; + } + final DatabaseHelper helper = getHelper(); SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0); instance = this; - busStopID = getIntent().getExtras().getString("busStopID"); - busStopName = getIntent().getExtras().getString("busStopName"); - U1RouteRadioButton = (CheckBox) findViewById(R.id.radio_u1); U1NRouteRadioButton = (CheckBox) findViewById(R.id.radio_u1n); U2RouteRadioButton = (CheckBox) findViewById(R.id.radio_u2); @@ -128,6 +139,10 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme U9RouteRadioButton.setOnCheckedChangeListener(this); try { + Dao<BusStop, String> busStopDao = helper.getBusStopDao(); + + busStop = busStopDao.queryForId(busStopID); + Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao(); Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao(); @@ -201,7 +216,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme Log.i(TAG, "Got busstop id " + busStopID); - busName.setText(busStopName); + busName.setText(busStop.description); busID.setText(busStopID); } @@ -217,7 +232,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme refreshData = new Runnable() { public void run() { timetableTask = new GetTimetableTask(); - timetableTask.execute(busStopID); + timetableTask.execute(busStop.id); mHandler.postDelayed(refreshData, 20000); } }; @@ -296,7 +311,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance); newTimetable = DataManager - .getTimetable(instance, busStopID, sharedPrefs.getBoolean(MapActivity.UNI_LINK_BUS_TIMES, + .getTimetable(instance, busStop.id, sharedPrefs.getBoolean(MapActivity.UNI_LINK_BUS_TIMES, MapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs.getBoolean( MapActivity.NON_UNI_LINK_BUS_TIMES, MapActivity.NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT)); } catch (SQLException e) { @@ -319,7 +334,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme } protected void onPostExecute(Timetable newTimetable) { - Log.i(TAG, "Got timetable for " + busStopID); + Log.i(TAG, "Got timetable for " + busStop.id); if (newTimetable == null) { Log.i(TAG, "Its null"); @@ -355,9 +370,9 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme try { Set<BusStop> tmpStops; if (item.getItemId() == R.id.menu_next_stop) { - tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), 1); + tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStop.id), 1); } else { - tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), -1); + tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStop.id), -1); } for (BusStop busStop : tmpStops) { if (!busStops.contains(busStop)) { |