Change getLastTrack to return the last track on the track list.

This commit is contained in:
Jimmy Shih
2013-04-11 14:28:38 -07:00
parent 5447b357d2
commit 86410b1f80
3 changed files with 10 additions and 21 deletions
@@ -684,12 +684,14 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
*/
private LatLng getDefaultLatLng() {
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(getActivity());
Location location = myTracksProviderUtils.getLastValidTrackPoint();
if (location != null) {
return new LatLng(location.getLatitude(), location.getLongitude());
} else {
return new LatLng(DEFAULT_LATITUDE, DEFAULT_LONGITUDE);
Track track = myTracksProviderUtils.getLastTrack();
if (track != null) {
Location location = myTracksProviderUtils.getLastValidTrackPoint(track.getId());
if (location != null) {
return new LatLng(location.getLatitude(), location.getLongitude());
}
}
return new LatLng(DEFAULT_LATITUDE, DEFAULT_LONGITUDE);
}
/**
@@ -252,11 +252,6 @@ public interface MyTracksProviderUtils {
*/
public Location getLastValidTrackPoint(long trackId);
/**
* Gets the last valid location recorded. Returns null if it doesn't exist.
*/
public Location getLastValidTrackPoint();
/**
* Creates a location cursor. The caller owns the returned cursor and is
* responsible for closing it.
@@ -238,9 +238,9 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
public Track getLastTrack() {
Cursor cursor = null;
try {
String selection = TracksColumns._ID + "=(select max(" + TracksColumns._ID + ") from "
+ TracksColumns.TABLE_NAME + ")";
cursor = getTrackCursor(null, selection, null, TracksColumns._ID);
// Using the same order as shown in the track list
cursor = getTrackCursor(null, null, null,
TracksColumns.SHAREDWITHME + " ASC, " + TracksColumns.STARTTIME + " DESC");
if (cursor != null && cursor.moveToNext()) {
return createTrack(cursor);
}
@@ -816,14 +816,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
return findTrackPointBy(selection, selectionArgs);
}
@Override
public Location getLastValidTrackPoint() {
String selection = TrackPointsColumns._ID + "=(select max(" + TrackPointsColumns._ID + ") from "
+ TrackPointsColumns.TABLE_NAME + " WHERE " + TrackPointsColumns.LATITUDE + "<="
+ MAX_LATITUDE + ")";
return findTrackPointBy(selection, null);
}
@Override
public Cursor getTrackPointCursor(
long trackId, long startTrackPointId, int maxLocations, boolean descending) {