--- android/TrainInfo/src/dk/thoerup/traininfo/WelcomeScreen.java 2011/10/26 12:15:52 1625 +++ android/TrainInfo/src/dk/thoerup/traininfo/WelcomeScreen.java 2011/11/25 09:16:29 1626 @@ -93,35 +93,35 @@ long last = prefs.getLong(stationsreload, 0); long now = System.currentTimeMillis(); Log.i("TrainInfo", "Last Load: " + last); - - if ( (now-last) > (14*24*60*60*1000) ) { - stationLoader = new StationLoader(osp); + + boolean didLoad = false; + + try { + didLoad = osp.loadStations(this); + } + catch (InvalidClassException e) { + Log.i("TrainInfo", "invalid class - do a new download of stationlist"); + } + catch (Exception e) { + Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show(); + Log.e("TrainInfo", "load error", e); + } + + if (didLoad == false) { + stationLoader = new StationLoader(osp, false); stationLoader.execute( (Void)null); } else { - - boolean didLoad = false; - - try { - didLoad = osp.loadStations(this); - } - catch (InvalidClassException e) { - Log.i("TrainInfo", "invalid class - do a new download of stationlist"); - } - catch (Exception e) { - Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show(); - Log.e("TrainInfo", "load error", e); - } - - if (didLoad == false) { - stationLoader = new StationLoader(osp); + if ( (now-last) > (14*24*60*60*1000) ) { //if we had a stations list but it was too old, load a new one silent + Log.i("TrainInfo", "Stationlist too old, do a silent download"); + stationLoader = new StationLoader(osp, true); stationLoader.execute( (Void)null); } } } } - - + + @Override protected void onDestroy() { @@ -159,7 +159,7 @@ case MENU_RELOAD: OfflineStationProvider osp = (OfflineStationProvider) ProviderFactory.getStationProvider(); - new StationLoader(osp).execute( (Void)null); + new StationLoader(osp, false).execute( (Void)null); break; default: @@ -206,7 +206,7 @@ OfflineStationProvider osp = (OfflineStationProvider) sp; if (! osp.hasStations()) { - stationLoader = new StationLoader(osp); + stationLoader = new StationLoader(osp, false); stationLoader.execute( (Void)null); return; } @@ -226,9 +226,11 @@ ProgressDialog dlg; OfflineStationProvider osp; String exMsg; + boolean silent; - public StationLoader(OfflineStationProvider osp) { + public StationLoader(OfflineStationProvider osp, boolean silent) { this.osp = osp; + this.silent = silent; } @Override @@ -238,7 +240,8 @@ succeeded = true; } catch (Exception e) { succeeded = false; - exMsg = e.getMessage(); + exMsg = e.getMessage(); + Log.e("TrainInfo", "download error", e); } return null; } @@ -247,26 +250,34 @@ @Override protected void onPreExecute() { super.onPreExecute(); + Log.i("TrainInfo", "StationLoader.onPreExecute() "); - dlg = new ProgressDialog(WelcomeScreen.this); - dlg.setMessage( getText(R.string.welcome_downloadingstations) ); - dlg.setCancelable(false); - dlg.show(); + if (silent == false) { + dlg = new ProgressDialog(WelcomeScreen.this); + dlg.setMessage( getText(R.string.welcome_downloadingstations) ); + dlg.setCancelable(false); + dlg.show(); + } } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); + Log.i("TrainInfo", "StationLoader.onPostExecute() "); - dlg.dismiss(); - dlg = null; + if (silent == false) { + dlg.dismiss(); + dlg = null; + } if (succeeded) { Editor edit = prefs.edit(); edit.putLong(stationsreload, System.currentTimeMillis() ); edit.commit(); } else { - Toast.makeText(WelcomeScreen.this, "Error " + exMsg, Toast.LENGTH_LONG).show(); + if (silent == false) { + Toast.makeText(WelcomeScreen.this, "Error " + exMsg, Toast.LENGTH_LONG).show(); + } } } }