Fix a bug in getLocationIterator

This commit is contained in:
bartn
2010-12-17 15:09:58 -08:00
parent 56f22aa073
commit 70bc7e53fe
@@ -940,18 +940,18 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
public LocationIterator getLocationIterator(final long trackId, final long startTrackPointId, public LocationIterator getLocationIterator(final long trackId, final long startTrackPointId,
final boolean descending, final LocationFactory locationFactory) { final boolean descending, final LocationFactory locationFactory) {
return new LocationIterator() { return new LocationIterator() {
private long lastTrackPointId = startTrackPointId - 1; private long lastTrackPointId = startTrackPointId;
private Cursor cursor = getCursor(); private Cursor cursor = getCursor(startTrackPointId);
private final int idColumnIdx = cursor != null ? private final int idColumnIdx = cursor != null ?
cursor.getColumnIndexOrThrow(TrackPointsColumns._ID) : -1; cursor.getColumnIndexOrThrow(TrackPointsColumns._ID) : -1;
private Cursor getCursor() { private Cursor getCursor(long trackPointId) {
return getLocationsCursor(trackId, lastTrackPointId + 1, 2000, descending); return getLocationsCursor(trackId, trackPointId, 2000, descending);
} }
private boolean advanceCursorToNextBatch() { private boolean advanceCursorToNextBatch() {
cursor.close(); cursor.close();
cursor = getCursor(); cursor = getCursor(lastTrackPointId + (descending ? -1 : 1));
return cursor != null && cursor.moveToNext(); return cursor != null && cursor.moveToNext();
} }