aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/BusStopActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/BusStopActivity.java')
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index 0d4dea4..bc8e22e 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -59,13 +59,11 @@ import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
-public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener,
- Preferences, OnItemClickListener {
+public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences,
+ OnItemClickListener {
final static String TAG = "BusTimeActivity";
- private boolean dataChanged;
-
private ListView busTimeList;
private TextView busName;
private TextView busID;
@@ -110,6 +108,8 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
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) {
@@ -257,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);
@@ -300,10 +295,10 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
try {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance);
- newTimetable = DataManager.getTimetable(instance, busStopID, 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));
+ newTimetable = DataManager
+ .getTimetable(instance, busStopID, 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) {
errorMessage = "Error message regarding SQL?";
e.printStackTrace();