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() { private LatLng getDefaultLatLng() {
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(getActivity()); MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(getActivity());
Location location = myTracksProviderUtils.getLastValidTrackPoint(); Track track = myTracksProviderUtils.getLastTrack();
if (location != null) { if (track != null) {
return new LatLng(location.getLatitude(), location.getLongitude()); Location location = myTracksProviderUtils.getLastValidTrackPoint(track.getId());
} else { if (location != null) {
return new LatLng(DEFAULT_LATITUDE, DEFAULT_LONGITUDE); 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); 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 * Creates a location cursor. The caller owns the returned cursor and is
* responsible for closing it. * responsible for closing it.
@@ -238,9 +238,9 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
public Track getLastTrack() { public Track getLastTrack() {
Cursor cursor = null; Cursor cursor = null;
try { try {
String selection = TracksColumns._ID + "=(select max(" + TracksColumns._ID + ") from " // Using the same order as shown in the track list
+ TracksColumns.TABLE_NAME + ")"; cursor = getTrackCursor(null, null, null,
cursor = getTrackCursor(null, selection, null, TracksColumns._ID); TracksColumns.SHAREDWITHME + " ASC, " + TracksColumns.STARTTIME + " DESC");
if (cursor != null && cursor.moveToNext()) { if (cursor != null && cursor.moveToNext()) {
return createTrack(cursor); return createTrack(cursor);
} }
@@ -816,14 +816,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
return findTrackPointBy(selection, selectionArgs); 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 @Override
public Cursor getTrackPointCursor( public Cursor getTrackPointCursor(
long trackId, long startTrackPointId, int maxLocations, boolean descending) { long trackId, long startTrackPointId, int maxLocations, boolean descending) {