39 |
import dk.thoerup.traininfo.provider.DepartureProvider; |
import dk.thoerup.traininfo.provider.DepartureProvider; |
40 |
import dk.thoerup.traininfo.provider.MetroProvider; |
import dk.thoerup.traininfo.provider.MetroProvider; |
41 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
42 |
|
|
43 |
|
import dk.thoerup.traininfo.util.FavoritesHelper; |
44 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
45 |
import dk.thoerup.traininfo.util.StationEntryCsv; |
import dk.thoerup.traininfo.util.StationEntryCsv; |
46 |
|
|
51 |
static final int MENU_NOTIFICATIONS = 101; |
static final int MENU_NOTIFICATIONS = 101; |
52 |
static final int MENU_METROMAP = 102; |
static final int MENU_METROMAP = 102; |
53 |
static final int MENU_TOGGLEDETAILS= 103; |
static final int MENU_TOGGLEDETAILS= 103; |
54 |
|
|
55 |
|
static final int MENU_FAVORITES_ADD = 104; |
56 |
|
static final int MENU_FAVORITES_REMOVE = 105; |
57 |
|
|
58 |
|
|
59 |
DepartureListAdapter adapter; |
DepartureListAdapter adapter; |
64 |
MetroProvider metro; |
MetroProvider metro; |
65 |
|
|
66 |
int selectedItemId; |
int selectedItemId; |
67 |
|
|
68 |
|
FavoritesHelper favorites; |
69 |
|
|
70 |
//DepartureBean currentDeparture; |
//DepartureBean currentDeparture; |
71 |
|
|
72 |
ProgressDialog pgDialog; |
ProgressDialog pgDialog; |
86 |
protected void onCreate(Bundle savedInstanceState) { |
protected void onCreate(Bundle savedInstanceState) { |
87 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
88 |
setContentView(R.layout.departurelist); |
setContentView(R.layout.departurelist); |
89 |
|
|
90 |
|
favorites = new FavoritesHelper(this); |
91 |
|
|
92 |
adapter = new DepartureListAdapter(this); |
adapter = new DepartureListAdapter(this); |
93 |
setListAdapter(adapter); |
setListAdapter(adapter); |
94 |
|
|
264 |
startMetroFetcher(); |
startMetroFetcher(); |
265 |
} else { |
} else { |
266 |
metroBean = (MetroBean) savedInstanceState.getSerializable("metro"); |
metroBean = (MetroBean) savedInstanceState.getSerializable("metro"); |
267 |
loadMetroData(); |
if (metroBean != null) { // Avoid reported NPE |
268 |
|
loadMetroData(); |
269 |
|
} else { |
270 |
|
startMetroFetcher(); |
271 |
|
} |
272 |
} |
} |
273 |
|
|
274 |
} else { |
} else { |
378 |
@Override |
@Override |
379 |
public boolean onPrepareOptionsMenu(Menu menu) { |
public boolean onPrepareOptionsMenu(Menu menu) { |
380 |
super.onPrepareOptionsMenu(menu); |
super.onPrepareOptionsMenu(menu); |
381 |
|
|
382 |
|
/////////////////////// |
383 |
|
|
384 |
MenuItem item = menu.findItem( MENU_NOTIFICATIONS ); |
MenuItem item = menu.findItem( MENU_NOTIFICATIONS ); |
385 |
boolean notifEnabled = hasNotifications(); |
boolean notifEnabled = hasNotifications(); |
386 |
item.setEnabled(notifEnabled); |
item.setEnabled(notifEnabled); |
387 |
|
|
388 |
|
////////////////////////// |
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
|
393 |
return true; |
return true; |
394 |
} |
} |
409 |
|
|
410 |
boolean notifEnabled = hasNotifications(); |
boolean notifEnabled = hasNotifications(); |
411 |
item.setEnabled(notifEnabled); |
item.setEnabled(notifEnabled); |
412 |
|
|
413 |
|
/////////////////////////////////////// |
414 |
|
if ( ! favorites.hasFavorite( this.station.getId() ) ) { |
415 |
|
item = menu.add(0, MENU_FAVORITES_ADD, 0, getString(dk.thoerup.traininfo.R.string.stationlist_addfavorite) ); |
416 |
|
} else { |
417 |
|
item = menu.add(0, MENU_FAVORITES_REMOVE, 0, getString(dk.thoerup.traininfo.R.string.stationlist_removefavorite) ); |
418 |
|
} |
419 |
|
item.setIcon(android.R.drawable.ic_menu_save); |
420 |
|
///////////////////////////// |
421 |
|
|
422 |
if (station.isMetro()) { |
if (station.isMetro()) { |
423 |
item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?! |
item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?! |
453 |
case MENU_TOGGLEDETAILS: |
case MENU_TOGGLEDETAILS: |
454 |
adapter.toggleShowDetails(); |
adapter.toggleShowDetails(); |
455 |
break; |
break; |
456 |
|
case MENU_FAVORITES_ADD: |
457 |
|
favorites.addFavorite( this.station.getId() ); |
458 |
|
Toast.makeText(this, getString(dk.thoerup.traininfo.R.string.stationlist_stationadded), Toast.LENGTH_SHORT).show(); |
459 |
|
break; |
460 |
|
case MENU_FAVORITES_REMOVE: |
461 |
|
favorites.removeFavorite( station.getId() ); |
462 |
|
Toast.makeText(this, getString(dk.thoerup.traininfo.R.string.stationlist_stationremoved), Toast.LENGTH_SHORT).show(); |
463 |
|
break; |
464 |
default: |
default: |
465 |
res = super.onOptionsItemSelected(item); |
res = super.onOptionsItemSelected(item); |
466 |
} |
} |