--- android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java 2011/05/03 20:30:12 1441 +++ android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java 2011/07/08 16:26:09 1562 @@ -14,10 +14,12 @@ import android.content.ActivityNotFoundException; import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Typeface; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.preference.PreferenceManager; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -38,6 +40,7 @@ import dk.thoerup.traininfo.provider.MetroProvider; import dk.thoerup.traininfo.provider.ProviderFactory; import dk.thoerup.traininfo.util.MessageBox; +import dk.thoerup.traininfo.util.StationEntryCsv; public class DepartureList extends ListActivity { @@ -77,8 +80,8 @@ setContentView(R.layout.departurelist); adapter = new DepartureListAdapter(this); - setListAdapter(adapter); - + setListAdapter(adapter); + Intent launchedBy = getIntent(); station = (StationEntry) launchedBy.getSerializableExtra("stationbean"); @@ -193,7 +196,9 @@ ProviderFactory.purgeOldEntries(); //cleanup before fetching more data - Log.e("Station", station.toCSV() ); + Log.e("Station", StationEntryCsv.toCSV(station) ); + + if (station.isMetro() == false) { metroBtn.setVisibility( View.GONE ); @@ -223,6 +228,16 @@ trainType = "STOG"; } + //Both enabled - use preferred from preferences + if (station.isRegional() == true && station.isStrain() == true ) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + trainType = prefs.getString("traintype", "REGIONAL"); //default value is gps + + if (trainType.equals("STOG") ) { + stogBtn.setBackgroundResource(R.drawable.custom_button_hilight); + regionalBtn.setBackgroundResource(R.drawable.custom_button); + } + } if (station.isRegional() == false && station.isStrain() == false) { @@ -263,6 +278,8 @@ } } + + boolean hasNotifications() { return (departures != null && departures.notifications.size() > 0); } @@ -298,6 +315,12 @@ protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); + //how can this happen ?? + if (departures == null || departures.entries == null || departures.entries.size() == 0) { + Toast.makeText(this, "No departures in list ?!?", Toast.LENGTH_LONG).show(); //TODO: translate + return; + } + selectedItemId = position; DepartureEntry dep = departures.entries.get(selectedItemId); @@ -339,6 +362,17 @@ @Override + public boolean onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + + MenuItem item = menu.findItem( MENU_NOTIFICATIONS ); + boolean notifEnabled = hasNotifications(); + item.setEnabled(notifEnabled); + + return true; + } + + @Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem item;