Always get cached boarded departure when processing an alarm (no matter how old)
This commit is contained in:
parent
d407db14bb
commit
016d6523cd
@ -12,5 +12,6 @@
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
|
@ -107,6 +107,10 @@ public class BartRunnerApplication extends Application {
|
||||
}
|
||||
|
||||
public Departure getBoardedDeparture() {
|
||||
return getBoardedDeparture(false);
|
||||
}
|
||||
|
||||
public Departure getBoardedDeparture(boolean useOldCache) {
|
||||
if (mBoardedDeparture == null) {
|
||||
// see if there's a saved one
|
||||
File cachedDepartureFile = new File(getCacheDir(), CACHE_FILE_NAME);
|
||||
@ -123,12 +127,13 @@ public class BartRunnerApplication extends Application {
|
||||
parcel.recycle();
|
||||
|
||||
/*
|
||||
* Check if the cached one is relatively recent. If so,
|
||||
* restore that to the application context
|
||||
* Ooptionally check if the cached one is relatively recent.
|
||||
* If so, restore that to the application context
|
||||
*/
|
||||
long now = System.currentTimeMillis();
|
||||
if (lastBoardedDeparture.getEstimatedArrivalTime() >= now
|
||||
- FIVE_MINUTES
|
||||
if (useOldCache
|
||||
|| lastBoardedDeparture.getEstimatedArrivalTime() >= now
|
||||
- FIVE_MINUTES
|
||||
|| lastBoardedDeparture.getMeanEstimate() >= now
|
||||
- 2 * FIVE_MINUTES) {
|
||||
mBoardedDeparture = lastBoardedDeparture;
|
||||
|
@ -16,7 +16,7 @@ public class AlarmBroadcastReceiver extends BroadcastReceiver {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
BartRunnerApplication application = (BartRunnerApplication) context
|
||||
.getApplicationContext();
|
||||
final Departure boardedDeparture = application.getBoardedDeparture();
|
||||
final Departure boardedDeparture = application.getBoardedDeparture(true);
|
||||
if (boardedDeparture == null) {
|
||||
// Nothing to notify about
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user