Allow importer to update an existing track. Add clearTrack in MyTracksProviderUtils

This commit is contained in:
Jimmy Shih
2013-01-23 11:04:15 -08:00
parent 6b5f9c976b
commit 07cd1dcdbb
6 changed files with 95 additions and 32 deletions
@@ -40,6 +40,13 @@ public interface MyTracksProviderUtils {
*/
public static final String AUTHORITY = "com.google.android.maps.mytracks";
/**
* Clears a track. Removes waypoints and trackpoints. Only keeps the track id.
*
* @param trackId the track id
*/
public void clearTrack(long trackId);
/**
* Creates a {@link Track} from a cursor.
*
@@ -122,7 +129,8 @@ public interface MyTracksProviderUtils {
* deletion. The generator is used to update the next statistics waypoint.
*
* @param waypointId the waypoint id
* @param descriptionGenerator the description generator. Can be null for waypoint marker
* @param descriptionGenerator the description generator. Can be null for
* waypoint marker
*/
public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator);
@@ -143,8 +151,8 @@ public interface MyTracksProviderUtils {
public Waypoint getLastWaypoint(long trackId, WaypointType waypointType);
/**
* Gets the next waypoint number for a type. Returns -1 if not able to get the next
* waypoint number.
* Gets the next waypoint number for a type. Returns -1 if not able to get the
* next waypoint number.
*
* @param trackId the track id
* @param waypointType the waypoint type
@@ -165,7 +173,8 @@ public interface MyTracksProviderUtils {
* @param selection the selection. Can be null
* @param selectionArgs the selection arguments. Can be null
* @param sortOrder the sort order. Can be null
* @param maxWaypoints the maximum number of waypoints to return. -1 for no limit
* @param maxWaypoints the maximum number of waypoints to return. -1 for no
* limit
*/
public Cursor getWaypointCursor(
String selection, String[] selectionArgs, String sortOrder, int maxWaypoints);
@@ -176,7 +185,8 @@ public interface MyTracksProviderUtils {
*
* @param trackId the track id
* @param minWaypointId the minimum waypoint id. -1L to ignore
* @param maxWaypoints the maximum number of waypoints to return. -1 for no limit
* @param maxWaypoints the maximum number of waypoints to return. -1 for no
* limit
*/
public Cursor getWaypointCursor(long trackId, long minWaypointId, int maxWaypoints);
@@ -228,12 +238,13 @@ public interface MyTracksProviderUtils {
public long getLastTrackPointId(long trackId);
/**
* Gets the first valid location for a track. Returns null if it doesn't exist.
* Gets the first valid location for a track. Returns null if it doesn't
* exist.
*
* @param trackId the track id
*/
public Location getFirstValidTrackPoint(long trackId);
/**
* Gets the last valid location for a track. Returns null if it doesn't exist.
*
@@ -50,6 +50,14 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
this.contentResolver = contentResolver;
}
@Override
public void clearTrack(long trackId) {
deleteTrackPointsAndWaypoints(trackId);
Track track = new Track();
track.setId(trackId);
updateTrack(track);
}
@Override
public Track createTrack(Cursor cursor) {
int idIndex = cursor.getColumnIndexOrThrow(TracksColumns._ID);
@@ -164,6 +172,21 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
@Override
public void deleteTrack(long trackId) {
deleteTrackPointsAndWaypoints(trackId);
// Delete track last since it triggers a database vaccum call
contentResolver.delete(TracksColumns.CONTENT_URI, TracksColumns._ID + "=?",
new String[] { Long.toString(trackId) });
}
/**
* Deletes track points and waypoints of a track. Assumes
* {@link TracksColumns#STARTID}, {@link TracksColumns#STOPID}, and
* {@link TracksColumns#NUMPOINTS} will be updated by the caller.
*
* @param trackId the track id
*/
private void deleteTrackPointsAndWaypoints(long trackId) {
Track track = getTrack(trackId);
if (track != null) {
String where = TrackPointsColumns._ID + ">=? AND " + TrackPointsColumns._ID + "<=?";
@@ -173,9 +196,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
}
contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns.TRACKID + "=?",
new String[] { Long.toString(trackId) });
// Delete tracks last since it triggers a database vaccum call
contentResolver.delete(TracksColumns.CONTENT_URI, TracksColumns._ID + "=?",
new String[] { Long.toString(trackId) });
}
@Override
@@ -759,7 +779,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
String[] selectionArgs = new String[] { Long.toString(trackId) };
return findTrackPointBy(selection, selectionArgs);
}
@Override
public Location getLastValidTrackPoint(long trackId) {
if (trackId < 0) {