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"/>
|
<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>
|
||||||
|
@ -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,12 +127,13 @@ 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
|
||||||
- FIVE_MINUTES
|
|| lastBoardedDeparture.getEstimatedArrivalTime() >= now
|
||||||
|
- FIVE_MINUTES
|
||||||
|| lastBoardedDeparture.getMeanEstimate() >= now
|
|| lastBoardedDeparture.getMeanEstimate() >= now
|
||||||
- 2 * FIVE_MINUTES) {
|
- 2 * FIVE_MINUTES) {
|
||||||
mBoardedDeparture = lastBoardedDeparture;
|
mBoardedDeparture = lastBoardedDeparture;
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user