diff options
Diffstat (limited to 'src/net/cbaines/suma/BusStopActivity.java')
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index ab0a9b5..07dd45c 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -64,8 +64,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme final static String TAG = "BusTimeActivity"; - private boolean dataChanged; - private ListView busTimeList; private TextView busName; private TextView busID; @@ -106,10 +104,12 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.bustimes); + setContentView(R.layout.bus_stop_activity); final DatabaseHelper helper = getHelper(); + SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0); + instance = this; busStopID = getIntent().getExtras().getString("busStopID"); @@ -184,7 +184,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme busStop = busStopDao.queryForId(busStopID); busFavourite = (CheckBox) findViewById(R.id.favouriteCheckBox); - busFavourite.setChecked(busStop.favourite); + busFavourite.setChecked(favouritesPreferences.getBoolean(busStop.id, false)); busFavourite.setOnCheckedChangeListener(this); } catch (SQLException e) { @@ -247,7 +247,8 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme public void onPause() { if (mHandler != null) { // BusTimes are enabled mHandler.removeCallbacks(refreshData); - if (timetableTask != null) // Could happen if the handler has not created the timetableTask yet + if (timetableTask != null) // Could happen if the handler has not + // created the timetableTask yet timetableTask.cancel(true); Log.i(TAG, "Stoping refreshing timetable data"); } @@ -256,23 +257,18 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme } public void finish() { - if (dataChanged) { - getIntent().putExtra("busStopChanged", busStopID); - } - setResult(RESULT_OK, getIntent()); - super.finish(); } public void onCheckedChanged(CompoundButton button, boolean checked) { if (button.equals(busFavourite)) { - busStop.favourite = checked; - try { - busStopDao.update(busStop); - dataChanged = true; - } catch (SQLException e) { - e.printStackTrace(); + SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0); + + if (checked) { + favouritesPreferences.edit().putBoolean(busStop.id, true).commit(); + } else { + favouritesPreferences.edit().remove(busStop.id).commit(); } } else { Log.i(TAG, "Route radio button made " + checked); @@ -372,7 +368,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme e.printStackTrace(); } } - Log.i(TAG, "stops " + busStops); if (busStops.size() == 1) { |