/[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 725 by torben, Tue May 11 05:38:18 2010 UTC revision 1453 by torben, Thu May 5 15:11:00 2011 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfo;  package dk.thoerup.traininfo;
2    
3  import java.util.ArrayList;  import static dk.thoerup.traininfo.R.string.app_name;
4  import java.util.List;  import static dk.thoerup.traininfo.R.string.generic_cancel;
5    import static dk.thoerup.traininfo.R.string.generic_retry;
6    import static dk.thoerup.traininfo.R.string.generic_search;
7    import static dk.thoerup.traininfo.R.string.stationlist_accuracy;
8    import static dk.thoerup.traininfo.R.string.stationlist_addfavorite;
9    import static dk.thoerup.traininfo.R.string.stationlist_favorites;
10    import static dk.thoerup.traininfo.R.string.stationlist_fetcherror;
11    import static dk.thoerup.traininfo.R.string.stationlist_findbyname;
12    import static dk.thoerup.traininfo.R.string.stationlist_findingnearby;
13    import static dk.thoerup.traininfo.R.string.stationlist_gpsinfo;
14    import static dk.thoerup.traininfo.R.string.stationlist_gpstimeout;
15    import static dk.thoerup.traininfo.R.string.stationlist_latitude;
16    import static dk.thoerup.traininfo.R.string.stationlist_loadfavorites;
17    import static dk.thoerup.traininfo.R.string.stationlist_locationinfo;
18    import static dk.thoerup.traininfo.R.string.stationlist_longitude;
19    import static dk.thoerup.traininfo.R.string.stationlist_nearbystations;
20    import static dk.thoerup.traininfo.R.string.stationlist_nofavorites;
21    import static dk.thoerup.traininfo.R.string.stationlist_nolocation;
22    import static dk.thoerup.traininfo.R.string.stationlist_nolocationprovider;
23    import static dk.thoerup.traininfo.R.string.stationlist_nostations;
24    import static dk.thoerup.traininfo.R.string.stationlist_obtainedby;
25    import static dk.thoerup.traininfo.R.string.stationlist_removefavorite;
26    import static dk.thoerup.traininfo.R.string.stationlist_satellitecount;
27    import static dk.thoerup.traininfo.R.string.stationlist_search;
28    import static dk.thoerup.traininfo.R.string.stationlist_stationadded;
29    import static dk.thoerup.traininfo.R.string.stationlist_stationmap;
30    import static dk.thoerup.traininfo.R.string.stationlist_stationremoved;
31    import static dk.thoerup.traininfo.R.string.stationlist_stationsearch;
32    import static dk.thoerup.traininfo.R.string.stationlist_twocharmin;
33    import static dk.thoerup.traininfo.R.string.stationlist_waitforlocation;
34    
35    import java.util.ArrayList;
36    
37    import android.app.Activity;
38  import android.app.AlertDialog;  import android.app.AlertDialog;
39  import android.app.Dialog;  import android.app.Dialog;
40  import android.app.ListActivity;  import android.app.ListActivity;
# Line 17  import android.os.AsyncTask; Line 48  import android.os.AsyncTask;
48  import android.os.Bundle;  import android.os.Bundle;
49  import android.os.Handler;  import android.os.Handler;
50  import android.os.Message;  import android.os.Message;
   
51  import android.util.Log;  import android.util.Log;
52  import android.view.ContextMenu;  import android.view.ContextMenu;
53    import android.view.ContextMenu.ContextMenuInfo;
54  import android.view.LayoutInflater;  import android.view.LayoutInflater;
55  import android.view.Menu;  import android.view.Menu;
56  import android.view.MenuItem;  import android.view.MenuItem;
57  import android.view.View;  import android.view.View;
 import android.view.ContextMenu.ContextMenuInfo;  
58  import android.view.View.OnCreateContextMenuListener;  import android.view.View.OnCreateContextMenuListener;
59  import android.widget.AdapterView;  import android.widget.AdapterView;
60  import android.widget.EditText;  import android.widget.EditText;
61  import android.widget.ListView;  import android.widget.ListView;
62  import android.widget.Toast;  import android.widget.Toast;
63    import dk.thoerup.android.traininfo.common.StationBean;
64    import dk.thoerup.android.traininfo.common.StationEntry;
65  import dk.thoerup.traininfo.provider.ProviderFactory;  import dk.thoerup.traininfo.provider.ProviderFactory;
66  import dk.thoerup.traininfo.provider.StationProvider;  import dk.thoerup.traininfo.provider.StationProvider;
67  import dk.thoerup.traininfo.stationmap.GeoPair;  import dk.thoerup.traininfo.stationmap.GeoPair;
# Line 37  import dk.thoerup.traininfo.stationmap.S Line 69  import dk.thoerup.traininfo.stationmap.S
69  import dk.thoerup.traininfo.util.IntSet;  import dk.thoerup.traininfo.util.IntSet;
70  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
71    
 import static dk.thoerup.traininfo.R.string.*;  
   
72  public class StationList extends ListActivity  {  public class StationList extends ListActivity  {
         public static final int GOTLOCATION = 1001;  
         public static final int GOTSTATIONLIST = 1002;  
         public static final int NOPROVIDER = 1003;  
         public static final int LOCATIONFIXTIMEOUT = 1004;  
           
         public static final int OPTIONS_MAP = 2003;  
         public static final int OPTIONS_GPSINFO = 2004;  
73    
74                    
75            
76            public static final int OPTIONS_MAP = 103;
77            public static final int OPTIONS_GPSINFO = 104;
78                    
79          public static final int DLG_PROGRESS = 3001;          public static final int DLG_PROGRESS = 3001;
80          public static final int DLG_STATIONNAME = 3002;          public static final int DLG_STATIONNAME = 3002;
81                    
82            
83            public static final int GPS_TIMEOUT_MS = 15000; //how long are we willing to wait for gps fix -in milliseconds
84            
85            
86          static enum LookupMethod {          static enum LookupMethod {
87                  ByLocation,                  ByLocation,
88                  ByName,                  ByName,
# Line 68  public class StationList extends ListAct Line 97  public class StationList extends ListAct
97          FindStationsTask findStationsTask;          FindStationsTask findStationsTask;
98          StationsFetchedHandler stationsFetched = new StationsFetchedHandler();          StationsFetchedHandler stationsFetched = new StationsFetchedHandler();
99                    
100          GeoPair location = new GeoPair();          //GeoPair location = new GeoPair();
101            
102          boolean isRunning = false;          boolean isLaunchedforShortcut;
103          List<StationBean> stations = new ArrayList<StationBean>();  
104            StationBean stations = new StationBean();
105                    
106          StationProvider stationProvider = ProviderFactory.getStationProvider();          StationProvider stationProvider = ProviderFactory.getStationProvider();
107                                    
# Line 82  public class StationList extends ListAct Line 112  public class StationList extends ListAct
112    
113          WelcomeScreen.ListType listType;          WelcomeScreen.ListType listType;
114          SharedPreferences prefs;          SharedPreferences prefs;
115                                    
116          ///////////////////////////////////////////////////////////////////////////////////////////          ///////////////////////////////////////////////////////////////////////////////////////////
117          //Activity call backs          //Activity call backs
118                    
119          @SuppressWarnings("unchecked")  
120          @Override          @Override
121          public void onCreate(Bundle savedInstanceState) {          public void onCreate(Bundle savedInstanceState) {
122                  super.onCreate(savedInstanceState);                  super.onCreate(savedInstanceState);
# Line 99  public class StationList extends ListAct Line 129  public class StationList extends ListAct
129                  ListView lv = getListView();                  ListView lv = getListView();
130                  lv.setOnCreateContextMenuListener(contextMenu);                  lv.setOnCreateContextMenuListener(contextMenu);
131                                    
132                  locationLookup = new LocationLookup(this, stationsFetched);                  locationLookup = new LocationLookup(this);
133                                    
134    
135                  prefs = getSharedPreferences("TrainStation", 0);                  prefs = getSharedPreferences("TrainStation", 0);
# Line 111  public class StationList extends ListAct Line 141  public class StationList extends ListAct
141                  listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type");                  listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type");
142                  setTitle();                  setTitle();
143                                    
144                    isLaunchedforShortcut = getIntent().getBooleanExtra("shortcut", false);
145                    
146                    ProviderFactory.purgeOldEntries(); //cleanup before fetching more data
147                    
148                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
149    
150                                                    
151                          switch (listType) {                          switch (listType) {
152                          case ListNearest:                          case ListNearest:
153                                  startLookup();                                  startNearestLookup();
154                                  break;                                  break;
155                          case ListSearch:                          case ListSearch:                                
156                                  this.showDialogSafe(DLG_STATIONNAME);                                  showDialog(DLG_STATIONNAME);
157                                  break;                                  break;
158                          case ListFavorites:                          case ListFavorites:
159                                  startFavoriteLookup();                                  startFavoriteLookup();
# Line 129  public class StationList extends ListAct Line 163  public class StationList extends ListAct
163                          }                          }
164                                                    
165                  } else {                  } else {
166                          stations = (ArrayList<StationBean>) savedInstanceState.getSerializable("stations");                          stations = (StationBean) savedInstanceState.getSerializable("stations");
167                          adapter.setStations(stations);                          adapter.setStations(stations);
                         location = (GeoPair) savedInstanceState.getSerializable("location");  
168                  }                  }
169                                    
170          }          }
171            
172            
173    
174    
175    
176    
177            @Override
178            protected void onDestroy() {
179                    super.onDestroy();
180                    
181                    stationsFetched.removeMessages(0);
182                    
183                    
184                    if (locationLookup != null) {
185                            locationLookup.stopSearch();
186                    }
187                    if (findStationsTask != null) {
188                            findStationsTask.cancel(true);
189                    }              
190            }
191    
192            
193          protected void setTitle() {          protected void setTitle() {
194                  String dialogTitle = getResources().getString(app_name);                  String dialogTitle = getResources().getString(app_name);
195                  switch (listType) {                  switch (listType) {
# Line 155  public class StationList extends ListAct Line 210  public class StationList extends ListAct
210                                    
211          }          }
212                    
           
         /* these 3 dialogs helper functions are very rude and ugly hack  
          * to remove these auto-reported exceptions  
          * - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running?  
          * - java.lang.IllegalArgumentException: View not attached to window manager  
          */  
           
         public void showDialogSafe(int id) {  
                 try {  
                         showDialog(id);  
                 } catch (Exception e) {  
                         Log.e("StationList", "showDialog failed", e);  
                 }  
         }  
           
         public void dismissDialogSafe(int id) {  
                 try {  
                         dismissDialog(id);  
                 } catch (Exception e) {  
                         Log.e("StationList", "dismissDialog failed", e);  
                 }  
         }  
         public void dismissDialogSafe(Dialog dlg) {  
                 try {  
                         dlg.dismiss();  
                 } catch (Exception e) {  
                         Log.e("StationList", "dismissDialog failed", e);  
                 }  
         }  
           
         public void builderShowSafe(AlertDialog.Builder builder) {  
                 try {  
                         builder.show();  
                 } catch (Exception e) {  
                         Log.e("StationList", "builder.show() failed", e);  
                 }  
213                                    
         }  
         /* EOF rude and ugly dialog hack */  
           
   
214    
215      @Override      @Override
216      public void onSaveInstanceState(Bundle outState)      public void onSaveInstanceState(Bundle outState)
217      {      {
218          if (dialog != null && dialog.isShowing())          if (dialog != null && dialog.isShowing())
219                  dialog.dismiss();                  dialog.dismiss();
220          outState.putSerializable("stations", (ArrayList<StationBean>) stations);          outState.putSerializable("stations", (StationBean) stations);
         outState.putSerializable("location", location);  
221                    
222      }      }
223                    
# Line 217  public class StationList extends ListAct Line 231  public class StationList extends ListAct
231                  item.setIcon(android.R.drawable.ic_menu_mapmode);                  item.setIcon(android.R.drawable.ic_menu_mapmode);
232                                    
233                  item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo));                  item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo));
234                  item.setIcon(android.R.drawable.ic_menu_mapmode);                                item.setIcon(android.R.drawable.ic_menu_info_details);
235                    boolean hasLoc = (locationLookup.getLocation() != null);
236                    item.setEnabled(hasLoc);
237                                    
238                  return true;                  return true;
239          }          }
240            
241    
242    
243    
244          @Override          @Override
245          public boolean onOptionsItemSelected(MenuItem item) {          public boolean onOptionsItemSelected(MenuItem item) {
246                  boolean retval = true;                  boolean retval = true;
247    
248                  //TODO: Cleanup  
249                  switch (item.getItemId()) {                  switch (item.getItemId()) {
250                  case OPTIONS_MAP:                  case OPTIONS_MAP:
251                                                    
252                          Intent intent = new Intent(this,StationMapView.class);                          Intent intent = new Intent(this,StationMapView.class);
253                                                    
254                          ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>();                          ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>();
255                          for (StationBean st : stations ) {                          for (StationEntry st : stations.entries ) {
256                                  stationPoints.add( new GeoPair(st.getLatitude(), st.getLongitude(), st.getName()) );                                  stationPoints.add( new GeoPair(st.getLatitude(), st.getLongitude(), st.getName()) );
257                          }                          }
258                                                    
# Line 245  public class StationList extends ListAct Line 264  public class StationList extends ListAct
264                          Location loc = locationLookup.getLocation();                          Location loc = locationLookup.getLocation();
265                          StringBuffer message = new StringBuffer();                          StringBuffer message = new StringBuffer();
266                          message.append( getString(stationlist_locationinfo) ).append(":\n");                          message.append( getString(stationlist_locationinfo) ).append(":\n");
267                          if (loc != null) {                          
268                                  message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n");                          message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n");
269                                  message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n");                          message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n");
270                                  message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n");                          message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n");
271                                  message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n");                          message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n");
272                          } else {                                                  
                                 message.append( getString(stationlist_nolocation) );  
                         }                        
273                                                    
274                          MessageBox.showMessage(this, message.toString());                          MessageBox.showMessage(this, message.toString(), false);
275                          break;                          break;
276                  default:                  default:
277                          retval = super.onOptionsItemSelected(item);                          retval = super.onOptionsItemSelected(item);
# Line 313  public class StationList extends ListAct Line 330  public class StationList extends ListAct
330                                          dialog.dismiss();                                          dialog.dismiss();
331                                          String search = et.getText().toString().trim();                                          String search = et.getText().toString().trim();
332                                          if (search.length() >= 2) {                                          if (search.length() >= 2) {
333                                                  startNameSearch(search);                                                  startNameLookup(search);
334                                          } else {                                          } else {
335                                                  showMessageAndClose( getString(stationlist_twocharmin) );                                                  showMessageAndClose( getString(stationlist_twocharmin) );
336                                          }                                          }
# Line 352  public class StationList extends ListAct Line 369  public class StationList extends ListAct
369          protected void onListItemClick(ListView l, View v, int position, long id) {          protected void onListItemClick(ListView l, View v, int position, long id) {
370                  super.onListItemClick(l, v, position, id);                  super.onListItemClick(l, v, position, id);
371                                                                    
372                  StationBean station = stations.get(position);                  StationEntry station = stations.entries.get(position);
373                                    
374                  Intent intent = new Intent(this, DepartureList.class);                  if (isLaunchedforShortcut == true) {
375                  intent.putExtra("stationbean", station);                          Intent i = new Intent();
376                  startActivity(intent);                          i.putExtra("station", station);
377                            setResult(Activity.RESULT_OK, i);
378                            finish();
379                    } else {                
380                            Intent intent = new Intent(this, DepartureList.class);
381                            intent.putExtra("stationbean", station);
382                            startActivity(intent);
383                    }
384          }          }
385    
386          /////////////////////////////////////////////////////////////          /////////////////////////////////////////////////////////////
387          //          //
388    
389          public void startLookup() {          public void startNearestLookup() {
                 isRunning = true;                
390                  dialogMessage = getString( stationlist_waitforlocation );                  dialogMessage = getString( stationlist_waitforlocation );
391                  showDialogSafe(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
392                                    
393                  locationLookup.locateStations();                  locationLookup.locateStations();
394                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);                  stationsFetched.sendEmptyMessageDelayed(0, 500);
395          }          }
396                    
397          void startNameSearch(String name) {          void startNameLookup(String name) {
398                  dialogMessage = getString( stationlist_findbyname );                  dialogMessage = getString( stationlist_findbyname );
399                  showDialogSafe(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
400    
401                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
402                  findStationsTask.searchByName(name);                  findStationsTask.searchByName(name);
# Line 385  public class StationList extends ListAct Line 408  public class StationList extends ListAct
408                                    
409                  if (favorites.size() > 0) {                  if (favorites.size() > 0) {
410                          dialogMessage = getString( stationlist_loadfavorites );                          dialogMessage = getString( stationlist_loadfavorites );
411                          showDialogSafe(DLG_PROGRESS);                          showDialog(DLG_PROGRESS);
412    
413                          findStationsTask = new FindStationsTask();                          findStationsTask = new FindStationsTask();
414                          findStationsTask.searchByIds( favorites.toString() );                          findStationsTask.searchByIds( favorites.toString() );
# Line 400  public class StationList extends ListAct Line 423  public class StationList extends ListAct
423          void startLocatorTask()          void startLocatorTask()
424          {          {
425                  dialogMessage = getString( stationlist_findingnearby );                  dialogMessage = getString( stationlist_findingnearby );
426                  showDialogSafe(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);              
427                                    
428                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
429                  findStationsTask.searchByLocation( locationLookup.getLocation() );                  findStationsTask.searchByLocation( locationLookup.getLocation() );
# Line 415  public class StationList extends ListAct Line 438  public class StationList extends ListAct
438                  @Override                  @Override
439                  public void handleMessage(Message msg) {                  public void handleMessage(Message msg) {
440    
441                          switch (msg.what) {                          LocationLookup.LookupStates state = locationLookup.getState();
442    
443    
444                            switch (state) {
445                          case GOTLOCATION:                          case GOTLOCATION:
446                                  dismissDialogSafe(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);
447                                    
448                                  startLocatorTask();                                  startLocatorTask();
449                                  location = GeoPair.fromLocation( locationLookup.getLocation() );  
450                                                                    return;
                                 break;  
451    
452                          case NOPROVIDER:                          case NOPROVIDER:
453                                  dismissDialogSafe(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);
454                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider) );                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true );
455                                  break;                                  //StationList.this.finish();
456                          case LOCATIONFIXTIMEOUT:                                                                  return;
457                                  if (isRunning) {                          case IDLE:
458                                          locationLookup.stopSearch();                                  Log.e("TrainInfo", "How did this happen ???");
459                                          if (locationLookup.hasLocation()) {                                  dismissDialog(DLG_PROGRESS); // how did we get here ??
460                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );                                  return;
461                                          } else {                                                                                  
462                                                  dismissDialogSafe(DLG_PROGRESS);                          }
463                                                    
464                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                  
465                                                  builder.setMessage(  getString( stationlist_gpstimeout) );  
466                                                  builder.setCancelable(true);                          if (locationLookup.elapsedTime() >=  GPS_TIMEOUT_MS) {
467                                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {                                  dismissDialog(DLG_PROGRESS);
468                                                          public void onClick(DialogInterface dialog, int id) {  
469                                                                  dialog.dismiss();  
470                                                                  startLookup();                                  locationLookup.stopSearch();
471                                                                    
472                                                          }                                  if (locationLookup.hasLocation()) {
473                                                  });                                          startLocatorTask();
474                                                  builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() {                                  } else {                                                
475                                                          public void onClick(DialogInterface dialog, int id) {                                          AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
476                                                                  dialog.dismiss();                                          builder.setMessage(  getString( stationlist_gpstimeout) );
477                                                          }                                                                                                builder.setCancelable(true);
478                                                  });                                          builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
479                                                  builderShowSafe(builder); // builder.show()                                                  public void onClick(DialogInterface dialog, int id) {
480                                                            dialog.dismiss();
481                                                            startNearestLookup();
482    
483                                                    }
484                                            });
485                                            builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() {
486                                                    public void onClick(DialogInterface dialog, int id) {
487                                                            dialog.dismiss();
488                                                            StationList.this.finish(); // Close this Activity
489                                                    }                                                      
490                                            });
491                                            builder.show();
492    
                                         }  
493                                  }                                  }
494                                  break;                          } else {
495                                    if (locationLookup.hasGps()) {
496                                            int count = locationLookup.getSatCount();
497                                            String dialogMessage = getString( stationlist_waitforlocation ) + "\n" + getString( stationlist_satellitecount ) + ": " + count;
498                                            dialog.setMessage( dialogMessage );
499                                    }
500                                    this.sendEmptyMessageDelayed(0, 500);
501                          }                          }
502                          isRunning = false;                          
503                  }                  }
504          };          }
505    
506    
507    
508                    
509          class FindStationsTask extends AsyncTask<Void,Void,Void> {          class FindStationsTask extends AsyncTask<Void,Void,Void> {
510                                    
511                  LookupMethod method = LookupMethod.MethodNone;                  LookupMethod method = LookupMethod.MethodNone;
                 boolean success;  
512                  String name;                  String name;
513                  Location loc;                  Location loc;
514                  String ids;                  String ids;
# Line 500  public class StationList extends ListAct Line 543  public class StationList extends ListAct
543    
544                          switch (method) {                          switch (method) {
545                          case ByLocation:                          case ByLocation:
546                                  success = stationProvider.lookupStations(loc);                                  stations = stationProvider.lookupStationsByLocation(loc);
547                                  break;                                  break;
548                          case ByName:                          case ByName:
549                                  success = stationProvider.lookupStationsByName(name);                                  stations = stationProvider.lookupStationsByName(name);
550                                  break;                                  break;
551                          case ByList:                          case ByList:
552                                  success = stationProvider.lookupStationsByIds(ids);                                  stations = stationProvider.lookupStationsByIds(ids);
553                                  break;                                  break;
554                          default:                          default:
555                                  success = false; // not possible                                          stations = null; // not possible        
556                          }                          }
557                                                    
558                                                    
# Line 519  public class StationList extends ListAct Line 562  public class StationList extends ListAct
562                  @Override                  @Override
563                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
564                          super.onPostExecute(result);                          super.onPostExecute(result);
565                          dismissDialogSafe(dialog);                          dialog.dismiss();
566                                                    
567                                                    
568                          if (success) {                                                    if (stations != null) {                        
569                                  if (stationProvider.getStations().size() == 0) {                                  if (stations.entries.size() == 0) {
570                                          showMessageAndClose(getString(stationlist_nostations));                                          showMessageAndClose(getString(stationlist_nostations));
571                                  }                                  }
572                                  stations = stationProvider.getStations();  
573                                    StationList.this.getListView().invalidateViews();
574                                  adapter.setStations( stations );                                                                  adapter.setStations( stations );                                
575                                                                    
576                                    
577                          } else { //communication or parse errors                          } else { //communication or parse errors
578                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
579                                  builder.setMessage(getString(stationlist_nearbyerror));                                                          builder.setMessage(getString(stationlist_fetcherror));                          
580                                  builder.setCancelable(true);                                  builder.setCancelable(true);
581                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
582                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
# Line 551  public class StationList extends ListAct Line 596  public class StationList extends ListAct
596                                                          runner = new Runnable() {                                                          runner = new Runnable() {
597                                                                  @Override                                                                  @Override
598                                                                  public void run() {                                                                  public void run() {
599                                                                          startNameSearch( FindStationsTask.this.name );                                                                          startNameLookup( FindStationsTask.this.name );
600                                                                  }                                                                  }
601                                                          };                                                          };
602                                                          break;                                                          break;
# Line 571  public class StationList extends ListAct Line 616  public class StationList extends ListAct
616                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
617                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
618                                                  dialog.dismiss();                                                  dialog.dismiss();
619                                                    StationList.this.finish();
620                                          }                                                                                                }                                                      
621                                  });                                  });
622                                                                    
623                                  builderShowSafe(builder); // builder.show()                                  builder.show();
624                          }                          }
625                  }                  }
626          }          }
# Line 592  public class StationList extends ListAct Line 638  public class StationList extends ListAct
638                                                                                                    
639                          AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;                          AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
640                          selectedPosition = info.position;                          selectedPosition = info.position;
641                          int stationID = stations.get(selectedPosition).getId();                          int stationID = stations.entries.get(selectedPosition).getId();
642    
643                          if (!favorites.contains(stationID)) {                          if (!favorites.contains(stationID)) {
644                                  menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) );                                  menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) );
# Line 603  public class StationList extends ListAct Line 649  public class StationList extends ListAct
649                  }                  }
650                                    
651                  public void onContextItemSelected(MenuItem item) {                  public void onContextItemSelected(MenuItem item) {
652                          StationBean sb = stations.get(selectedPosition);                          StationEntry sb = stations.entries.get(selectedPosition);
653                                                    
654                          int stationID = sb.getId();                          int stationID = sb.getId();
655                          if (item.getItemId() == FAVORITES_ADD) {                          if (item.getItemId() == FAVORITES_ADD) {
# Line 616  public class StationList extends ListAct Line 662  public class StationList extends ListAct
662                                                                    
663                                                                    
664                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {
665                                          stations.remove(selectedPosition);                                          stations.entries.remove(selectedPosition);
666                                          adapter.notifyDataSetChanged();                                          adapter.notifyDataSetChanged();
667                                  }                                  }
668                          }                          }

Legend:
Removed from v.725  
changed lines
  Added in v.1453

  ViewVC Help
Powered by ViewVC 1.1.20