--- android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java 2012/03/04 20:21:03 1708 +++ android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java 2012/03/06 11:02:04 1709 @@ -39,6 +39,8 @@ import dk.thoerup.traininfo.provider.DepartureProvider; import dk.thoerup.traininfo.provider.MetroProvider; import dk.thoerup.traininfo.provider.ProviderFactory; + +import dk.thoerup.traininfo.util.FavoritesHelper; import dk.thoerup.traininfo.util.MessageBox; import dk.thoerup.traininfo.util.StationEntryCsv; @@ -49,6 +51,9 @@ static final int MENU_NOTIFICATIONS = 101; static final int MENU_METROMAP = 102; static final int MENU_TOGGLEDETAILS= 103; + + static final int MENU_FAVORITES_ADD = 104; + static final int MENU_FAVORITES_REMOVE = 105; DepartureListAdapter adapter; @@ -59,6 +64,9 @@ MetroProvider metro; int selectedItemId; + + FavoritesHelper favorites; + //DepartureBean currentDeparture; ProgressDialog pgDialog; @@ -78,7 +86,9 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.departurelist); - + + favorites = new FavoritesHelper(this); + adapter = new DepartureListAdapter(this); setListAdapter(adapter); @@ -364,10 +374,17 @@ @Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); + + /////////////////////// MenuItem item = menu.findItem( MENU_NOTIFICATIONS ); boolean notifEnabled = hasNotifications(); item.setEnabled(notifEnabled); + + ////////////////////////// + + + return true; } @@ -388,6 +405,14 @@ boolean notifEnabled = hasNotifications(); item.setEnabled(notifEnabled); + + /////////////////////////////////////// + if ( ! favorites.hasFavorite( this.station.getId() ) ) { + item = menu.add(0, MENU_FAVORITES_ADD, 0, getString(dk.thoerup.traininfo.R.string.stationlist_addfavorite) ); + } else { + item = menu.add(0, MENU_FAVORITES_REMOVE, 0, getString(dk.thoerup.traininfo.R.string.stationlist_removefavorite) ); + } + ///////////////////////////// if (station.isMetro()) { item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?! @@ -423,6 +448,14 @@ case MENU_TOGGLEDETAILS: adapter.toggleShowDetails(); break; + case MENU_FAVORITES_ADD: + favorites.addFavorite( this.station.getId() ); + Toast.makeText(this, getString(dk.thoerup.traininfo.R.string.stationlist_stationadded), Toast.LENGTH_SHORT).show(); + break; + case MENU_FAVORITES_REMOVE: + favorites.removeFavorite( station.getId() ); + Toast.makeText(this, getString(dk.thoerup.traininfo.R.string.stationlist_stationremoved), Toast.LENGTH_SHORT).show(); + break; default: res = super.onOptionsItemSelected(item); }