81 |
FavoritesMenu contextMenu = new FavoritesMenu(); |
FavoritesMenu contextMenu = new FavoritesMenu(); |
82 |
IntSet favorites = new IntSet(); |
IntSet favorites = new IntSet(); |
83 |
|
|
84 |
|
boolean showingFavorites = false; |
85 |
|
|
86 |
SharedPreferences prefs; |
SharedPreferences prefs; |
87 |
|
|
460 |
|
|
461 |
@Override |
@Override |
462 |
protected Void doInBackground(Void... params) { |
protected Void doInBackground(Void... params) { |
463 |
|
|
464 |
if (method.equals(LookupMethod.ByLocation)) |
switch (method) { |
465 |
|
case ByLocation: |
466 |
success = stationProvider.lookupStations(loc); |
success = stationProvider.lookupStations(loc); |
467 |
|
break; |
468 |
if (method.equals(LookupMethod.ByName)) |
case ByName: |
469 |
success = stationProvider.lookupStationsByName(name); |
success = stationProvider.lookupStationsByName(name); |
470 |
|
break; |
471 |
if (method.equals(LookupMethod.ByList)) |
case ByList: |
472 |
success = stationProvider.lookupStationsByIds(ids); |
success = stationProvider.lookupStationsByIds(ids); |
473 |
|
break; |
474 |
|
default: |
475 |
|
success = false; // not possible |
476 |
|
} |
477 |
|
|
478 |
|
|
479 |
Location dummy = new Location("gps"); |
Location dummy = new Location("gps"); |
480 |
List<StationBean> stations = stationProvider.getStations(); |
List<StationBean> stations = stationProvider.getStations(); |
483 |
String addr = lookupAddress(station.getLatitude(), station.getLongitude()); |
String addr = lookupAddress(station.getLatitude(), station.getLongitude()); |
484 |
station.setAddress(addr); |
station.setAddress(addr); |
485 |
|
|
486 |
if (method.equals(LookupMethod.ByName) || method.equals(LookupMethod.ByList)) { |
if (loc != null) { //only do the distance calc if we have a location |
487 |
dummy.setLatitude(station.getLatitude()); |
if (method.equals(LookupMethod.ByName) || method.equals(LookupMethod.ByList)) { |
488 |
dummy.setLongitude(station.getLongitude()); |
dummy.setLatitude(station.getLatitude()); |
489 |
station.setDistance( (int)loc.distanceTo(dummy) ); |
dummy.setLongitude(station.getLongitude()); |
490 |
|
station.setDistance( (int)loc.distanceTo(dummy) ); |
491 |
|
} |
492 |
|
} else { |
493 |
|
station.setDistance(0); |
494 |
} |
} |
495 |
} |
} |
496 |
|
|
502 |
super.onPostExecute(result); |
super.onPostExecute(result); |
503 |
dialog.dismiss(); |
dialog.dismiss(); |
504 |
|
|
505 |
|
//set title |
506 |
|
String title; |
507 |
|
switch (method) { |
508 |
|
case ByLocation: |
509 |
|
title = "Traininfo DK - Nearby stations"; |
510 |
|
break; |
511 |
|
case ByName: |
512 |
|
title = "Traininfo DK - Search"; |
513 |
|
break; |
514 |
|
case ByList: |
515 |
|
title = "Traininfo DK - Favorites"; |
516 |
|
break; |
517 |
|
default: |
518 |
|
title = "";//not possible |
519 |
|
} |
520 |
|
|
521 |
|
StationList.this.setTitle(title); |
522 |
|
//set title end |
523 |
|
|
524 |
if (success) { |
if (success) { |
525 |
if (stationProvider.getStations().size() == 0) |
if (stationProvider.getStations().size() == 0) |
526 |
MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?! |
MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?! |
527 |
stations = stationProvider.getStations(); |
stations = stationProvider.getStations(); |
528 |
adapter.setStations( stations ); |
adapter.setStations( stations ); |
529 |
|
|
530 |
|
showingFavorites = method.equals(LookupMethod.ByList); |
531 |
|
|
532 |
} else { //communication or parse errors |
} else { //communication or parse errors |
533 |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
586 |
favorites.add(stationID); |
favorites.add(stationID); |
587 |
Toast.makeText(StationList.this, "Station added", Toast.LENGTH_SHORT).show(); |
Toast.makeText(StationList.this, "Station added", Toast.LENGTH_SHORT).show(); |
588 |
} else { |
} else { |
589 |
|
|
590 |
favorites.remove(stationID); |
favorites.remove(stationID); |
591 |
Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show(); |
Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show(); |
592 |
|
|
593 |
|
if (showingFavorites) { |
594 |
|
stations.remove(selectedPosition); |
595 |
|
adapter.notifyDataSetChanged(); |
596 |
|
} |
597 |
} |
} |
598 |
Editor ed = prefs.edit(); |
Editor ed = prefs.edit(); |
599 |
ed.putString("favorites", favorites.toString()); |
ed.putString("favorites", favorites.toString()); |