/[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 1551 by torben, Thu Jul 7 20:45:17 2011 UTC revision 1572 by torben, Sat Jul 9 09:45:40 2011 UTC
# Line 2  package dk.thoerup.traininfo; Line 2  package dk.thoerup.traininfo;
2    
3    
4    
5    import java.io.InvalidClassException;
6    
7  import android.app.Activity;  import android.app.Activity;
8  import android.app.ProgressDialog;  import android.app.ProgressDialog;
9  import android.content.Intent;  import android.content.Intent;
# Line 45  public class WelcomeScreen extends Activ Line 47  public class WelcomeScreen extends Activ
47                    
48          SharedPreferences prefs;          SharedPreferences prefs;
49                    
50            StationLoader stationLoader;
51            
52          @Override          @Override
53          public void onCreate(Bundle savedInstanceState) {          public void onCreate(Bundle savedInstanceState) {
54                                    
# Line 86  public class WelcomeScreen extends Activ Line 90  public class WelcomeScreen extends Activ
90                                    
91                  if (sp instanceof OfflineStationProvider ) {                  if (sp instanceof OfflineStationProvider ) {
92                          OfflineStationProvider osp = (OfflineStationProvider) sp;                          OfflineStationProvider osp = (OfflineStationProvider) sp;
93                          try {                          long last = prefs.getLong(stationsreload, 0);
94                                                            long now = System.currentTimeMillis();
95                                  long last = prefs.getLong(stationsreload, 0);                          Log.i("TrainInfo", "Last Load: " + last);
96                                  long now = System.currentTimeMillis();                          
97                                                            if ( (now-last) > (14*24*60*60*1000) ) {
98                                  Log.i("TrainInfo", "Last Load: " + last);                                  stationLoader = new StationLoader(osp);
99                                                                    stationLoader.execute( (Void)null);
100                                  if ( (now-last) > (14*24*60*60*1000) ) {                          } else {
101                                          new StationLoader(osp).execute( (Void)null);                          
102                                  } else {                                  boolean didLoad = false;
103                                                                    
104                                          boolean didLoad = osp.loadStations(this);                                  try {
105                                                                                    didLoad = osp.loadStations(this);
106                                          if (didLoad == false) {                                                                  }
107                                                  new StationLoader(osp).execute( (Void)null);                                  catch (InvalidClassException e) {
108                                          }                                          Log.i("TrainInfo", "invalid class - do a new download of stationlist");
109                                    }
110                                    catch (Exception e) {
111                                            Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
112                                            Log.e("TrainInfo", "load error", e);
113                                  }                                  }
114                                                                    
115                          } catch (Exception e) {                                  if (didLoad == false) {                                
116                                  Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();                                          stationLoader = new StationLoader(osp);
117                                            stationLoader.execute( (Void)null);
118                                    }
119                          }                          }
120    
121                  }                  }
122          }          }
123                    
# Line 115  public class WelcomeScreen extends Activ Line 126  public class WelcomeScreen extends Activ
126          @Override          @Override
127          protected void onDestroy() {          protected void onDestroy() {
128                  super.onDestroy();                  super.onDestroy();
129                    if (stationLoader != null) {
130                            stationLoader.cancel(false);
131                    }
132                    
133                  ProviderFactory.purgeOldEntries(); //exiting application, do some cleanup                  ProviderFactory.purgeOldEntries(); //exiting application, do some cleanup
134          }          }
135    
# Line 184  public class WelcomeScreen extends Activ Line 199  public class WelcomeScreen extends Activ
199                                    
200                  @Override                  @Override
201                  public void onClick(View v) {                  public void onClick(View v) {
202                            
203                            StationProvider sp = ProviderFactory.getStationProvider();
204                            
205                            if (sp instanceof OfflineStationProvider ) {
206                                    OfflineStationProvider osp = (OfflineStationProvider) sp;
207                                    
208                                    if (! osp.hasStations()) {
209                                            stationLoader = new StationLoader(osp);
210                                            stationLoader.execute( (Void)null);    
211                                            return;
212                                    }
213                            }
214                            
215                          Intent intent = new Intent(WelcomeScreen.this, StationList.class);                          Intent intent = new Intent(WelcomeScreen.this, StationList.class);
216                          intent.putExtra("type", launchType);                          intent.putExtra("type", launchType);
217                          WelcomeScreen.this.startActivity(intent);                          WelcomeScreen.this.startActivity(intent);
# Line 215  public class WelcomeScreen extends Activ Line 243  public class WelcomeScreen extends Activ
243                          return null;                          return null;
244                  }                  }
245    
246                    
247                  @Override                  @Override
248                  protected void onPreExecute() {                  protected void onPreExecute() {
249                          super.onPreExecute();                          super.onPreExecute();
250                                                    
251                          dlg = new ProgressDialog(WelcomeScreen.this);                          dlg = new ProgressDialog(WelcomeScreen.this);
252                          dlg.setMessage( "Downloading stations list" );//TODO: translate                          dlg.setMessage( getText(R.string.welcome_downloadingstations) );
253                          dlg.setCancelable(true);                          dlg.setCancelable(false);
254                          dlg.show();                          dlg.show();
255                  }                  }
256    

Legend:
Removed from v.1551  
changed lines
  Added in v.1572

  ViewVC Help
Powered by ViewVC 1.1.20