2 |
|
|
3 |
|
|
4 |
|
|
5 |
import java.util.ArrayList; |
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; |
10 |
import android.content.SharedPreferences; |
import android.content.SharedPreferences; |
11 |
import android.content.SharedPreferences.Editor; |
import android.content.SharedPreferences.Editor; |
|
import android.location.Location; |
|
12 |
import android.net.Uri; |
import android.net.Uri; |
13 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
14 |
import android.os.Bundle; |
import android.os.Bundle; |
24 |
|
|
25 |
import com.nullwire.trace.ExceptionHandler; |
import com.nullwire.trace.ExceptionHandler; |
26 |
|
|
|
import dk.thoerup.android.traininfo.common.StationEntry; |
|
27 |
import dk.thoerup.androidutils.CheckUpdates; |
import dk.thoerup.androidutils.CheckUpdates; |
28 |
import dk.thoerup.traininfo.provider.OfflineStationProvider; |
import dk.thoerup.traininfo.provider.OfflineStationProvider; |
29 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
30 |
import dk.thoerup.traininfo.provider.StationProvider; |
import dk.thoerup.traininfo.provider.StationProvider; |
31 |
import dk.thoerup.traininfo.stationmap.GeoPair; |
|
|
import dk.thoerup.traininfo.stationmap.StationMapView; |
|
|
import dk.thoerup.traininfo.util.MessageBox; |
|
32 |
|
|
33 |
public class WelcomeScreen extends Activity{ |
public class WelcomeScreen extends Activity{ |
34 |
|
|
88 |
|
|
89 |
if (sp instanceof OfflineStationProvider ) { |
if (sp instanceof OfflineStationProvider ) { |
90 |
OfflineStationProvider osp = (OfflineStationProvider) sp; |
OfflineStationProvider osp = (OfflineStationProvider) sp; |
91 |
try { |
long last = prefs.getLong(stationsreload, 0); |
92 |
|
long now = System.currentTimeMillis(); |
93 |
|
Log.i("TrainInfo", "Last Load: " + last); |
94 |
|
|
95 |
|
if ( (now-last) > (14*24*60*60*1000) ) { |
96 |
|
new StationLoader(osp).execute( (Void)null); |
97 |
|
} else { |
98 |
|
|
99 |
|
boolean didLoad = false; |
100 |
|
|
101 |
long last = prefs.getLong(stationsreload, 0); |
try { |
102 |
long now = System.currentTimeMillis(); |
didLoad = osp.loadStations(this); |
103 |
|
} |
104 |
|
catch (InvalidClassException e) { |
105 |
|
Log.i("TrainInfo", "invalid class - do a new download of stationlist"); |
106 |
|
} |
107 |
|
catch (Exception e) { |
108 |
|
Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show(); |
109 |
|
Log.e("TrainInfo", "load error", e); |
110 |
|
} |
111 |
|
|
112 |
if ( (now-last) > (14*24*60*60*1000) ) { |
if (didLoad == false) { |
113 |
new StationLoader(osp).execute( (Void)null); |
new StationLoader(osp).execute( (Void)null); |
|
} else { |
|
|
|
|
|
boolean didLoad = osp.loadStations(this); |
|
|
|
|
|
if (didLoad == false) { |
|
|
new StationLoader(osp).execute( (Void)null); |
|
|
} |
|
114 |
} |
} |
|
|
|
|
} catch (Exception e) { |
|
|
Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show(); |
|
115 |
} |
} |
116 |
|
|
117 |
} |
} |
118 |
} |
} |
119 |
|
|
204 |
boolean succeeded; |
boolean succeeded; |
205 |
ProgressDialog dlg; |
ProgressDialog dlg; |
206 |
OfflineStationProvider osp; |
OfflineStationProvider osp; |
207 |
|
String exMsg; |
208 |
|
|
209 |
public StationLoader(OfflineStationProvider osp) { |
public StationLoader(OfflineStationProvider osp) { |
210 |
this.osp = osp; |
this.osp = osp; |
217 |
succeeded = true; |
succeeded = true; |
218 |
} catch (Exception e) { |
} catch (Exception e) { |
219 |
succeeded = false; |
succeeded = false; |
220 |
Toast.makeText(WelcomeScreen.this, "Error " + e.getMessage(), Toast.LENGTH_LONG).show(); |
exMsg = e.getMessage(); |
221 |
} |
} |
222 |
return null; |
return null; |
223 |
} |
} |
243 |
Editor edit = prefs.edit(); |
Editor edit = prefs.edit(); |
244 |
edit.putLong(stationsreload, System.currentTimeMillis() ); |
edit.putLong(stationsreload, System.currentTimeMillis() ); |
245 |
edit.commit(); |
edit.commit(); |
246 |
|
} else { |
247 |
|
Toast.makeText(WelcomeScreen.this, "Error " + exMsg, Toast.LENGTH_LONG).show(); |
248 |
} |
} |
249 |
} |
} |
250 |
} |
} |