32 |
import android.app.ProgressDialog; |
import android.app.ProgressDialog; |
33 |
import android.content.DialogInterface; |
import android.content.DialogInterface; |
34 |
import android.content.Intent; |
import android.content.Intent; |
|
import android.content.SharedPreferences; |
|
|
import android.content.SharedPreferences.Editor; |
|
35 |
import android.location.Location; |
import android.location.Location; |
36 |
import android.os.Bundle; |
import android.os.Bundle; |
37 |
import android.os.Handler; |
import android.os.Handler; |
56 |
import dk.thoerup.traininfo.provider.StationProvider; |
import dk.thoerup.traininfo.provider.StationProvider; |
57 |
import dk.thoerup.traininfo.stationmap.GeoPair; |
import dk.thoerup.traininfo.stationmap.GeoPair; |
58 |
import dk.thoerup.traininfo.stationmap.StationMapView; |
import dk.thoerup.traininfo.stationmap.StationMapView; |
59 |
import dk.thoerup.traininfo.util.IntSet; |
import dk.thoerup.traininfo.util.FavoritesHelper; |
60 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
61 |
|
|
62 |
public class StationList extends ListActivity { |
public class StationList extends ListActivity { |
96 |
StationListAdapter adapter = null; |
StationListAdapter adapter = null; |
97 |
|
|
98 |
FavoritesMenu contextMenu = new FavoritesMenu(); |
FavoritesMenu contextMenu = new FavoritesMenu(); |
99 |
IntSet favorites = new IntSet(); |
FavoritesHelper favorites; |
100 |
|
|
101 |
WelcomeScreen.ListType listType; |
WelcomeScreen.ListType listType; |
|
SharedPreferences prefs; |
|
102 |
|
|
103 |
/////////////////////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////////////////////// |
104 |
//Activity call backs |
//Activity call backs |
108 |
public void onCreate(Bundle savedInstanceState) { |
public void onCreate(Bundle savedInstanceState) { |
109 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
110 |
setContentView(R.layout.stationlist); |
setContentView(R.layout.stationlist); |
111 |
|
|
112 |
|
favorites = new FavoritesHelper(this); |
113 |
|
|
114 |
listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type"); |
listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type"); |
115 |
|
|
121 |
|
|
122 |
locationLookup = new LocationLookup(this); |
locationLookup = new LocationLookup(this); |
123 |
|
|
|
|
|
|
prefs = getSharedPreferences("TrainStation", 0); |
|
|
String favoriteString = prefs.getString("favorites", ""); |
|
|
if (! favoriteString.equals("") ) { |
|
|
favorites.fromString(favoriteString); |
|
|
} |
|
124 |
|
|
125 |
setTitle(); |
setTitle(); |
126 |
|
|
395 |
|
|
396 |
public void startFavoriteLookup() { |
public void startFavoriteLookup() { |
397 |
|
|
398 |
if (favorites.size() > 0) { |
if (favorites.getSize() > 0) { |
399 |
|
|
400 |
stations = stationProvider.lookupStationsByIds( favorites.toString() ); |
stations = stationProvider.lookupStationsByIds( favorites.getString() ); |
401 |
getListView().invalidateViews(); |
getListView().invalidateViews(); |
402 |
adapter.setStations( stations ); |
adapter.setStations( stations ); |
403 |
|
|
506 |
selectedPosition = info.position; |
selectedPosition = info.position; |
507 |
int stationID = stations.entries.get(selectedPosition).getId(); |
int stationID = stations.entries.get(selectedPosition).getId(); |
508 |
|
|
509 |
if (!favorites.contains(stationID)) { |
if (!favorites.hasFavorite(stationID)) { |
510 |
menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) ); |
menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) ); |
511 |
} else { |
} else { |
512 |
menu.add(0, FAVORITES_REMOVE, 0, getString(stationlist_removefavorite) ); |
menu.add(0, FAVORITES_REMOVE, 0, getString(stationlist_removefavorite) ); |
519 |
|
|
520 |
int stationID = sb.getId(); |
int stationID = sb.getId(); |
521 |
if (item.getItemId() == FAVORITES_ADD) { |
if (item.getItemId() == FAVORITES_ADD) { |
522 |
favorites.add(stationID); |
favorites.addFavorite(stationID); |
523 |
Toast.makeText(StationList.this, getString(stationlist_stationadded), Toast.LENGTH_SHORT).show(); |
Toast.makeText(StationList.this, getString(stationlist_stationadded), Toast.LENGTH_SHORT).show(); |
524 |
} else { |
} else { |
525 |
|
|
526 |
favorites.remove(stationID); |
favorites.removeFavorite(stationID); |
527 |
Toast.makeText(StationList.this, getString(stationlist_stationremoved), Toast.LENGTH_SHORT).show(); |
Toast.makeText(StationList.this, getString(stationlist_stationremoved), Toast.LENGTH_SHORT).show(); |
528 |
|
|
529 |
|
|
532 |
adapter.notifyDataSetChanged(); |
adapter.notifyDataSetChanged(); |
533 |
} |
} |
534 |
} |
} |
|
Editor ed = prefs.edit(); |
|
|
ed.putString("favorites", favorites.toString()); |
|
|
ed.commit(); |
|
535 |
} |
} |
536 |
} |
} |
|
} |
|
537 |
|
} |