forked from upstream-mirrors/OpenTracks
Making locations be reused when writing tracks.
This commit is contained in:
@@ -266,9 +266,10 @@ public class TrackWriter {
|
|||||||
private void writeLocations() {
|
private void writeLocations() {
|
||||||
boolean wroteFirst = false;
|
boolean wroteFirst = false;
|
||||||
boolean segmentOpen = false;
|
boolean segmentOpen = false;
|
||||||
Location lastLoc = null;
|
Location lastLoc = null, loc = null;
|
||||||
boolean isLastValid = false;
|
boolean isLastValid = false;
|
||||||
Cursor locationsCursor = providerUtils.getLocationsCursor(track.getId(), 0, -1, false);
|
Cursor locationsCursor =
|
||||||
|
providerUtils.getLocationsCursor(track.getId(), 0, -1, false);
|
||||||
|
|
||||||
if (locationsCursor == null || !locationsCursor.moveToFirst()) {
|
if (locationsCursor == null || !locationsCursor.moveToFirst()) {
|
||||||
Log.w(MyTracksConstants.TAG, "Unable to get any points to write");
|
Log.w(MyTracksConstants.TAG, "Unable to get any points to write");
|
||||||
@@ -276,8 +277,8 @@ public class TrackWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// TODO: Use fillLocation instead
|
if (loc == null) loc = new Location("");
|
||||||
Location loc = providerUtils.createLocation(locationsCursor);
|
providerUtils.fillLocation(locationsCursor, loc);
|
||||||
|
|
||||||
boolean isValid = MyTracksUtils.isValidLocation(loc);
|
boolean isValid = MyTracksUtils.isValidLocation(loc);
|
||||||
boolean validSegment = isValid && isLastValid;
|
boolean validSegment = isValid && isLastValid;
|
||||||
@@ -306,7 +307,12 @@ public class TrackWriter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Swap loc and lastLoc (so lastLoc is reused)
|
||||||
|
Location tmp = lastLoc;
|
||||||
lastLoc = loc;
|
lastLoc = loc;
|
||||||
|
loc = tmp;
|
||||||
|
loc.reset();
|
||||||
|
|
||||||
isLastValid = isValid;
|
isLastValid = isValid;
|
||||||
} while (locationsCursor.moveToNext());
|
} while (locationsCursor.moveToNext());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user