Always get cached boarded departure when processing an alarm (no matter how old)

This commit is contained in:
Doug Keen 2013-07-04 11:33:37 -07:00
parent d407db14bb
commit 016d6523cd
3 changed files with 11 additions and 5 deletions

View File

@ -12,5 +12,6 @@
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

View File

@ -107,6 +107,10 @@ public class BartRunnerApplication extends Application {
} }
public Departure getBoardedDeparture() { public Departure getBoardedDeparture() {
return getBoardedDeparture(false);
}
public Departure getBoardedDeparture(boolean useOldCache) {
if (mBoardedDeparture == null) { if (mBoardedDeparture == null) {
// see if there's a saved one // see if there's a saved one
File cachedDepartureFile = new File(getCacheDir(), CACHE_FILE_NAME); File cachedDepartureFile = new File(getCacheDir(), CACHE_FILE_NAME);
@ -123,11 +127,12 @@ public class BartRunnerApplication extends Application {
parcel.recycle(); parcel.recycle();
/* /*
* Check if the cached one is relatively recent. If so, * Ooptionally check if the cached one is relatively recent.
* restore that to the application context * If so, restore that to the application context
*/ */
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (lastBoardedDeparture.getEstimatedArrivalTime() >= now if (useOldCache
|| lastBoardedDeparture.getEstimatedArrivalTime() >= now
- FIVE_MINUTES - FIVE_MINUTES
|| lastBoardedDeparture.getMeanEstimate() >= now || lastBoardedDeparture.getMeanEstimate() >= now
- 2 * FIVE_MINUTES) { - 2 * FIVE_MINUTES) {

View File

@ -16,7 +16,7 @@ public class AlarmBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
BartRunnerApplication application = (BartRunnerApplication) context BartRunnerApplication application = (BartRunnerApplication) context
.getApplicationContext(); .getApplicationContext();
final Departure boardedDeparture = application.getBoardedDeparture(); final Departure boardedDeparture = application.getBoardedDeparture(true);
if (boardedDeparture == null) { if (boardedDeparture == null) {
// Nothing to notify about // Nothing to notify about
return; return;