forked from upstream-mirrors/OpenTracks
Update gallery when photo markers are deleted
This commit is contained in:
@@ -95,7 +95,7 @@ public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
context, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
context, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
||||||
SyncUtils.disableSync(context);
|
SyncUtils.disableSync(context);
|
||||||
SyncUtils.clearSyncState(context);
|
SyncUtils.clearSyncState(context);
|
||||||
myTracksProviderUtils.deleteAllTracks();
|
myTracksProviderUtils.deleteAllTracks(context);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
for (long id : trackIds) {
|
for (long id : trackIds) {
|
||||||
@@ -103,7 +103,7 @@ public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Track track = myTracksProviderUtils.getTrack(id);
|
Track track = myTracksProviderUtils.getTrack(id);
|
||||||
myTracksProviderUtils.deleteTrack(id);
|
myTracksProviderUtils.deleteTrack(context, id);
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
String driveId = track.getDriveId();
|
String driveId = track.getDriveId();
|
||||||
if (driveId != null && !driveId.equals("")) {
|
if (driveId != null && !driveId.equals("")) {
|
||||||
|
|||||||
+1
-1
@@ -90,7 +90,7 @@ public class DeleteMarkerDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(
|
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(
|
||||||
fragmentActivity);
|
fragmentActivity);
|
||||||
for (long markerId : markerIds) {
|
for (long markerId : markerIds) {
|
||||||
myTracksProviderUtils.deleteWaypoint(
|
myTracksProviderUtils.deleteWaypoint(fragmentActivity,
|
||||||
markerId, new DescriptionGeneratorImpl(fragmentActivity));
|
markerId, new DescriptionGeneratorImpl(fragmentActivity));
|
||||||
}
|
}
|
||||||
caller.onDeleteMarkerDone();
|
caller.onDeleteMarkerDone();
|
||||||
|
|||||||
+2
-2
@@ -310,7 +310,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
"Cannot import more than one track to an existing track " + importTrackId));
|
"Cannot import more than one track to an existing track " + importTrackId));
|
||||||
}
|
}
|
||||||
trackId = importTrackId;
|
trackId = importTrackId;
|
||||||
myTracksProviderUtils.clearTrack(trackId);
|
myTracksProviderUtils.clearTrack(context, trackId);
|
||||||
}
|
}
|
||||||
trackIds.add(trackId);
|
trackIds.add(trackId);
|
||||||
trackData.track.setId(trackId);
|
trackData.track.setId(trackId);
|
||||||
@@ -614,7 +614,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
*/
|
*/
|
||||||
private void cleanImport() {
|
private void cleanImport() {
|
||||||
for (long trackId : trackIds) {
|
for (long trackId : trackIds) {
|
||||||
myTracksProviderUtils.deleteTrack(trackId);
|
myTracksProviderUtils.deleteTrack(context, trackId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,13 +171,13 @@ public class ImportActivity extends Activity {
|
|||||||
final Dialog dialog = new AlertDialog.Builder(this).setCancelable(true).setIcon(iconId)
|
final Dialog dialog = new AlertDialog.Builder(this).setCancelable(true).setIcon(iconId)
|
||||||
.setMessage(message).setOnCancelListener(new DialogInterface.OnCancelListener() {
|
.setMessage(message).setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialogInterface) {
|
||||||
dialog.dismiss();
|
dialogInterface.dismiss();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}).setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
}).setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialogInterface, int which) {
|
||||||
if (successCount == totalCount && !importAll && trackId != -1L) {
|
if (successCount == totalCount && !importAll && trackId != -1L) {
|
||||||
Intent intent = IntentUtils.newIntent(
|
Intent intent = IntentUtils.newIntent(
|
||||||
ImportActivity.this, TrackDetailActivity.class)
|
ImportActivity.this, TrackDetailActivity.class)
|
||||||
@@ -186,7 +186,7 @@ public class ImportActivity extends Activity {
|
|||||||
.addParentStack(TrackDetailActivity.class).addNextIntent(intent)
|
.addParentStack(TrackDetailActivity.class).addNextIntent(intent)
|
||||||
.startActivities();
|
.startActivities();
|
||||||
}
|
}
|
||||||
dialog.dismiss();
|
dialogInterface.dismiss();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}).setTitle(titleId).create();
|
}).setTitle(titleId).create();
|
||||||
|
|||||||
+1
-1
@@ -112,7 +112,7 @@ public class KmzTrackImporter implements TrackImporter {
|
|||||||
private void cleanImport(long trackId) {
|
private void cleanImport(long trackId) {
|
||||||
if (trackId != -1L) {
|
if (trackId != -1L) {
|
||||||
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
||||||
myTracksProviderUtils.deleteTrack(trackId);
|
myTracksProviderUtils.deleteTrack(context, trackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (importTrackId != -1L) {
|
if (importTrackId != -1L) {
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
do {
|
do {
|
||||||
Track track = myTracksProviderUtils.createTrack(cursor);
|
Track track = myTracksProviderUtils.createTrack(cursor);
|
||||||
if (!syncedDriveIds.contains(track.getDriveId())) {
|
if (!syncedDriveIds.contains(track.getDriveId())) {
|
||||||
myTracksProviderUtils.deleteTrack(track.getId());
|
myTracksProviderUtils.deleteTrack(context, track.getId());
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
}
|
}
|
||||||
@@ -314,7 +314,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
File driveFile = changes.get(driveId);
|
File driveFile = changes.get(driveId);
|
||||||
if (driveFile == null) {
|
if (driveFile == null) {
|
||||||
Log.d(TAG, "Delete local track " + track.getName());
|
Log.d(TAG, "Delete local track " + track.getName());
|
||||||
myTracksProviderUtils.deleteTrack(track.getId());
|
myTracksProviderUtils.deleteTrack(context, track.getId());
|
||||||
} else {
|
} else {
|
||||||
if (SyncUtils.isInMyTracksAndValid(driveFile, getFolderId())
|
if (SyncUtils.isInMyTracksAndValid(driveFile, getFolderId())
|
||||||
|| SyncUtils.isInSharedWithMe(driveFile)) {
|
|| SyncUtils.isInSharedWithMe(driveFile)) {
|
||||||
@@ -532,7 +532,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
if (!success) {
|
if (!success) {
|
||||||
// if the track is new, delete it
|
// if the track is new, delete it
|
||||||
if (trackId == -1L && track != null) {
|
if (trackId == -1L && track != null) {
|
||||||
myTracksProviderUtils.deleteTrack(track.getId());
|
myTracksProviderUtils.deleteTrack(context, track.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public class SyncUtils {
|
|||||||
do {
|
do {
|
||||||
Track track = myTracksProviderUtils.createTrack(cursor);
|
Track track = myTracksProviderUtils.createTrack(cursor);
|
||||||
if (track.isSharedWithMe()) {
|
if (track.isSharedWithMe()) {
|
||||||
myTracksProviderUtils.deleteTrack(track.getId());
|
myTracksProviderUtils.deleteTrack(context, track.getId());
|
||||||
} else {
|
} else {
|
||||||
SyncUtils.updateTrack(myTracksProviderUtils, track, null);
|
SyncUtils.updateTrack(myTracksProviderUtils, track, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public interface MyTracksProviderUtils {
|
|||||||
*
|
*
|
||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
*/
|
*/
|
||||||
public void clearTrack(long trackId);
|
public void clearTrack(Context context, long trackId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link Track} from a cursor.
|
* Creates a {@link Track} from a cursor.
|
||||||
@@ -57,14 +57,14 @@ public interface MyTracksProviderUtils {
|
|||||||
/**
|
/**
|
||||||
* Deletes all tracks (including waypoints and track points).
|
* Deletes all tracks (including waypoints and track points).
|
||||||
*/
|
*/
|
||||||
public void deleteAllTracks();
|
public void deleteAllTracks(Context context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a track.
|
* Deletes a track.
|
||||||
*
|
*
|
||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
*/
|
*/
|
||||||
public void deleteTrack(long trackId);
|
public void deleteTrack(Context context, long trackId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all the tracks. If no track exists, an empty list is returned.
|
* Gets all the tracks. If no track exists, an empty list is returned.
|
||||||
@@ -132,7 +132,7 @@ public interface MyTracksProviderUtils {
|
|||||||
* @param descriptionGenerator the description generator. Can be null for
|
* @param descriptionGenerator the description generator. Can be null for
|
||||||
* waypoint marker
|
* waypoint marker
|
||||||
*/
|
*/
|
||||||
public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator);
|
public void deleteWaypoint(Context context, long waypointId, DescriptionGenerator descriptionGenerator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the first waypoint id for a track. The first waypoint is special as it
|
* Gets the first waypoint id for a track. The first waypoint is special as it
|
||||||
|
|||||||
+14
-11
@@ -24,6 +24,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
|
|||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@@ -53,8 +54,8 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearTrack(long trackId) {
|
public void clearTrack(Context context, long trackId) {
|
||||||
deleteTrackPointsAndWaypoints(trackId);
|
deleteTrackPointsAndWaypoints(context, trackId);
|
||||||
Track track = new Track();
|
Track track = new Track();
|
||||||
track.setId(trackId);
|
track.setId(trackId);
|
||||||
updateTrack(track);
|
updateTrack(track);
|
||||||
@@ -177,19 +178,19 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAllTracks() {
|
public void deleteAllTracks(Context context) {
|
||||||
contentResolver.delete(TrackPointsColumns.CONTENT_URI, null, null);
|
contentResolver.delete(TrackPointsColumns.CONTENT_URI, null, null);
|
||||||
contentResolver.delete(WaypointsColumns.CONTENT_URI, null, null);
|
contentResolver.delete(WaypointsColumns.CONTENT_URI, null, null);
|
||||||
// Delete tracks last since it triggers a database vaccum call
|
// Delete tracks last since it triggers a database vaccum call
|
||||||
contentResolver.delete(TracksColumns.CONTENT_URI, null, null);
|
contentResolver.delete(TracksColumns.CONTENT_URI, null, null);
|
||||||
|
|
||||||
File dir = FileUtils.getPhotoDir();
|
File dir = FileUtils.getPhotoDir();
|
||||||
deleteDirectoryRecurse(dir);
|
deleteDirectoryRecurse(context, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteTrack(long trackId) {
|
public void deleteTrack(Context context, long trackId) {
|
||||||
deleteTrackPointsAndWaypoints(trackId);
|
deleteTrackPointsAndWaypoints(context, trackId);
|
||||||
|
|
||||||
// Delete track last since it triggers a database vaccum call
|
// Delete track last since it triggers a database vaccum call
|
||||||
contentResolver.delete(TracksColumns.CONTENT_URI, TracksColumns._ID + "=?",
|
contentResolver.delete(TracksColumns.CONTENT_URI, TracksColumns._ID + "=?",
|
||||||
@@ -203,7 +204,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
*
|
*
|
||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
*/
|
*/
|
||||||
private void deleteTrackPointsAndWaypoints(long trackId) {
|
private void deleteTrackPointsAndWaypoints(Context context, long trackId) {
|
||||||
Track track = getTrack(trackId);
|
Track track = getTrack(trackId);
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
String where = TrackPointsColumns._ID + ">=? AND " + TrackPointsColumns._ID + "<=?";
|
String where = TrackPointsColumns._ID + ">=? AND " + TrackPointsColumns._ID + "<=?";
|
||||||
@@ -213,7 +214,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
}
|
}
|
||||||
contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns.TRACKID + "=?",
|
contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns.TRACKID + "=?",
|
||||||
new String[] { Long.toString(trackId) });
|
new String[] { Long.toString(trackId) });
|
||||||
deleteDirectoryRecurse(FileUtils.getPhotoDir(trackId));
|
deleteDirectoryRecurse(context, FileUtils.getPhotoDir(trackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -221,14 +222,15 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
*
|
*
|
||||||
* @param dir the directory
|
* @param dir the directory
|
||||||
*/
|
*/
|
||||||
private void deleteDirectoryRecurse(File dir) {
|
private void deleteDirectoryRecurse(Context context, File dir) {
|
||||||
if (FileUtils.isDirectory(dir)) {
|
if (FileUtils.isDirectory(dir)) {
|
||||||
for (File child : dir.listFiles()) {
|
for (File child : dir.listFiles()) {
|
||||||
deleteDirectoryRecurse(child);
|
deleteDirectoryRecurse(context, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dir.exists()) {
|
if (dir.exists()) {
|
||||||
dir.delete();
|
dir.delete();
|
||||||
|
FileUtils.updateMediaScanner(context, Uri.fromFile(dir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,7 +511,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator) {
|
public void deleteWaypoint(Context context, long waypointId, DescriptionGenerator descriptionGenerator) {
|
||||||
final Waypoint waypoint = getWaypoint(waypointId);
|
final Waypoint waypoint = getWaypoint(waypointId);
|
||||||
if (waypoint != null && waypoint.getType() == WaypointType.STATISTICS
|
if (waypoint != null && waypoint.getType() == WaypointType.STATISTICS
|
||||||
&& descriptionGenerator != null) {
|
&& descriptionGenerator != null) {
|
||||||
@@ -533,6 +535,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
File parent = file.getParentFile();
|
File parent = file.getParentFile();
|
||||||
file.delete();
|
file.delete();
|
||||||
|
FileUtils.updateMediaScanner(context, uri);
|
||||||
if (parent.listFiles().length == 0) {
|
if (parent.listFiles().length == 0) {
|
||||||
parent.delete();
|
parent.delete();
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -69,7 +69,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
|||||||
setContext(context);
|
setContext(context);
|
||||||
|
|
||||||
providerUtils = MyTracksProviderUtils.Factory.get(context);
|
providerUtils = MyTracksProviderUtils.Factory.get(context);
|
||||||
providerUtils.deleteAllTracks();
|
providerUtils.deleteAllTracks(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLocationIterator_noPoints() {
|
public void testLocationIterator_noPoints() {
|
||||||
@@ -220,7 +220,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link MyTracksProviderUtilsImpl#deleteAllTracks()}
|
* Tests the method {@link MyTracksProviderUtilsImpl#deleteAllTracks(Context)}
|
||||||
*/
|
*/
|
||||||
public void testDeleteAllTracks() {
|
public void testDeleteAllTracks() {
|
||||||
// Insert track, points and waypoint at first.
|
// Insert track, points and waypoint at first.
|
||||||
@@ -240,7 +240,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
|||||||
null, WaypointsColumns._ID);
|
null, WaypointsColumns._ID);
|
||||||
assertEquals(1, waypointCursor.getCount());
|
assertEquals(1, waypointCursor.getCount());
|
||||||
// Delete all.
|
// Delete all.
|
||||||
providerUtils.deleteAllTracks();
|
providerUtils.deleteAllTracks(context);
|
||||||
// Check whether all have been deleted.
|
// Check whether all have been deleted.
|
||||||
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null,
|
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null,
|
||||||
TracksColumns._ID);
|
TracksColumns._ID);
|
||||||
@@ -254,7 +254,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link MyTracksProviderUtilsImpl#deleteTrack(long)}.
|
* Tests the method {@link MyTracksProviderUtilsImpl#deleteTrack(Context, long)}.
|
||||||
*/
|
*/
|
||||||
public void testDeleteTrack() {
|
public void testDeleteTrack() {
|
||||||
// Insert three tracks, points of two tracks and way point of one track.
|
// Insert three tracks, points of two tracks and way point of one track.
|
||||||
@@ -280,7 +280,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
|||||||
null, WaypointsColumns._ID);
|
null, WaypointsColumns._ID);
|
||||||
assertEquals(1, waypointCursor.getCount());
|
assertEquals(1, waypointCursor.getCount());
|
||||||
// Delete one track.
|
// Delete one track.
|
||||||
providerUtils.deleteTrack(trackId);
|
providerUtils.deleteTrack(context, trackId);
|
||||||
// Check whether all data of a track has been deleted.
|
// Check whether all data of a track has been deleted.
|
||||||
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null,
|
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null,
|
||||||
TracksColumns._ID);
|
TracksColumns._ID);
|
||||||
@@ -431,7 +431,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method
|
* Tests the method
|
||||||
* {@link MyTracksProviderUtilsImpl#deleteWaypoint(long, DescriptionGenerator)}
|
* {@link MyTracksProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)}
|
||||||
* when there is only one waypoint in the track.
|
* when there is only one waypoint in the track.
|
||||||
*/
|
*/
|
||||||
public void testDeleteWaypoint_onlyOneWayPoint() {
|
public void testDeleteWaypoint_onlyOneWayPoint() {
|
||||||
@@ -460,14 +460,14 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
providerUtils.deleteWaypoint(1, descriptionGenerator);
|
providerUtils.deleteWaypoint(context, 1, descriptionGenerator);
|
||||||
|
|
||||||
assertNull(providerUtils.getWaypoint(1));
|
assertNull(providerUtils.getWaypoint(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method
|
* Tests the method
|
||||||
* {@link MyTracksProviderUtilsImpl#deleteWaypoint(long, DescriptionGenerator)}
|
* {@link MyTracksProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)}
|
||||||
* when there is more than one waypoint in the track.
|
* when there is more than one waypoint in the track.
|
||||||
*/
|
*/
|
||||||
public void testDeleteWaypoint_hasNextWayPoint() {
|
public void testDeleteWaypoint_hasNextWayPoint() {
|
||||||
@@ -515,7 +515,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
providerUtils.deleteWaypoint(1, descriptionGenerator);
|
providerUtils.deleteWaypoint(context, 1, descriptionGenerator);
|
||||||
|
|
||||||
assertNull(providerUtils.getWaypoint(1));
|
assertNull(providerUtils.getWaypoint(1));
|
||||||
assertEquals(MyTracksProviderUtilsImplTest.MOCK_DESC, providerUtils.getWaypoint(2)
|
assertEquals(MyTracksProviderUtilsImplTest.MOCK_DESC, providerUtils.getWaypoint(2)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class SearchEngineTest extends AndroidTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
providerUtils.deleteAllTracks();
|
providerUtils.deleteAllTracks(getContext());
|
||||||
|
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -244,7 +244,7 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
expect(
|
expect(
|
||||||
myTracksProviderUtils.getTrack(PreferencesUtils.getLong(getContext(),
|
myTracksProviderUtils.getTrack(PreferencesUtils.getLong(getContext(),
|
||||||
R.string.recording_track_id_key))).andStubReturn(null);
|
R.string.recording_track_id_key))).andStubReturn(null);
|
||||||
myTracksProviderUtils.deleteTrack(TRACK_ID_0);
|
myTracksProviderUtils.deleteTrack(getContext(), TRACK_ID_0);
|
||||||
AndroidMock.replay(myTracksProviderUtils);
|
AndroidMock.replay(myTracksProviderUtils);
|
||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
|
||||||
|
|||||||
+2
-2
@@ -74,7 +74,7 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
||||||
|
|
||||||
myTracksProviderUtils.clearTrack(TRACK_ID_0);
|
myTracksProviderUtils.clearTrack(getContext(), TRACK_ID_0);
|
||||||
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||||
|
|
||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
@@ -108,7 +108,7 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
|
|
||||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
|
|
||||||
myTracksProviderUtils.clearTrack(TRACK_ID_0);
|
myTracksProviderUtils.clearTrack(getContext(), TRACK_ID_0);
|
||||||
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||||
|
|
||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
|
|||||||
+24
-36
@@ -88,18 +88,16 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
tripStatisticsUpdater.updateElevation(elevation);
|
tripStatisticsUpdater.updateElevation(elevation);
|
||||||
assertEquals(elevation, tripStatisticsUpdater.getSmoothedElevation());
|
assertEquals(elevation, tripStatisticsUpdater.getSmoothedElevation());
|
||||||
|
|
||||||
if (i >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
assertEquals(elevation, tripStatistics.getMinElevation());
|
||||||
assertEquals(elevation, tripStatistics.getMinElevation());
|
assertEquals(elevation, tripStatistics.getMaxElevation());
|
||||||
assertEquals(elevation, tripStatistics.getMaxElevation());
|
assertEquals(elevation, tripStatistics.getTotalElevationGain());
|
||||||
assertEquals(0.0, tripStatistics.getTotalElevationGain());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, Double)} with
|
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with
|
||||||
* elevation gain.
|
* elevation gain.
|
||||||
*/
|
*/
|
||||||
public void testElevationGain() throws Exception {
|
public void testElevationGain() throws Exception {
|
||||||
@@ -108,34 +106,27 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
assertEquals(i, tripStatisticsUpdater.getSmoothedElevation(),
|
assertEquals(i, tripStatisticsUpdater.getSmoothedElevation(),
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
|
|
||||||
if (i >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
TripStatistics data = tripStatisticsUpdater.getTripStatistics();
|
||||||
TripStatistics data = tripStatisticsUpdater.getTripStatistics();
|
assertEquals(0.0, data.getMinElevation());
|
||||||
assertEquals(12.0, data.getMinElevation());
|
assertEquals(i, data.getMaxElevation(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
i, data.getMaxElevation(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
i, data.getTotalElevationGain(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
||||||
assertEquals(
|
|
||||||
i, data.getTotalElevationGain(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, Double)} with grade
|
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with grade
|
||||||
* of 1 and -1.
|
* of 1 and -1.
|
||||||
*/
|
*/
|
||||||
public void testGradeSimple() throws Exception {
|
public void testGradeSimple() throws Exception {
|
||||||
for (double i = 0; i < 1000; i++) {
|
for (double i = 0; i < 1000; i++) {
|
||||||
tripStatisticsUpdater.updateGrade(100, Double.valueOf(100));
|
tripStatisticsUpdater.updateGrade(100.0, 100.0);
|
||||||
if (i >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR
|
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||||
+ TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR) {
|
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
||||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
|
||||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (double i = 0; i < 1000; i++) {
|
for (double i = 0; i < 1000; i++) {
|
||||||
tripStatisticsUpdater.updateGrade(100, Double.valueOf(-100));
|
tripStatisticsUpdater.updateGrade(100.0, -100.0);
|
||||||
if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR
|
if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR) {
|
||||||
&& i >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR) {
|
|
||||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||||
// add 0.1 delta since changing min grade from 1 to -1
|
// add 0.1 delta since changing min grade from 1 to -1
|
||||||
assertEquals(-1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade(), 0.1);
|
assertEquals(-1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade(), 0.1);
|
||||||
@@ -144,7 +135,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, Double)} with
|
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with
|
||||||
* distance of 1. The grade should get ignored.
|
* distance of 1. The grade should get ignored.
|
||||||
*/
|
*/
|
||||||
public void testGradeIgnoreShort() throws Exception {
|
public void testGradeIgnoreShort() throws Exception {
|
||||||
@@ -154,7 +145,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
* elevation buffer.
|
* elevation buffer.
|
||||||
*/
|
*/
|
||||||
tripStatisticsUpdater.updateElevation(i);
|
tripStatisticsUpdater.updateElevation(i);
|
||||||
tripStatisticsUpdater.updateGrade(1, Double.valueOf(100));
|
tripStatisticsUpdater.updateGrade(1.0, 100.0);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Double.NEGATIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
Double.NEGATIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||||
assertEquals(
|
assertEquals(
|
||||||
@@ -201,9 +192,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
double speed = 4.0;
|
double speed = 4.0;
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
tripStatisticsUpdater.updateSpeed(i + ONE_SECOND, speed, i, speed);
|
tripStatisticsUpdater.updateSpeed(i + ONE_SECOND, speed, i, speed);
|
||||||
if (i >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
|
assertEquals(speed, tripStatisticsUpdater.getTripStatistics().getMaxSpeed());
|
||||||
assertEquals(speed, tripStatisticsUpdater.getTripStatistics().getMaxSpeed());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +223,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
assertEquals(i + locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
assertEquals(i + locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
if (i + locationOffset >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
if (i + locationOffset >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||||
assertEquals(12.0, tripStatistics.getMinElevation());
|
assertEquals(0.0, tripStatistics.getMinElevation());
|
||||||
assertEquals(i + locationOffset, tripStatistics.getMaxElevation(),
|
assertEquals(i + locationOffset, tripStatistics.getMaxElevation(),
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
assertEquals(i + locationOffset, tripStatistics.getTotalElevationGain(),
|
assertEquals(i + locationOffset, tripStatistics.getTotalElevationGain(),
|
||||||
@@ -248,8 +237,9 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
// If there are only moving locations in the track.
|
// If there are only moving locations in the track.
|
||||||
if (locationOffset == 0 && (i + locationOffset) >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR
|
if (locationOffset == 0 && (i + locationOffset) >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR
|
||||||
+ TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR) {
|
+ TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR) {
|
||||||
|
// 0.5 m / 111 m = .0045
|
||||||
|
assertEquals(0.0045, tripStatistics.getMinGrade(), 0.0001);
|
||||||
// 1 m / 111 m = .009
|
// 1 m / 111 m = .009
|
||||||
assertEquals(0.009, tripStatistics.getMinGrade(), 0.0001);
|
|
||||||
assertEquals(0.009, tripStatistics.getMaxGrade(), 0.0001);
|
assertEquals(0.009, tripStatistics.getMaxGrade(), 0.0001);
|
||||||
}
|
}
|
||||||
assertEquals((i + locationOffset) * 111.0, tripStatistics.getTotalDistance(),
|
assertEquals((i + locationOffset) * 111.0, tripStatistics.getTotalDistance(),
|
||||||
@@ -280,14 +270,12 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
assertEquals((locationOffset) * TEN_SECONDS, tripStatistics.getMovingTime());
|
assertEquals((locationOffset) * TEN_SECONDS, tripStatistics.getMovingTime());
|
||||||
assertEquals(locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
assertEquals(locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
assertEquals(12.0, tripStatistics.getMinElevation());
|
assertEquals(0.0, tripStatistics.getMinElevation());
|
||||||
assertEquals(locationOffset, tripStatistics.getMaxElevation(),
|
assertEquals(locationOffset, tripStatistics.getMaxElevation(),
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
assertEquals(locationOffset, tripStatistics.getTotalElevationGain(),
|
assertEquals(locationOffset, tripStatistics.getTotalElevationGain(),
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
||||||
if (locationOffset >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
|
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
||||||
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
|
||||||
}
|
|
||||||
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
locationOffset * 111.0, tripStatistics.getTotalDistance(), locationOffset * 111.0 * 0.01);
|
locationOffset * 111.0, tripStatistics.getTotalDistance(), locationOffset * 111.0 * 0.01);
|
||||||
|
|||||||
Reference in New Issue
Block a user