--- android/TrainInfo/src/dk/thoerup/traininfo/WelcomeScreen.java 2011/07/08 12:24:48 1555 +++ android/TrainInfo/src/dk/thoerup/traininfo/WelcomeScreen.java 2011/07/09 09:45:40 1572 @@ -47,6 +47,8 @@ SharedPreferences prefs; + StationLoader stationLoader; + @Override public void onCreate(Bundle savedInstanceState) { @@ -93,7 +95,8 @@ Log.i("TrainInfo", "Last Load: " + last); if ( (now-last) > (14*24*60*60*1000) ) { - new StationLoader(osp).execute( (Void)null); + stationLoader = new StationLoader(osp); + stationLoader.execute( (Void)null); } else { boolean didLoad = false; @@ -110,7 +113,8 @@ } if (didLoad == false) { - new StationLoader(osp).execute( (Void)null); + stationLoader = new StationLoader(osp); + stationLoader.execute( (Void)null); } } @@ -122,6 +126,10 @@ @Override protected void onDestroy() { super.onDestroy(); + if (stationLoader != null) { + stationLoader.cancel(false); + } + ProviderFactory.purgeOldEntries(); //exiting application, do some cleanup } @@ -191,6 +199,19 @@ @Override public void onClick(View v) { + + StationProvider sp = ProviderFactory.getStationProvider(); + + if (sp instanceof OfflineStationProvider ) { + OfflineStationProvider osp = (OfflineStationProvider) sp; + + if (! osp.hasStations()) { + stationLoader = new StationLoader(osp); + stationLoader.execute( (Void)null); + return; + } + } + Intent intent = new Intent(WelcomeScreen.this, StationList.class); intent.putExtra("type", launchType); WelcomeScreen.this.startActivity(intent); @@ -222,13 +243,14 @@ return null; } + @Override protected void onPreExecute() { super.onPreExecute(); dlg = new ProgressDialog(WelcomeScreen.this); - dlg.setMessage( "Downloading stations list" );//TODO: translate - dlg.setCancelable(true); + dlg.setMessage( getText(R.string.welcome_downloadingstations) ); + dlg.setCancelable(false); dlg.show(); }