From 016d6523cd3604450c730fe4a808a3c4f906ec6c Mon Sep 17 00:00:00 2001 From: Doug Keen Date: Thu, 4 Jul 2013 11:33:37 -0700 Subject: [PATCH] Always get cached boarded departure when processing an alarm (no matter how old) --- .classpath | 1 + src/com/dougkeen/bart/BartRunnerApplication.java | 13 +++++++++---- .../bart/receivers/AlarmBroadcastReceiver.java | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.classpath b/.classpath index 058b94f..bf6c652 100644 --- a/.classpath +++ b/.classpath @@ -12,5 +12,6 @@ + diff --git a/src/com/dougkeen/bart/BartRunnerApplication.java b/src/com/dougkeen/bart/BartRunnerApplication.java index bc73d14..45cf76e 100644 --- a/src/com/dougkeen/bart/BartRunnerApplication.java +++ b/src/com/dougkeen/bart/BartRunnerApplication.java @@ -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; diff --git a/src/com/dougkeen/bart/receivers/AlarmBroadcastReceiver.java b/src/com/dougkeen/bart/receivers/AlarmBroadcastReceiver.java index f2f8961..16a60dd 100644 --- a/src/com/dougkeen/bart/receivers/AlarmBroadcastReceiver.java +++ b/src/com/dougkeen/bart/receivers/AlarmBroadcastReceiver.java @@ -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;