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

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

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

revision 1625 by torben, Wed Aug 31 20:23:36 2011 UTC revision 1626 by torben, Fri Nov 25 09:16:29 2011 UTC
# Line 93  public class WelcomeScreen extends Activ Line 93  public class WelcomeScreen extends Activ
93                          long last = prefs.getLong(stationsreload, 0);                          long last = prefs.getLong(stationsreload, 0);
94                          long now = System.currentTimeMillis();                          long now = System.currentTimeMillis();
95                          Log.i("TrainInfo", "Last Load: " + last);                          Log.i("TrainInfo", "Last Load: " + last);
96                            
97                          if ( (now-last) > (14*24*60*60*1000) ) {                          boolean didLoad = false;
98                                  stationLoader = new StationLoader(osp);  
99                            try {
100                                    didLoad = osp.loadStations(this);
101                            }                                                                                              
102                            catch (InvalidClassException e) {
103                                    Log.i("TrainInfo", "invalid class - do a new download of stationlist");
104                            }
105                            catch (Exception e) {
106                                    Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
107                                    Log.e("TrainInfo", "load error", e);
108                            }
109    
110                            if (didLoad == false) {                                
111                                    stationLoader = new StationLoader(osp, false);
112                                  stationLoader.execute( (Void)null);                                  stationLoader.execute( (Void)null);
113                          } else {                          } else {
114                                                            if ( (now-last) > (14*24*60*60*1000) ) { //if we had a stations list but it was too old, load a new one silent
115                                  boolean didLoad = false;                                          Log.i("TrainInfo", "Stationlist too old, do a silent download");
116                                                                            stationLoader = new StationLoader(osp, true);
                                 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);  
117                                          stationLoader.execute( (Void)null);                                          stationLoader.execute( (Void)null);
118                                  }                                  }
119                          }                          }
120    
121                  }                  }
122          }          }
123            
124            
125                                    
126          @Override          @Override
127          protected void onDestroy() {          protected void onDestroy() {
# Line 159  public class WelcomeScreen extends Activ Line 159  public class WelcomeScreen extends Activ
159                                                    
160                  case MENU_RELOAD:                  case MENU_RELOAD:
161                          OfflineStationProvider osp = (OfflineStationProvider) ProviderFactory.getStationProvider();                          OfflineStationProvider osp = (OfflineStationProvider) ProviderFactory.getStationProvider();
162                          new StationLoader(osp).execute( (Void)null);                                              new StationLoader(osp, false).execute( (Void)null);                    
163                          break;                          break;
164                                                    
165                  default:                  default:
# Line 206  public class WelcomeScreen extends Activ Line 206  public class WelcomeScreen extends Activ
206                                  OfflineStationProvider osp = (OfflineStationProvider) sp;                                  OfflineStationProvider osp = (OfflineStationProvider) sp;
207                                                                    
208                                  if (! osp.hasStations()) {                                  if (! osp.hasStations()) {
209                                          stationLoader = new StationLoader(osp);                                          stationLoader = new StationLoader(osp, false);
210                                          stationLoader.execute( (Void)null);                                              stationLoader.execute( (Void)null);    
211                                          return;                                          return;
212                                  }                                  }
# Line 226  public class WelcomeScreen extends Activ Line 226  public class WelcomeScreen extends Activ
226                  ProgressDialog dlg;                  ProgressDialog dlg;
227                  OfflineStationProvider osp;                  OfflineStationProvider osp;
228                  String exMsg;                  String exMsg;
229                    boolean silent;
230                                    
231                  public StationLoader(OfflineStationProvider osp) {                  public StationLoader(OfflineStationProvider osp, boolean silent) {
232                          this.osp = osp;                          this.osp = osp;
233                            this.silent = silent;
234                  }                  }
235                                    
236                  @Override                  @Override
# Line 238  public class WelcomeScreen extends Activ Line 240  public class WelcomeScreen extends Activ
240                                  succeeded = true;                                  succeeded = true;
241                          } catch (Exception e) {                          } catch (Exception e) {
242                                  succeeded = false;                                  succeeded = false;
243                                  exMsg = e.getMessage();                                                          exMsg = e.getMessage();
244                                    Log.e("TrainInfo", "download error", e);                                
245                          }                          }
246                          return null;                          return null;
247                  }                  }
# Line 247  public class WelcomeScreen extends Activ Line 250  public class WelcomeScreen extends Activ
250                  @Override                  @Override
251                  protected void onPreExecute() {                  protected void onPreExecute() {
252                          super.onPreExecute();                          super.onPreExecute();
253                            Log.i("TrainInfo", "StationLoader.onPreExecute() ");
254                                                    
255                          dlg = new ProgressDialog(WelcomeScreen.this);                          if (silent == false) {
256                          dlg.setMessage( getText(R.string.welcome_downloadingstations) );                                  dlg = new ProgressDialog(WelcomeScreen.this);
257                          dlg.setCancelable(false);                                  dlg.setMessage( getText(R.string.welcome_downloadingstations) );
258                          dlg.show();                                  dlg.setCancelable(false);
259                                    dlg.show();
260                            }
261                  }                  }
262    
263                  @Override                  @Override
264                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
265                          super.onPostExecute(result);                          super.onPostExecute(result);
266                            Log.i("TrainInfo", "StationLoader.onPostExecute() ");
267                                                    
268                          dlg.dismiss();                          if (silent == false) {
269                          dlg = null;                                  dlg.dismiss();
270                                    dlg = null;
271                            }
272                                                    
273                          if (succeeded) {                          if (succeeded) {
274                                  Editor edit = prefs.edit();                                  Editor edit = prefs.edit();
275                                  edit.putLong(stationsreload, System.currentTimeMillis() );                                  edit.putLong(stationsreload, System.currentTimeMillis() );
276                                  edit.commit();                                  edit.commit();
277                          } else {                          } else {
278                                  Toast.makeText(WelcomeScreen.this, "Error " + exMsg, Toast.LENGTH_LONG).show();                                  if (silent == false) {
279                                            Toast.makeText(WelcomeScreen.this, "Error " + exMsg, Toast.LENGTH_LONG).show();
280                                    }
281                          }                          }
282                  }                        }      
283          }          }

Legend:
Removed from v.1625  
changed lines
  Added in v.1626

  ViewVC Help
Powered by ViewVC 1.1.20