/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/StationList.java
ViewVC logotype

Diff of /android/TrainInfo/src/dk/thoerup/traininfo/StationList.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 441 by torben, Sun Oct 11 07:23:35 2009 UTC revision 478 by torben, Wed Oct 28 08:40:32 2009 UTC
# Line 81  public class StationList extends ListAct Line 81  public class StationList extends ListAct
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                    
# Line 460  public class StationList extends ListAct Line 460  public class StationList extends ListAct
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();
# Line 477  public class StationList extends ListAct Line 483  public class StationList extends ListAct
483                                  String addr = lookupAddress(station.getLatitude(), station.getLongitude());                                  String addr = lookupAddress(station.getLatitude(), station.getLongitude());
484                                  station.setAddress(addr);                                  station.setAddress(addr);
485                                                                    
486                                    
487                                  if (method.equals(LookupMethod.ByName) || method.equals(LookupMethod.ByList)) {                                  if (method.equals(LookupMethod.ByName) || method.equals(LookupMethod.ByList)) {
488                                          dummy.setLatitude(station.getLatitude());                                          if (loc != null) { //only do the distance calc if we have a location
489                                          dummy.setLongitude(station.getLongitude());                                                  dummy.setLatitude(station.getLatitude());
490                                          station.setDistance( (int)loc.distanceTo(dummy) );                                                  dummy.setLongitude(station.getLongitude());
491                                                    station.setDistance( (int)loc.distanceTo(dummy) );
492                                            } else {
493                                                    station.setDistance(0);
494                                            }
495                                  }                                  }
496    
497                          }                                                                        }                                              
498                                                    
499                          return null;                          return null;
# Line 492  public class StationList extends ListAct Line 504  public class StationList extends ListAct
504                          super.onPostExecute(result);                          super.onPostExecute(result);
505                          dialog.dismiss();                          dialog.dismiss();
506                                                    
507                            //set title
508                            String title;
509                            switch (method) {
510                            case ByLocation:
511                                    title = "Traininfo DK - Nearby stations";
512                                    break;
513                            case ByName:
514                                    title = "Traininfo DK - Search";
515                                    break;
516                            case ByList:
517                                    title = "Traininfo DK - Favorites";
518                                    break;
519                            default:
520                                    title = "";//not possible                                      
521                            }                              
522                            
523                            StationList.this.setTitle(title);
524                            //set title end
525                            
526                          if (success) {                                                    if (success) {                          
527                                  if (stationProvider.getStations().size() == 0)                                  if (stationProvider.getStations().size() == 0)
528                                          MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?!                                          MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?!
529                                  stations = stationProvider.getStations();                                  stations = stationProvider.getStations();
530                                  adapter.setStations( stations );                                                                  adapter.setStations( stations );
531                                    
532                                    showingFavorites = method.equals(LookupMethod.ByList);                          
533                                                                    
534                          } else { //communication or parse errors                          } else { //communication or parse errors
535                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
# Line 555  public class StationList extends ListAct Line 588  public class StationList extends ListAct
588                                  favorites.add(stationID);                                  favorites.add(stationID);
589                                  Toast.makeText(StationList.this, "Station added", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, "Station added", Toast.LENGTH_SHORT).show();
590                          } else {                          } else {
591                                    
592                                  favorites.remove(stationID);                                  favorites.remove(stationID);
593                                  Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show();
594                                    
595                                    if (showingFavorites) {
596                                            stations.remove(selectedPosition);
597                                            adapter.notifyDataSetChanged();
598                                    }
599                          }                          }
600                          Editor ed = prefs.edit();                          Editor ed = prefs.edit();
601                          ed.putString("favorites", favorites.toString());                          ed.putString("favorites", favorites.toString());

Legend:
Removed from v.441  
changed lines
  Added in v.478

  ViewVC Help
Powered by ViewVC 1.1.20