From 62bd905f269f6db49ca7c4108b33bcfa302fd227 Mon Sep 17 00:00:00 2001 From: Doug Keen Date: Wed, 26 Sep 2012 10:50:15 -0700 Subject: [PATCH] Fixed problem where estimated arrival wasn't updating for departures other than the first one. --- .../bart/data/FavoritesArrayAdapter.java | 35 +++++++++++-------- .../dougkeen/bart/services/EtdService.java | 5 ++- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/com/dougkeen/bart/data/FavoritesArrayAdapter.java b/src/com/dougkeen/bart/data/FavoritesArrayAdapter.java index 65af46d..4212470 100644 --- a/src/com/dougkeen/bart/data/FavoritesArrayAdapter.java +++ b/src/com/dougkeen/bart/data/FavoritesArrayAdapter.java @@ -124,22 +124,29 @@ public class FavoritesArrayAdapter extends ArrayAdapter { } for (int i = 0; i < getCount(); i++) { StationPair adapterItem = getItem(i); - StationPair cursorItem = StationPair.createFromCursor(cursor); - while (!cursorItem.equals(adapterItem)) { - remove(adapterItem); - if (i < getCount()) { - adapterItem = getItem(i); - } else { - break; + if (cursor.isAfterLast()) { + while (i < getCount()) { + remove(getItem(i)); } + } else { + StationPair cursorItem = StationPair.createFromCursor(cursor); + while (!cursorItem.equals(adapterItem)) { + remove(adapterItem); + if (i < getCount()) { + adapterItem = getItem(i); + } else { + break; + } + } + if (cursorItem.equals(adapterItem) + && !cursorItem.fareEquals(adapterItem)) { + adapterItem.setFare(cursorItem.getFare()); + adapterItem.setFareLastUpdated(cursorItem + .getFareLastUpdated()); + notifyDataSetChanged(); + } + cursor.moveToNext(); } - if (cursorItem.equals(adapterItem) - && !cursorItem.fareEquals(adapterItem)) { - adapterItem.setFare(cursorItem.getFare()); - adapterItem.setFareLastUpdated(cursorItem.getFareLastUpdated()); - notifyDataSetChanged(); - } - cursor.moveToNext(); } while (!cursor.isAfterLast()) { add(StationPair.createFromCursor(cursor)); diff --git a/src/com/dougkeen/bart/services/EtdService.java b/src/com/dougkeen/bart/services/EtdService.java index b80d2c1..d990025 100644 --- a/src/com/dougkeen/bart/services/EtdService.java +++ b/src/com/dougkeen/bart/services/EtdService.java @@ -157,8 +157,9 @@ public class EtdService extends Service { protected void registerListener(EtdServiceListener listener, boolean limitToFirstNonDeparted) { mListeners.put(listener, true); - if (!limitToFirstNonDeparted) + if (!limitToFirstNonDeparted) { mLimitToFirstNonDeparted = false; + } if (!mPendingEtdRequest) { mStarted = true; fetchLatestDepartures(); @@ -578,6 +579,8 @@ public class EtdService extends Service { .getMeanEstimate()) { fetchLatestSchedule(); return; + } else if (!lastDeparture.hasAnyArrivalEstimate()) { + applyScheduleInformation(mLatestScheduleInfo); } }