From 74e09e1fa909b54181e021820a7104a3542b0063 Mon Sep 17 00:00:00 2001 From: Dennis Guse Date: Sat, 5 Sep 2020 10:13:01 +0200 Subject: [PATCH] Refactoring to marker: data class and ContentProviderUtils. #389 --- .../opentracks/content/SearchEngineTest.java | 54 ++-- .../opentracks/content/data/TestDataUtil.java | 4 +- .../provider/CustomContentProviderTest.java | 6 +- .../CustomContentProviderUtilsTest.java | 196 ++++++------- .../provider/CustomSQLiteOpenHelperTest.java | 12 +- .../AbstractTestFileTrackImporter.java | 6 +- .../io/file/importer/ExportImportTest.java | 18 +- .../services/TrackRecordingServiceTest.java | 8 +- .../opentracks/MarkerDetailActivity.java | 12 +- .../opentracks/MarkerEditActivity.java | 12 +- .../opentracks/MarkerListActivity.java | 28 +- .../opentracks/SearchListActivity.java | 8 +- .../opentracks/TrackListActivity.java | 2 +- .../opentracks/TrackRecordedActivity.java | 6 +- .../opentracks/chart/ChartView.java | 14 +- .../opentracks/content/SearchEngine.java | 30 +- .../opentracks/content/TrackDataHub.java | 10 +- .../opentracks/content/TrackDataListener.java | 6 +- .../data/{Waypoint.java => Marker.java} | 8 +- ...ypointsColumns.java => MarkerColumns.java} | 2 +- .../provider/ContentProviderUtils.java | 276 ++++++++---------- .../provider/CustomContentProvider.java | 36 +-- .../provider/CustomSQLiteOpenHelper.java | 6 +- .../opentracks/fragments/ChartFragment.java | 4 +- .../fragments/DeleteMarkerDialogFragment.java | 10 +- .../fragments/MarkerDetailFragment.java | 12 +- .../StatisticsRecordingFragment.java | 4 +- .../io/file/exporter/FileTrackExporter.java | 6 +- .../io/file/exporter/GpxTrackWriter.java | 4 +- .../io/file/exporter/KmlTrackWriter.java | 6 +- .../io/file/exporter/KmzTrackExporter.java | 10 +- .../io/file/exporter/TrackWriter.java | 6 +- .../importer/AbstractFileTrackImporter.java | 12 +- .../io/file/importer/KmzTrackImporter.java | 6 +- .../services/TrackRecordingService.java | 12 +- .../services/TrackRecordingServiceBinder.java | 4 +- .../TrackRecordingServiceConnection.java | 6 +- .../TrackRecordingServiceInterface.java | 4 +- .../opentracks/util/IntentDashboardUtils.java | 4 +- .../opentracks/util/IntentUtils.java | 4 +- 40 files changed, 421 insertions(+), 453 deletions(-) rename src/main/java/de/dennisguse/opentracks/content/data/{Waypoint.java => Marker.java} (94%) rename src/main/java/de/dennisguse/opentracks/content/data/{WaypointsColumns.java => MarkerColumns.java} (98%) diff --git a/src/androidTest/java/de/dennisguse/opentracks/content/SearchEngineTest.java b/src/androidTest/java/de/dennisguse/opentracks/content/SearchEngineTest.java index 173915217..23c932151 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/content/SearchEngineTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/content/SearchEngineTest.java @@ -34,8 +34,8 @@ import java.util.List; import de.dennisguse.opentracks.content.SearchEngine.ScoredResult; import de.dennisguse.opentracks.content.SearchEngine.SearchQuery; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.content.provider.CustomContentProvider; import de.dennisguse.opentracks.content.provider.CustomSQLiteOpenHelper; @@ -102,36 +102,36 @@ public class SearchEngineTest { return insertTrack(title, "", "", hoursAgo); } - private Waypoint.Id insertWaypoint(String title, String description, String category, double distance, long hoursAgo, Track.Id trackId) { + private Marker.Id insertWaypoint(String title, String description, String category, double distance, long hoursAgo, Track.Id trackId) { Location location = new Location(HERE); location.setLatitude(location.getLatitude() + distance); location.setLongitude(location.getLongitude() + distance); if (hoursAgo >= 0) { location.setTime(NOW - hoursAgo * 1000L * 60L * 60L); } - Waypoint waypoint = new Waypoint(location); + Marker waypoint = new Marker(location); waypoint.setName(title); waypoint.setDescription(description); waypoint.setCategory(category); waypoint.setTrackId(trackId); - Uri uri = providerUtils.insertWaypoint(waypoint); - return new Waypoint.Id(ContentUris.parseId(uri)); + Uri uri = providerUtils.insertMarker(waypoint); + return new Marker.Id(ContentUris.parseId(uri)); } - private Waypoint.Id insertWaypoint(String title, String description, String category) { + private Marker.Id insertWaypoint(String title, String description, String category) { return insertWaypoint(title, description, category, 0.0, -1, null); } - private Waypoint.Id insertWaypoint(String title, double distance) { + private Marker.Id insertWaypoint(String title, double distance) { return insertWaypoint(title, "", "", distance, -1, null); } - private Waypoint.Id insertWaypoint(String title, long hoursAgo) { + private Marker.Id insertWaypoint(String title, long hoursAgo) { return insertWaypoint(title, "", "", 0.0, hoursAgo, null); } - private Waypoint.Id insertWaypoint(String title, long hoursAgo, Track.Id trackId) { + private Marker.Id insertWaypoint(String title, long hoursAgo, Track.Id trackId) { return insertWaypoint(title, "", "", 0.0, hoursAgo, trackId); } @@ -171,12 +171,12 @@ public class SearchEngineTest { // - one which will match in title and description // - one which will match in all fields insertWaypoint("bb", "cc", "dd"); - Waypoint.Id descriptionMatchId = insertWaypoint("bb", "aa", "cc"); - Waypoint.Id categoryMatchId = insertWaypoint("bb", "cc", "aa"); - Waypoint.Id titleMatchId = insertWaypoint("aa", "bb", "cc"); - Waypoint.Id titleCategoryMatchId = insertWaypoint("aa", "bb", "ca"); - Waypoint.Id titleDescriptionMatchId = insertWaypoint("aa", "ba", "cc"); - Waypoint.Id allMatchId = insertWaypoint("aa", "ba", "ca"); + Marker.Id descriptionMatchId = insertWaypoint("bb", "aa", "cc"); + Marker.Id categoryMatchId = insertWaypoint("bb", "cc", "aa"); + Marker.Id titleMatchId = insertWaypoint("aa", "bb", "cc"); + Marker.Id titleCategoryMatchId = insertWaypoint("aa", "bb", "ca"); + Marker.Id titleDescriptionMatchId = insertWaypoint("aa", "ba", "cc"); + Marker.Id allMatchId = insertWaypoint("aa", "ba", "ca"); SearchQuery query = new SearchQuery("a", null, null, NOW); ArrayList results = new ArrayList<>(engine.search(query)); @@ -193,9 +193,9 @@ public class SearchEngineTest { // - one waypoint which will match by title // - one track which won't match // - one track which will match by title - Waypoint.Id descriptionWaypointId = insertWaypoint("bb", "aa", "cc"); + Marker.Id descriptionWaypointId = insertWaypoint("bb", "aa", "cc"); insertWaypoint("bb", "cc", "dd"); - Waypoint.Id titleWaypointId = insertWaypoint("aa", "bb", "cc"); + Marker.Id titleWaypointId = insertWaypoint("aa", "bb", "cc"); insertTrack("bb", "cc", "dd"); Track.Id trackId = insertTrack("aa", "bb", "cc"); @@ -212,9 +212,9 @@ public class SearchEngineTest { @Test public void testSearchWaypointDistance() { // All results match text, but they're at difference distances from the user. - Waypoint.Id farFarAwayId = insertWaypoint("aa", 0.3); - Waypoint.Id nearId = insertWaypoint("ab", 0.1); - Waypoint.Id farId = insertWaypoint("ac", 0.2); + Marker.Id farFarAwayId = insertWaypoint("aa", 0.3); + Marker.Id nearId = insertWaypoint("ab", 0.1); + Marker.Id farId = insertWaypoint("ac", 0.2); SearchQuery query = new SearchQuery("a", HERE, null, NOW); ArrayList results = new ArrayList<>(engine.search(query)); @@ -239,9 +239,9 @@ public class SearchEngineTest { @Test public void testSearchWaypointRecent() { // All results match text, but they're were recorded at different times. - Waypoint.Id oldestId = insertWaypoint("aa", 2); - Waypoint.Id recentId = insertWaypoint("ab", 0); - Waypoint.Id oldId = insertWaypoint("ac", 1); + Marker.Id oldestId = insertWaypoint("aa", 2); + Marker.Id recentId = insertWaypoint("ab", 0); + Marker.Id oldId = insertWaypoint("ac", 1); SearchQuery query = new SearchQuery("a", null, null, NOW); ArrayList results = new ArrayList<>(engine.search(query)); @@ -266,8 +266,8 @@ public class SearchEngineTest { @Test public void testSearchCurrentTrackWaypoint() { // All results match text, but one of them is in the current track. - Waypoint.Id otherId = insertWaypoint("aa", 1, new Track.Id(456)); - Waypoint.Id currentId = insertWaypoint("ab", 1, new Track.Id(123)); + Marker.Id otherId = insertWaypoint("aa", 1, new Track.Id(456)); + Marker.Id currentId = insertWaypoint("ab", 1, new Track.Id(123)); SearchQuery query = new SearchQuery("a", null, new Track.Id(123), NOW); ArrayList results = new ArrayList<>(engine.search(query)); @@ -298,13 +298,13 @@ public class SearchEngineTest { } } - private void assertWaypointResult(Waypoint.Id waypointId, ScoredResult result) { + private void assertWaypointResult(Marker.Id waypointId, ScoredResult result) { assertNotNull("Not a waypoint", result.waypoint); assertNull("Ambiguous result", result.track); assertEquals(waypointId, result.waypoint.getId()); } - private void assertWaypointResults(List results, Waypoint.Id... waypointIds) { + private void assertWaypointResults(List results, Marker.Id... waypointIds) { long[] longWaypointIds = new long[waypointIds.length]; for (int i = 0; i < waypointIds.length; i++) { longWaypointIds[i] = waypointIds[i].getId(); diff --git a/src/androidTest/java/de/dennisguse/opentracks/content/data/TestDataUtil.java b/src/androidTest/java/de/dennisguse/opentracks/content/data/TestDataUtil.java index 30902e9f3..83c272937 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/content/data/TestDataUtil.java +++ b/src/androidTest/java/de/dennisguse/opentracks/content/data/TestDataUtil.java @@ -93,12 +93,12 @@ public class TestDataUtil { * @param location The location. * @return the Waypoint created. */ - public static Waypoint createWaypointWithPhoto(Context context, Track.Id trackId, Location location) throws IOException { + public static Marker createWaypointWithPhoto(Context context, Track.Id trackId, Location location) throws IOException { File dstFile = new File(FileUtils.getImageUrl(context, trackId)); dstFile.createNewFile(); Uri photoUri = FileUtils.getUriForFile(context, dstFile); String photoUrl = photoUri.toString(); - return new Waypoint("Waypoint name", "Waypoint description", "Waypoint category", "", trackId, 0.0, 0, location, photoUrl); + return new Marker("Waypoint name", "Waypoint description", "Waypoint category", "", trackId, 0.0, 0, location, photoUrl); } } diff --git a/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomContentProviderTest.java b/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomContentProviderTest.java index 1bace4ece..26e4b9d1a 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomContentProviderTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomContentProviderTest.java @@ -25,9 +25,9 @@ import androidx.test.core.app.ApplicationProvider; import org.junit.Before; import org.junit.Test; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.TrackPointsColumns; import de.dennisguse.opentracks.content.data.TracksColumns; -import de.dennisguse.opentracks.content.data.WaypointsColumns; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -67,7 +67,7 @@ public class CustomContentProviderTest { assertEquals(TrackPointsColumns.CONTENT_TYPE, customContentProvider.getType(TrackPointsColumns.CONTENT_URI_BY_ID)); assertEquals(TrackPointsColumns.CONTENT_ITEMTYPE, customContentProvider.getType(ContentUris.appendId(TrackPointsColumns.CONTENT_URI_BY_TRACKID.buildUpon(), 1).build())); - assertEquals(WaypointsColumns.CONTENT_TYPE, customContentProvider.getType(WaypointsColumns.CONTENT_URI)); - assertEquals(WaypointsColumns.CONTENT_ITEMTYPE, customContentProvider.getType(ContentUris.appendId(WaypointsColumns.CONTENT_URI.buildUpon(), 1).build())); + assertEquals(MarkerColumns.CONTENT_TYPE, customContentProvider.getType(MarkerColumns.CONTENT_URI)); + assertEquals(MarkerColumns.CONTENT_ITEMTYPE, customContentProvider.getType(ContentUris.appendId(MarkerColumns.CONTENT_URI.buildUpon(), 1).build())); } } \ No newline at end of file diff --git a/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomContentProviderUtilsTest.java b/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomContentProviderUtilsTest.java index 4835b8811..b7a517715 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomContentProviderUtilsTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomContentProviderUtilsTest.java @@ -38,13 +38,13 @@ import java.util.Arrays; import java.util.List; import java.util.UUID; +import de.dennisguse.opentracks.content.data.Marker; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; import de.dennisguse.opentracks.content.data.TrackPointsColumns; import de.dennisguse.opentracks.content.data.TracksColumns; -import de.dennisguse.opentracks.content.data.Waypoint; -import de.dennisguse.opentracks.content.data.WaypointsColumns; import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.util.FileUtils; import de.dennisguse.opentracks.util.UUIDUtils; @@ -212,15 +212,15 @@ public class CustomContentProviderUtilsTest { Track.Id trackId = new Track.Id(System.currentTimeMillis()); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); - Waypoint waypoint = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId)); - contentProviderUtils.insertWaypoint(waypoint); + Marker waypoint = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId)); + contentProviderUtils.insertMarker(waypoint); ContentResolver contentResolver = context.getContentResolver(); Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID); assertEquals(1, tracksCursor.getCount()); Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); assertEquals(10, tracksPointsCursor.getCount()); - Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID); + Cursor waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); assertEquals(1, waypointCursor.getCount()); // Delete all. contentProviderUtils.deleteAllTracks(context); @@ -229,7 +229,7 @@ public class CustomContentProviderUtilsTest { assertEquals(0, tracksCursor.getCount()); tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); assertEquals(0, tracksPointsCursor.getCount()); - waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID); + waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); assertEquals(0, waypointCursor.getCount()); } @@ -243,15 +243,15 @@ public class CustomContentProviderUtilsTest { Track track = TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId); - Waypoint waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); - contentProviderUtils.insertWaypoint(waypoint); + Marker waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); + contentProviderUtils.insertMarker(waypoint); ContentResolver contentResolver = context.getContentResolver(); Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID); assertEquals(1, tracksCursor.getCount()); Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); assertEquals(10, tracksPointsCursor.getCount()); - Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID); + Cursor waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); assertEquals(1, waypointCursor.getCount()); // Check waypoint has photo and it's in the external storage. assertTrue(waypoint.hasPhoto()); @@ -266,7 +266,7 @@ public class CustomContentProviderUtilsTest { assertEquals(0, tracksCursor.getCount()); tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); assertEquals(0, tracksPointsCursor.getCount()); - waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID); + waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); assertEquals(0, waypointCursor.getCount()); assertFalse(dir.exists()); } @@ -287,16 +287,16 @@ public class CustomContentProviderUtilsTest { TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId2, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId3, 10); - Waypoint waypoint = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId2)); + Marker waypoint = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId2)); waypoint.setTrackId(trackId1); - contentProviderUtils.insertWaypoint(waypoint); + contentProviderUtils.insertMarker(waypoint); ContentResolver contentResolver = context.getContentResolver(); Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID); assertEquals(3, tracksCursor.getCount()); Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); assertEquals(20, tracksPointsCursor.getCount()); - Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID); + Cursor waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); assertEquals(1, waypointCursor.getCount()); // Delete one track. contentProviderUtils.deleteTrack(context, trackId1); @@ -305,7 +305,7 @@ public class CustomContentProviderUtilsTest { assertEquals(2, tracksCursor.getCount()); tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); assertEquals(20, tracksPointsCursor.getCount()); - waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID); + waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); assertEquals(0, waypointCursor.getCount()); } @@ -326,13 +326,13 @@ public class CustomContentProviderUtilsTest { // Insert a waypoint in tracks trackId and trackId + 1. TrackPoint trackPoint1 = contentProviderUtils.getLastValidTrackPoint(trackId1); - Waypoint waypoint1 = TestDataUtil.createWaypointWithPhoto(context, trackId1, trackPoint1.getLocation()); - contentProviderUtils.insertWaypoint(waypoint1); + Marker waypoint1 = TestDataUtil.createWaypointWithPhoto(context, trackId1, trackPoint1.getLocation()); + contentProviderUtils.insertMarker(waypoint1); File dir1 = FileUtils.getPhotoDir(context, trackId1); TrackPoint trackPoint2 = contentProviderUtils.getLastValidTrackPoint(trackId2); - Waypoint waypoint2 = TestDataUtil.createWaypointWithPhoto(context, trackId2, trackPoint2.getLocation()); - contentProviderUtils.insertWaypoint(waypoint2); + Marker waypoint2 = TestDataUtil.createWaypointWithPhoto(context, trackId2, trackPoint2.getLocation()); + contentProviderUtils.insertMarker(waypoint2); File dir2 = FileUtils.getPhotoDir(context, trackId2); // Check. @@ -341,7 +341,7 @@ public class CustomContentProviderUtilsTest { assertEquals(3, tracksCursor.getCount()); Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); assertEquals(30, tracksPointsCursor.getCount()); - Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID); + Cursor waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); assertEquals(2, waypointCursor.getCount()); assertTrue(waypoint1.hasPhoto()); assertTrue(dir1.isDirectory()); @@ -357,7 +357,7 @@ public class CustomContentProviderUtilsTest { assertEquals(2, tracksCursor.getCount()); tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); assertEquals(20, tracksPointsCursor.getCount()); - waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID); + waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); assertEquals(1, waypointCursor.getCount()); assertFalse(dir1.exists()); assertTrue(dir2.exists()); @@ -439,7 +439,7 @@ public class CustomContentProviderUtilsTest { } /** - * Tests the method {@link ContentProviderUtils#createContentValues(Waypoint)}. + * Tests the method {@link ContentProviderUtils#createContentValues(Marker)}. */ @Test public void testCreateContentValues_waypoint() { @@ -463,30 +463,30 @@ public class CustomContentProviderUtilsTest { track.first.setTrackStatistics(statistics); contentProviderUtils.insertTrack(track.first); - Waypoint waypoint = new Waypoint(track.second[0]); + Marker waypoint = new Marker(track.second[0]); waypoint.setDescription(TEST_DESC); - contentProviderUtils.insertWaypoint(waypoint); + contentProviderUtils.insertMarker(waypoint); ContentProviderUtils contentProviderUtils = new ContentProviderUtils(contentResolverMock); - Waypoint.Id waypointId = new Waypoint.Id(System.currentTimeMillis()); + Marker.Id waypointId = new Marker.Id(System.currentTimeMillis()); waypoint.setId(waypointId); ContentValues contentValues = contentProviderUtils.createContentValues(waypoint); - assertEquals(waypointId.getId(), contentValues.get(WaypointsColumns._ID)); - assertEquals((int) (TestDataUtil.INITIAL_LONGITUDE * 1000000), contentValues.get(WaypointsColumns.LONGITUDE)); - assertEquals(TEST_DESC, contentValues.get(WaypointsColumns.DESCRIPTION)); + assertEquals(waypointId.getId(), contentValues.get(MarkerColumns._ID)); + assertEquals((int) (TestDataUtil.INITIAL_LONGITUDE * 1000000), contentValues.get(MarkerColumns.LONGITUDE)); + assertEquals(TEST_DESC, contentValues.get(MarkerColumns.DESCRIPTION)); } /** - * Tests the method {@link ContentProviderUtils#createWaypoint(Cursor)}. + * Tests the method {@link ContentProviderUtils#createMarker(Cursor)}. */ @Test public void testCreateWaypoint() { int startColumnIndex = 1; int columnIndex = startColumnIndex; - when(cursorMock.getColumnIndexOrThrow(WaypointsColumns._ID)).thenReturn(columnIndex++); - when(cursorMock.getColumnIndexOrThrow(WaypointsColumns.NAME)).thenReturn(columnIndex++); - when(cursorMock.getColumnIndexOrThrow(WaypointsColumns.TRACKID)).thenReturn(columnIndex++); + when(cursorMock.getColumnIndexOrThrow(MarkerColumns._ID)).thenReturn(columnIndex++); + when(cursorMock.getColumnIndexOrThrow(MarkerColumns.NAME)).thenReturn(columnIndex++); + when(cursorMock.getColumnIndexOrThrow(MarkerColumns.TRACKID)).thenReturn(columnIndex++); columnIndex = startColumnIndex; // Id when(cursorMock.isNull(columnIndex++)).thenReturn(false); @@ -505,7 +505,7 @@ public class CustomContentProviderUtilsTest { long trackId = 11L; when(cursorMock.getLong(columnIndex++)).thenReturn(trackId); - Waypoint waypoint = contentProviderUtils.createWaypoint(cursorMock); + Marker waypoint = contentProviderUtils.createMarker(cursorMock); assertEquals(id, waypoint.getId().getId()); assertEquals(name, waypoint.getName()); assertEquals(trackId, waypoint.getTrackId().getId()); @@ -513,7 +513,7 @@ public class CustomContentProviderUtilsTest { /** * Tests the method - * {@link ContentProviderUtils#deleteWaypoint(Context, Waypoint.Id)} + * {@link ContentProviderUtils#deleteMarker(Context, Marker.Id)} * when there is only one waypoint in the track. */ @Test @@ -522,26 +522,26 @@ public class CustomContentProviderUtilsTest { TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); // Insert at first. - Waypoint waypoint1 = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId)); + Marker waypoint1 = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId)); waypoint1.setDescription(TEST_DESC); waypoint1.setTrackId(trackId); - contentProviderUtils.insertWaypoint(waypoint1); + contentProviderUtils.insertMarker(waypoint1); // Check insert was done. - assertEquals(contentProviderUtils.getWaypointCount(trackId), 1); + assertEquals(contentProviderUtils.getMarkerCount(trackId), 1); // Get waypoint id that needs to delete. - Waypoint.Id waypoint1Id = new Waypoint.Id(ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint1))); + Marker.Id waypoint1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint1))); // Delete - contentProviderUtils.deleteWaypoint(context, waypoint1Id); + contentProviderUtils.deleteMarker(context, waypoint1Id); - assertNull(contentProviderUtils.getWaypoint(waypoint1Id)); + assertNull(contentProviderUtils.getMarker(waypoint1Id)); } /** * Tests the method - * {@link ContentProviderUtils#deleteWaypoint(Context, Waypoint.Id)} + * {@link ContentProviderUtils#deleteMarker(Context, Marker.Id)} * when there is only one waypoint in the track. */ @Test @@ -551,14 +551,14 @@ public class CustomContentProviderUtilsTest { // Insert at first. TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId); - Waypoint waypoint1 = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); - contentProviderUtils.insertWaypoint(waypoint1); + Marker waypoint1 = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); + contentProviderUtils.insertMarker(waypoint1); // Check insert was done. - assertEquals(contentProviderUtils.getWaypointCount(trackId), 1); + assertEquals(contentProviderUtils.getMarkerCount(trackId), 1); // Get waypoint id that needs to delete. - Waypoint.Id waypoint1Id = new Waypoint.Id(ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint1))); + Marker.Id waypoint1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint1))); // Check waypoint has photo and it's in the external storage. assertTrue(waypoint1.hasPhoto()); @@ -568,15 +568,15 @@ public class CustomContentProviderUtilsTest { assertTrue(dir.exists()); // Delete - contentProviderUtils.deleteWaypoint(context, waypoint1Id); + contentProviderUtils.deleteMarker(context, waypoint1Id); // Check waypoint doesn't exists and photo folder was deleted. - assertNull(contentProviderUtils.getWaypoint(waypoint1Id)); + assertNull(contentProviderUtils.getMarker(waypoint1Id)); assertFalse(dir.exists()); } /** - * Tests the method {@link ContentProviderUtils#deleteWaypoint(Context, Waypoint.Id)} when there is more than one waypoint in the track. + * Tests the method {@link ContentProviderUtils#deleteMarker(Context, Marker.Id)} when there is more than one waypoint in the track. */ @Test public void testDeleteWaypoint_hasNextWayPoint() { @@ -600,67 +600,67 @@ public class CustomContentProviderUtilsTest { // TestDataUtil.insertTrackWithLocations(contentProviderUtils, track); // Insert at first. - Waypoint waypoint1 = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId)); + Marker waypoint1 = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId)); waypoint1.setDescription(MOCK_DESC); waypoint1.setTrackId(trackId); - Waypoint.Id waypoint1Id = new Waypoint.Id(ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint1))); + Marker.Id waypoint1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint1))); - Waypoint waypoint2 = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId)); + Marker waypoint2 = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId)); waypoint2.setDescription(MOCK_DESC); waypoint2.setTrackId(trackId); - Waypoint.Id waypoint2Id = new Waypoint.Id(ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint2))); + Marker.Id waypoint2Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint2))); // Delete - assertNotNull(contentProviderUtils.getWaypoint(waypoint1Id)); - contentProviderUtils.deleteWaypoint(context, waypoint1Id); - assertNull(contentProviderUtils.getWaypoint(waypoint1Id)); + assertNotNull(contentProviderUtils.getMarker(waypoint1Id)); + contentProviderUtils.deleteMarker(context, waypoint1Id); + assertNull(contentProviderUtils.getMarker(waypoint1Id)); - assertEquals(MOCK_DESC, contentProviderUtils.getWaypoint(waypoint2Id).getDescription()); + assertEquals(MOCK_DESC, contentProviderUtils.getMarker(waypoint2Id).getDescription()); } /** - * Tests the method {@link ContentProviderUtils#getNextWaypointNumber(Track.Id)}. + * Tests the method {@link ContentProviderUtils#getNextMarkerNumber(Track.Id)}. */ @Test public void testGetNextWaypointNumber() { Track.Id trackId = new Track.Id(System.currentTimeMillis()); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); - Waypoint waypoint1 = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId)); + Marker waypoint1 = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId)); waypoint1.setTrackId(trackId); - Waypoint waypoint2 = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId)); + Marker waypoint2 = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId)); waypoint2.setTrackId(trackId); - Waypoint waypoint3 = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId)); + Marker waypoint3 = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId)); waypoint3.setTrackId(trackId); - Waypoint waypoint4 = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId)); + Marker waypoint4 = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId)); waypoint4.setTrackId(trackId); - contentProviderUtils.insertWaypoint(waypoint1); - contentProviderUtils.insertWaypoint(waypoint2); - contentProviderUtils.insertWaypoint(waypoint3); - contentProviderUtils.insertWaypoint(waypoint4); + contentProviderUtils.insertMarker(waypoint1); + contentProviderUtils.insertMarker(waypoint2); + contentProviderUtils.insertMarker(waypoint3); + contentProviderUtils.insertMarker(waypoint4); - assertEquals(4, contentProviderUtils.getNextWaypointNumber(trackId)); + assertEquals(4, contentProviderUtils.getNextMarkerNumber(trackId)); } /** - * Tests the method {@link ContentProviderUtils#insertWaypoint(Waypoint)} and - * {@link ContentProviderUtils#getWaypoint(Waypoint.Id)}. + * Tests the method {@link ContentProviderUtils#insertMarker(Marker)} and + * {@link ContentProviderUtils#getMarker(Marker.Id)}. */ @Test public void testInsertAndGetWaypoint() { Track.Id trackId = new Track.Id(System.currentTimeMillis()); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); - Waypoint waypoint = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId)); + Marker waypoint = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId)); waypoint.setDescription(TEST_DESC); waypoint.setTrackId(trackId); - Waypoint.Id waypointId = new Waypoint.Id(ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint))); + Marker.Id waypointId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint))); - assertEquals(TEST_DESC, contentProviderUtils.getWaypoint(waypointId).getDescription()); + assertEquals(TEST_DESC, contentProviderUtils.getMarker(waypointId).getDescription()); } /** - * Tests the method {@link ContentProviderUtils#updateWaypoint(Context, Waypoint)}. + * Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}. */ @Test public void testUpdateWaypoint() { @@ -668,21 +668,21 @@ public class CustomContentProviderUtilsTest { TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); // Insert at first. - Waypoint waypoint = new Waypoint(contentProviderUtils.getLastValidTrackPoint(trackId)); + Marker waypoint = new Marker(contentProviderUtils.getLastValidTrackPoint(trackId)); waypoint.setDescription(TEST_DESC); waypoint.setTrackId(trackId); - Waypoint.Id waypointId = new Waypoint.Id(ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint))); + Marker.Id waypointId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint))); // Update - waypoint = contentProviderUtils.getWaypoint(waypointId); + waypoint = contentProviderUtils.getMarker(waypointId); waypoint.setDescription(TEST_DESC_NEW); - contentProviderUtils.updateWaypoint(context, waypoint); + contentProviderUtils.updateMarker(context, waypoint); - assertEquals(TEST_DESC_NEW, contentProviderUtils.getWaypoint(waypointId).getDescription()); + assertEquals(TEST_DESC_NEW, contentProviderUtils.getMarker(waypointId).getDescription()); } /** - * Tests the method {@link ContentProviderUtils#updateWaypoint(Context, Waypoint)}. + * Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}. */ @Test public void testUpdateWaypoint_withPhoto() throws IOException { @@ -693,10 +693,10 @@ public class CustomContentProviderUtilsTest { // Insert at first. TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId); - Waypoint waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); + Marker waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); waypoint.setDescription(TEST_DESC); waypoint.setTrackId(trackId); - Waypoint.Id waypointId = new Waypoint.Id(ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint))); + Marker.Id waypointId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint))); File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.getId()); assertTrue(dir.exists()); @@ -704,13 +704,13 @@ public class CustomContentProviderUtilsTest { assertEquals(1, dir.list().length); // Update - waypoint = contentProviderUtils.getWaypoint(waypointId); + waypoint = contentProviderUtils.getMarker(waypointId); waypoint.setName(TEST_NAME_NEW); waypoint.setDescription(TEST_DESC_NEW); - contentProviderUtils.updateWaypoint(context, waypoint); + contentProviderUtils.updateMarker(context, waypoint); - assertEquals(TEST_NAME_NEW, contentProviderUtils.getWaypoint(waypointId).getName()); - assertEquals(TEST_DESC_NEW, contentProviderUtils.getWaypoint(waypointId).getDescription()); + assertEquals(TEST_NAME_NEW, contentProviderUtils.getMarker(waypointId).getName()); + assertEquals(TEST_DESC_NEW, contentProviderUtils.getMarker(waypointId).getDescription()); assertTrue(waypoint.hasPhoto()); assertTrue(dir.exists()); assertTrue(dir.isDirectory()); @@ -718,7 +718,7 @@ public class CustomContentProviderUtilsTest { } /** - * Tests the method {@link ContentProviderUtils#updateWaypoint(Context, Waypoint)}. + * Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}. */ @Test public void testUpdateWaypoint_delPhotoAndDir() throws IOException { @@ -729,10 +729,10 @@ public class CustomContentProviderUtilsTest { // Insert at first. TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId); - Waypoint waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); + Marker waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); waypoint.setDescription(TEST_DESC); waypoint.setTrackId(trackId); - Waypoint.Id waypointId = new Waypoint.Id(ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint))); + Marker.Id waypointId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint))); File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.getId()); assertTrue(dir.exists()); @@ -740,20 +740,20 @@ public class CustomContentProviderUtilsTest { assertEquals(1, dir.list().length); // Update - waypoint = contentProviderUtils.getWaypoint(waypointId); + waypoint = contentProviderUtils.getMarker(waypointId); waypoint.setName(TEST_NAME_NEW); waypoint.setDescription(TEST_DESC_NEW); waypoint.setPhotoUrl(null); - contentProviderUtils.updateWaypoint(context, waypoint); + contentProviderUtils.updateMarker(context, waypoint); - assertEquals(TEST_NAME_NEW, contentProviderUtils.getWaypoint(waypointId).getName()); - assertEquals(TEST_DESC_NEW, contentProviderUtils.getWaypoint(waypointId).getDescription()); + assertEquals(TEST_NAME_NEW, contentProviderUtils.getMarker(waypointId).getName()); + assertEquals(TEST_DESC_NEW, contentProviderUtils.getMarker(waypointId).getDescription()); assertFalse(waypoint.hasPhoto()); assertFalse(dir.exists()); } /** - * Tests the method {@link ContentProviderUtils#updateWaypoint(Context, Waypoint)}. + * Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}. */ @Test public void testUpdateWaypoint_delPhotoNotDir() throws IOException { @@ -764,14 +764,14 @@ public class CustomContentProviderUtilsTest { // Insert two waypoints with photos. TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId); - Waypoint waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); + Marker waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); waypoint.setDescription(TEST_DESC); waypoint.setTrackId(trackId); - Waypoint otherWaypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); + Marker otherWaypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); otherWaypoint.setDescription(TEST_DESC); otherWaypoint.setTrackId(trackId); - Waypoint.Id waypointId = new Waypoint.Id(ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint))); - contentProviderUtils.insertWaypoint(otherWaypoint); + Marker.Id waypointId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint))); + contentProviderUtils.insertMarker(otherWaypoint); File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.getId()); assertTrue(dir.exists()); @@ -779,11 +779,11 @@ public class CustomContentProviderUtilsTest { assertEquals(2, dir.list().length); // Update one waypoint deleting photo. - waypoint = contentProviderUtils.getWaypoint(waypointId); + waypoint = contentProviderUtils.getMarker(waypointId); waypoint.setPhotoUrl(null); - contentProviderUtils.updateWaypoint(context, waypoint); + contentProviderUtils.updateMarker(context, waypoint); - assertEquals(TEST_DESC, contentProviderUtils.getWaypoint(waypointId).getDescription()); + assertEquals(TEST_DESC, contentProviderUtils.getMarker(waypointId).getDescription()); assertFalse(waypoint.hasPhoto()); assertTrue(dir.exists()); assertTrue(dir.isDirectory()); diff --git a/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomSQLiteOpenHelperTest.java b/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomSQLiteOpenHelperTest.java index 0dd5abe7a..f776cae7b 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomSQLiteOpenHelperTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/content/provider/CustomSQLiteOpenHelperTest.java @@ -18,9 +18,9 @@ import org.junit.runner.RunWith; import java.util.HashMap; import java.util.Map; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.TrackPointsColumns; import de.dennisguse.opentracks.content.data.TracksColumns; -import de.dennisguse.opentracks.content.data.WaypointsColumns; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -45,7 +45,7 @@ public class CustomSQLiteOpenHelperTest { @VisibleForTesting public static Map getTableSQL(SQLiteDatabase db) { HashMap tableSQL = new HashMap<>(); - try (Cursor cursor = db.query("sqlite_master", new String[]{"name", "SQL"}, "name IN ('" + TracksColumns.TABLE_NAME + "', '" + TrackPointsColumns.TABLE_NAME + "', '" + WaypointsColumns.TABLE_NAME + "')", null, null, null, "name")) { + try (Cursor cursor = db.query("sqlite_master", new String[]{"name", "SQL"}, "name IN ('" + TracksColumns.TABLE_NAME + "', '" + TrackPointsColumns.TABLE_NAME + "', '" + MarkerColumns.TABLE_NAME + "')", null, null, null, "name")) { if (cursor != null) { while (cursor.moveToNext()) { tableSQL.put(cursor.getString(0), cursor.getString(1)); @@ -106,8 +106,8 @@ public class CustomSQLiteOpenHelperTest { assertTrue(hasSqlCreate(db, TrackPointsColumns.CREATE_TABLE)); assertTrue(hasSqlCreate(db, TrackPointsColumns.CREATE_TABLE_INDEX)); - assertTrue(hasSqlCreate(db, WaypointsColumns.CREATE_TABLE)); - assertTrue(hasSqlCreate(db, WaypointsColumns.CREATE_TABLE_INDEX)); + assertTrue(hasSqlCreate(db, MarkerColumns.CREATE_TABLE)); + assertTrue(hasSqlCreate(db, MarkerColumns.CREATE_TABLE_INDEX)); } catch (Exception e) { fail(); } @@ -140,13 +140,13 @@ public class CustomSQLiteOpenHelperTest { assertEquals(tablesByCreate.get(TracksColumns.TABLE_NAME), tableByUpgrade.get(TracksColumns.TABLE_NAME)); assertEquals(tablesByCreate.get(TrackPointsColumns.TABLE_NAME), tableByUpgrade.get(TrackPointsColumns.TABLE_NAME)); - assertEquals(tablesByCreate.get(WaypointsColumns.TABLE_NAME), tableByUpgrade.get(WaypointsColumns.TABLE_NAME)); + assertEquals(tablesByCreate.get(MarkerColumns.TABLE_NAME), tableByUpgrade.get(MarkerColumns.TABLE_NAME)); // then - verify custom indices assertEquals(3, indicesByCreate.size()); assertEquals(indicesByUpgrade.get(TracksColumns.TABLE_NAME), indicesByCreate.get(TracksColumns.TABLE_NAME)); assertEquals(indicesByUpgrade.get(TrackPointsColumns.TABLE_NAME), indicesByCreate.get(TrackPointsColumns.TABLE_NAME)); - assertEquals(indicesByUpgrade.get(WaypointsColumns.TABLE_NAME), indicesByCreate.get(WaypointsColumns.TABLE_NAME)); + assertEquals(indicesByUpgrade.get(MarkerColumns.TABLE_NAME), indicesByCreate.get(MarkerColumns.TABLE_NAME)); } @Test diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/AbstractTestFileTrackImporter.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/AbstractTestFileTrackImporter.java index 678f75557..f0e83fae2 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/AbstractTestFileTrackImporter.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/AbstractTestFileTrackImporter.java @@ -33,9 +33,9 @@ import java.util.Locale; import java.util.SimpleTimeZone; import java.util.TimeZone; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.WaypointsColumns; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import static org.junit.Assert.assertEquals; @@ -70,7 +70,7 @@ public abstract class AbstractTestFileTrackImporter { static final long TRACK_POINT_ID_3 = 4; private static final long WAYPOINT_ID_0 = 1; - private static final Uri WAYPOINT_ID_O_URI = ContentUris.appendId(WaypointsColumns.CONTENT_URI.buildUpon(), WAYPOINT_ID_0).build(); + private static final Uri WAYPOINT_ID_O_URI = ContentUris.appendId(MarkerColumns.CONTENT_URI.buildUpon(), WAYPOINT_ID_0).build(); protected final Context context = ApplicationProvider.getApplicationContext(); @@ -114,7 +114,7 @@ public abstract class AbstractTestFileTrackImporter { protected void expectTrackUpdate(ArgumentCaptor trackCaptor, boolean lastTrack, Track.Id trackId) { contentProviderUtils.updateTrack(trackCaptor.capture()); - when(contentProviderUtils.insertWaypoint(any())).thenReturn(WAYPOINT_ID_O_URI); + when(contentProviderUtils.insertMarker(any())).thenReturn(WAYPOINT_ID_O_URI); if (lastTrack) { // Return null to not add waypoints when(contentProviderUtils.getTrack(trackId)).thenReturn(null); diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java index 6fc9bfd39..ce2ae0104 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java @@ -21,10 +21,10 @@ import java.util.Arrays; import java.util.List; import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.io.file.TrackFileFormat; import de.dennisguse.opentracks.io.file.exporter.TrackExporter; @@ -53,7 +53,7 @@ public class ExportImportTest { private static final String TRACK_CATEGORY = "the category"; private static final String TRACK_DESCRIPTION = "the description"; - private final List waypoints = new ArrayList<>(); + private final List waypoints = new ArrayList<>(); private final List trackPoints = new ArrayList<>(); private Track.Id importTrackId; @@ -72,19 +72,19 @@ public class ExportImportTest { trackPoints.addAll(Arrays.asList(track.second)); for (int i = 0; i < 3; i++) { - Waypoint waypoint = new Waypoint(track.second[i].getLocation()); + Marker waypoint = new Marker(track.second[i].getLocation()); waypoint.setName("the waypoint " + i); waypoint.setDescription("the waypoint description " + i); waypoint.setCategory("the waypoint category" + i); waypoint.setIcon("the waypoing icon" + i); waypoint.setPhotoUrl("the photo url" + i); waypoint.setTrackId(trackId); - contentProviderUtils.insertWaypoint(waypoint); + contentProviderUtils.insertMarker(waypoint); waypoints.add(waypoint); } - assertEquals(waypoints.size(), contentProviderUtils.getWaypointCount(trackId)); + assertEquals(waypoints.size(), contentProviderUtils.getMarkerCount(trackId)); } @After @@ -286,12 +286,12 @@ public class ExportImportTest { } private void assertWaypoints() { - assertEquals(waypoints.size(), contentProviderUtils.getWaypointCount(importTrackId)); + assertEquals(waypoints.size(), contentProviderUtils.getMarkerCount(importTrackId)); - List importedWaypoints = contentProviderUtils.getWaypoints(importTrackId); + List importedWaypoints = contentProviderUtils.getMarkers(importTrackId); for (int i = 0; i < waypoints.size(); i++) { - Waypoint waypoint = waypoints.get(i); - Waypoint importedWaypoint = importedWaypoints.get(i); + Marker waypoint = waypoints.get(i); + Marker importedWaypoint = importedWaypoints.get(i); assertEquals(waypoint.getCategory(), importedWaypoint.getCategory()); assertEquals(waypoint.getDescription(), importedWaypoint.getDescription()); // assertEquals(waypoint.getIcon(), importedWaypoint.getIcon()); // TODO for KML diff --git a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTest.java b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTest.java index 792fe5a89..70a55bc6b 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTest.java @@ -44,10 +44,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; import de.dennisguse.opentracks.content.data.TrackPointsColumns; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.content.provider.CustomContentProvider; import de.dennisguse.opentracks.stats.TrackStatistics; @@ -296,7 +296,7 @@ public class TrackRecordingServiceTest { assertFalse(service.isRecording()); // when - Waypoint.Id waypointId = service.insertWaypoint(null, null, null, null); + Marker.Id waypointId = service.insertWaypoint(null, null, null, null); // then assertNull(waypointId); @@ -313,11 +313,11 @@ public class TrackRecordingServiceTest { Track.Id trackId = service.getRecordingTrackId(); // when - Waypoint.Id waypointId = service.insertWaypoint(null, null, null, null); + Marker.Id waypointId = service.insertWaypoint(null, null, null, null); // then assertNotEquals(-1L, waypointId); - Waypoint wpt = contentProviderUtils.getWaypoint(waypointId); + Marker wpt = contentProviderUtils.getMarker(waypointId); assertEquals(context.getString(R.string.marker_waypoint_icon_url), wpt.getIcon()); assertEquals(context.getString(R.string.marker_name_format, 1), wpt.getName()); assertEquals(trackId, wpt.getTrackId()); diff --git a/src/main/java/de/dennisguse/opentracks/MarkerDetailActivity.java b/src/main/java/de/dennisguse/opentracks/MarkerDetailActivity.java index 31fd197bc..ef82aba39 100644 --- a/src/main/java/de/dennisguse/opentracks/MarkerDetailActivity.java +++ b/src/main/java/de/dennisguse/opentracks/MarkerDetailActivity.java @@ -30,7 +30,7 @@ import androidx.viewpager.widget.ViewPager; import java.util.ArrayList; import java.util.List; -import de.dennisguse.opentracks.content.data.Waypoint; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller; import de.dennisguse.opentracks.fragments.MarkerDetailFragment; @@ -48,13 +48,13 @@ public class MarkerDetailActivity extends AbstractActivity implements DeleteMark private static final String TAG = MarkerDetailActivity.class.getSimpleName(); - private List waypointIds; + private List waypointIds; @Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); - Waypoint.Id waypointId = getIntent().getParcelableExtra(EXTRA_MARKER_ID); + Marker.Id waypointId = getIntent().getParcelableExtra(EXTRA_MARKER_ID); if (waypointId == null) { Log.d(TAG, "invalid marker id"); finish(); @@ -62,16 +62,16 @@ public class MarkerDetailActivity extends AbstractActivity implements DeleteMark } ContentProviderUtils contentProviderUtils = new ContentProviderUtils(this); - Waypoint waypoint = contentProviderUtils.getWaypoint(waypointId); + Marker waypoint = contentProviderUtils.getMarker(waypointId); waypointIds = new ArrayList<>(); int markerIndex = -1; //TODO Load only waypointIds, not the whole waypoint - try (Cursor cursor = contentProviderUtils.getWaypointCursor(waypoint.getTrackId(), null, -1)) { + try (Cursor cursor = contentProviderUtils.getMarkerCursor(waypoint.getTrackId(), null, -1)) { if (cursor != null && cursor.moveToFirst()) { for (int i = 0; i < cursor.getCount(); i++) { - Waypoint currentMarker = contentProviderUtils.createWaypoint(cursor); + Marker currentMarker = contentProviderUtils.createMarker(cursor); waypointIds.add(currentMarker.getId()); if (waypointId.equals(currentMarker.getId())) { markerIndex = waypointIds.size() - 1; diff --git a/src/main/java/de/dennisguse/opentracks/MarkerEditActivity.java b/src/main/java/de/dennisguse/opentracks/MarkerEditActivity.java index 82f966bd9..af8b82b28 100644 --- a/src/main/java/de/dennisguse/opentracks/MarkerEditActivity.java +++ b/src/main/java/de/dennisguse/opentracks/MarkerEditActivity.java @@ -42,8 +42,8 @@ import java.io.File; import java.io.FileDescriptor; import java.io.IOException; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.services.TrackRecordingServiceConnection; import de.dennisguse.opentracks.util.FileUtils; @@ -67,7 +67,7 @@ public class MarkerEditActivity extends AbstractActivity { private static final String TAG = MarkerEditActivity.class.getSimpleName(); private Track.Id trackId; private TrackRecordingServiceConnection trackRecordingServiceConnection = new TrackRecordingServiceConnection(); - private Waypoint waypoint; + private Marker waypoint; private MenuItem insertPhotoMenuItem; private MenuItem insertGalleryImgMenuItem; @@ -87,7 +87,7 @@ public class MarkerEditActivity extends AbstractActivity { super.onCreate(savedInstanceState); trackId = getIntent().getParcelableExtra(EXTRA_TRACK_ID); - Waypoint.Id waypointId = getIntent().getParcelableExtra(EXTRA_MARKER_ID); + Marker.Id waypointId = getIntent().getParcelableExtra(EXTRA_MARKER_ID); hasCamera = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); @@ -127,7 +127,7 @@ public class MarkerEditActivity extends AbstractActivity { }); if (isNewMarker) { - int nextWaypointNumber = trackId == null ? -1 : new ContentProviderUtils(this).getNextWaypointNumber(trackId); + int nextWaypointNumber = trackId == null ? -1 : new ContentProviderUtils(this).getNextMarkerNumber(trackId); if (nextWaypointNumber == -1) { nextWaypointNumber = 0; } @@ -136,7 +136,7 @@ public class MarkerEditActivity extends AbstractActivity { waypointMarkerType.setText(""); waypointDescription.setText(""); } else { - waypoint = new ContentProviderUtils(this).getWaypoint(waypointId); + waypoint = new ContentProviderUtils(this).getMarker(waypointId); if (waypoint == null) { Log.d(TAG, "waypoint is null"); finish(); @@ -307,6 +307,6 @@ public class MarkerEditActivity extends AbstractActivity { waypoint.setDescription(waypointDescription.getText().toString()); waypoint.setPhotoUrl(photoUri != null ? photoUri.toString() : null); - new ContentProviderUtils(this).updateWaypoint(this, waypoint); + new ContentProviderUtils(this).updateMarker(this, waypoint); } } diff --git a/src/main/java/de/dennisguse/opentracks/MarkerListActivity.java b/src/main/java/de/dennisguse/opentracks/MarkerListActivity.java index 6b49e8ddc..d09011ae9 100644 --- a/src/main/java/de/dennisguse/opentracks/MarkerListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/MarkerListActivity.java @@ -34,9 +34,9 @@ import androidx.loader.app.LoaderManager; import androidx.loader.app.LoaderManager.LoaderCallbacks; import androidx.loader.content.Loader; +import de.dennisguse.opentracks.content.data.Marker; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.Track; -import de.dennisguse.opentracks.content.data.Waypoint; -import de.dennisguse.opentracks.content.data.WaypointsColumns; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment; import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller; @@ -124,19 +124,19 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker listView.setEmptyView(findViewById(R.id.marker_list_empty)); listView.setOnItemClickListener((parent, view, position, id) -> { Intent intent = IntentUtils.newIntent(MarkerListActivity.this, MarkerDetailActivity.class) - .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, new Waypoint.Id(id)); + .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, new Marker.Id(id)); startActivity(intent); }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { - int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME); - int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME); - int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY); - int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION); - int photoUrlIndex = cursor.getColumnIndex(WaypointsColumns.PHOTOURL); - int latitudeIndex = cursor.getColumnIndex(WaypointsColumns.LATITUDE); - int longitudeIndex = cursor.getColumnIndex(WaypointsColumns.LONGITUDE); + int nameIndex = cursor.getColumnIndex(MarkerColumns.NAME); + int timeIndex = cursor.getColumnIndexOrThrow(MarkerColumns.TIME); + int categoryIndex = cursor.getColumnIndex(MarkerColumns.CATEGORY); + int descriptionIndex = cursor.getColumnIndex(MarkerColumns.DESCRIPTION); + int photoUrlIndex = cursor.getColumnIndex(MarkerColumns.PHOTOURL); + int latitudeIndex = cursor.getColumnIndex(MarkerColumns.LATITUDE); + int longitudeIndex = cursor.getColumnIndex(MarkerColumns.LONGITUDE); int iconId = MarkerUtils.ICON_ID; String name = cursor.getString(nameIndex); @@ -158,7 +158,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker @NonNull @Override public Loader onCreateLoader(int arg0, Bundle arg1) { - return ContentProviderUtils.getWaypointsLoader(MarkerListActivity.this, track != null ? track.getId() : null); + return ContentProviderUtils.getMarkersLoader(MarkerListActivity.this, track != null ? track.getId() : null); } @Override @@ -234,16 +234,16 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker * @return true if handled. */ private boolean handleContextItem(int itemId, long... longWaypointIds) { - Waypoint.Id[] waypointIds = new Waypoint.Id[longWaypointIds.length]; + Marker.Id[] waypointIds = new Marker.Id[longWaypointIds.length]; for (int i = 0; i < longWaypointIds.length; i++) { - waypointIds[i] = new Waypoint.Id(longWaypointIds[i]); + waypointIds[i] = new Marker.Id(longWaypointIds[i]); } Intent intent; switch (itemId) { case R.id.list_context_menu_show_on_map: if (waypointIds.length == 1) { - IntentUtils.showCoordinateOnMap(this, contentProviderUtils.getWaypoint(waypointIds[0])); + IntentUtils.showCoordinateOnMap(this, contentProviderUtils.getMarker(waypointIds[0])); } return true; case R.id.list_context_menu_edit: diff --git a/src/main/java/de/dennisguse/opentracks/SearchListActivity.java b/src/main/java/de/dennisguse/opentracks/SearchListActivity.java index 1602ac25f..215ac107d 100644 --- a/src/main/java/de/dennisguse/opentracks/SearchListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/SearchListActivity.java @@ -41,8 +41,8 @@ import java.util.SortedSet; import de.dennisguse.opentracks.content.SearchEngine; import de.dennisguse.opentracks.content.SearchEngine.ScoredResult; import de.dennisguse.opentracks.content.SearchEngine.SearchQuery; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment; import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment; @@ -271,7 +271,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa } Map item = arrayAdapter.getItem(positions[0]); Track.Id trackId = (Track.Id) item.get(TRACK_ID_FIELD); - Waypoint.Id waypointId = (Waypoint.Id) item.get(MARKER_ID_FIELD); + Marker.Id waypointId = (Marker.Id) item.get(MARKER_ID_FIELD); Intent intent; switch (itemId) { case R.id.list_context_menu_show_on_map: @@ -367,7 +367,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa * @param waypoint the marker * @return the result map */ - private Map prepareMarkerForDisplay(Waypoint waypoint) { + private Map prepareMarkerForDisplay(Marker waypoint) { Map resultMap = new HashMap<>(); //TODO: It may be more appropriate to obtain the track name as a join in the retrieval phase of the searchable. @@ -422,7 +422,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa resultMap.put(NAME_FIELD, track.getName()); resultMap.put(TOTAL_TIME_FIELD, StringUtils.formatElapsedTime(trackStatistics.getTotalTime())); resultMap.put(TOTAL_DISTANCE_FIELD, StringUtils.formatDistance(this, trackStatistics.getTotalDistance(), metricUnits)); - resultMap.put(MARKER_COUNT_FIELD, contentProviderUtils.getWaypointCount(track.getId())); + resultMap.put(MARKER_COUNT_FIELD, contentProviderUtils.getMarkerCount(track.getId())); resultMap.put(START_TIME_FIELD, trackStatistics.getStartTime_ms()); resultMap.put(CATEGORY_FIELD, category); resultMap.put(DESCRIPTION_FIELD, track.getDescription()); diff --git a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java index 75f66e464..fe6e6d39f 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java @@ -269,7 +269,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe String name = cursor.getString(nameIndex); String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex)); String totalDistance = StringUtils.formatDistance(TrackListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits); - int markerCount = contentProviderUtils.getWaypointCount(trackId); + int markerCount = contentProviderUtils.getMarkerCount(trackId); long startTime = cursor.getLong(startTimeIndex); String category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex); String description = cursor.getString(descriptionIndex); diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordedActivity.java index f2b412241..eafd09ee2 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordedActivity.java @@ -31,8 +31,8 @@ import androidx.viewpager.widget.ViewPager; import com.google.android.material.tabs.TabLayout; import de.dennisguse.opentracks.content.TrackDataHub; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.fragments.ChartFragment; import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment; @@ -206,10 +206,10 @@ public class TrackRecordedActivity extends AbstractListActivity implements Choos private void handleIntent(Intent intent) { Track.Id trackId = intent.getParcelableExtra(EXTRA_TRACK_ID); - Waypoint.Id waypointId = intent.getParcelableExtra(EXTRA_MARKER_ID); + Marker.Id waypointId = intent.getParcelableExtra(EXTRA_MARKER_ID); if (waypointId != null) { // Use the trackId from the marker - Waypoint waypoint = contentProviderUtils.getWaypoint(waypointId); + Marker waypoint = contentProviderUtils.getMarker(waypointId); if (waypoint == null) { finish(); return; diff --git a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java index 6602dd166..5ea8ea944 100644 --- a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java +++ b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java @@ -42,7 +42,7 @@ import java.util.List; import de.dennisguse.opentracks.MarkerDetailActivity; import de.dennisguse.opentracks.R; -import de.dennisguse.opentracks.content.data.Waypoint; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.stats.ExtremityMonitor; import de.dennisguse.opentracks.util.IntentUtils; import de.dennisguse.opentracks.util.MarkerUtils; @@ -87,7 +87,7 @@ public class ChartView extends View { private final ChartValueSeries paceSeries; private final List chartPoints = new ArrayList<>(); - private final List waypoints = new ArrayList<>(); + private final List waypoints = new ArrayList<>(); private final ExtremityMonitor xExtremityMonitor = new ExtremityMonitor(); private final Paint axisPaint; private final Paint xAxisMarkerPaint; @@ -150,9 +150,9 @@ public class ChartView extends View { // Check if the y event is within markerHeight of the marker center if (Math.abs(event.getY() - topBorder - spacer - markerHeight / 2f) < markerHeight) { int minDistance = Integer.MAX_VALUE; - Waypoint nearestWaypoint = null; + Marker nearestWaypoint = null; synchronized (waypoints) { - for (Waypoint waypoint : waypoints) { + for (Marker waypoint : waypoints) { int distance = Math.abs(getX(getWaypointXValue(waypoint)) - (int) event.getX() - getScrollX()); if (distance < minDistance) { minDistance = distance; @@ -434,7 +434,7 @@ public class ChartView extends View { scrollTo(0, 0); } - public void addWaypoint(Waypoint waypoint) { + public void addWaypoint(Marker waypoint) { synchronized (waypoints) { waypoints.add(waypoint); } @@ -594,7 +594,7 @@ public class ChartView extends View { */ private void drawWaypoints(Canvas canvas) { synchronized (waypoints) { - for (Waypoint waypoint : waypoints) { + for (Marker waypoint : waypoints) { double xValue = getWaypointXValue(waypoint); if (xValue > maxX) { continue; @@ -980,7 +980,7 @@ public class ChartView extends View { * * @param waypoint the waypoint */ - private double getWaypointXValue(Waypoint waypoint) { + private double getWaypointXValue(Marker waypoint) { if (chartByDistance) { double lenghtInKm = waypoint.getLength() * UnitConversions.M_TO_KM; return metricUnits ? lenghtInKm : lenghtInKm * UnitConversions.KM_TO_MI; diff --git a/src/main/java/de/dennisguse/opentracks/content/SearchEngine.java b/src/main/java/de/dennisguse/opentracks/content/SearchEngine.java index 79c5bc8c5..a8f9230ca 100644 --- a/src/main/java/de/dennisguse/opentracks/content/SearchEngine.java +++ b/src/main/java/de/dennisguse/opentracks/content/SearchEngine.java @@ -28,10 +28,10 @@ import java.util.Locale; import java.util.SortedSet; import java.util.TreeSet; +import de.dennisguse.opentracks.content.data.Marker; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TracksColumns; -import de.dennisguse.opentracks.content.data.Waypoint; -import de.dennisguse.opentracks.content.data.WaypointsColumns; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.util.LocationUtils; @@ -56,9 +56,9 @@ public class SearchEngine { * WHERE query to get waypoints by name. */ private static final String WAYPOINT_SELECTION_QUERY = - WaypointsColumns.NAME + " LIKE ? OR " + - WaypointsColumns.DESCRIPTION + " LIKE ? OR " + - WaypointsColumns.CATEGORY + " LIKE ?"; + MarkerColumns.NAME + " LIKE ? OR " + + MarkerColumns.DESCRIPTION + " LIKE ? OR " + + MarkerColumns.CATEGORY + " LIKE ?"; /** * Order of track results. @@ -68,7 +68,7 @@ public class SearchEngine { /** * Order of waypoint results. */ - private static final String WAYPOINT_SELECTION_ORDER = WaypointsColumns._ID + " DESC"; + private static final String WAYPOINT_SELECTION_ORDER = MarkerColumns._ID + " DESC"; /** * How much we promote a match in the track category. @@ -190,8 +190,8 @@ public class SearchEngine { * * @param query the query to retrieve for */ - private List retrieveWaypoints(SearchQuery query) { - ArrayList waypoints = new ArrayList<>(); + private List retrieveWaypoints(SearchQuery query) { + ArrayList waypoints = new ArrayList<>(); String queryLikeSelection2 = "%" + query.textQuery + "%"; String[] waypointSelectionArgs = new String[]{ @@ -200,11 +200,11 @@ public class SearchEngine { queryLikeSelection2 }; - try (Cursor cursor = providerUtils.getWaypointCursor(WAYPOINT_SELECTION_QUERY, waypointSelectionArgs, WAYPOINT_SELECTION_ORDER, MAX_SCORED_WAYPOINTS)) { + try (Cursor cursor = providerUtils.getMarkerCursor(WAYPOINT_SELECTION_QUERY, waypointSelectionArgs, WAYPOINT_SELECTION_ORDER, MAX_SCORED_WAYPOINTS)) { if (cursor != null) { waypoints.ensureCapacity(cursor.getCount()); while (cursor.moveToNext()) { - Waypoint waypoint = providerUtils.createWaypoint(cursor); + Marker waypoint = providerUtils.createMarker(cursor); if (LocationUtils.isValidLocation(waypoint.getLocation())) { waypoints.add(waypoint); } @@ -264,8 +264,8 @@ public class SearchEngine { * @param query the query to score for * @param output the collection to fill with scored results */ - private void scoreWaypointResults(Collection waypoints, SearchQuery query, Collection output) { - for (Waypoint waypoint : waypoints) { + private void scoreWaypointResults(Collection waypoints, SearchQuery query, Collection output) { + for (Marker waypoint : waypoints) { // Calculate the score. double score = scoreWaypointResult(query, waypoint); @@ -281,7 +281,7 @@ public class SearchEngine { * @param waypoint the results to score * @return the score for the waypoint */ - private double scoreWaypointResult(SearchQuery query, Waypoint waypoint) { + private double scoreWaypointResult(SearchQuery query, Marker waypoint) { double score = 1.0; Location location = waypoint.getLocation(); @@ -398,7 +398,7 @@ public class SearchEngine { */ public static class ScoredResult { public final Track track; - public final Waypoint waypoint; + public final Marker waypoint; final double score; ScoredResult(Track track, double score) { @@ -407,7 +407,7 @@ public class SearchEngine { this.score = score; } - ScoredResult(Waypoint waypoint, double score) { + ScoredResult(Marker waypoint, double score) { this.track = null; this.waypoint = waypoint; this.score = score; diff --git a/src/main/java/de/dennisguse/opentracks/content/TrackDataHub.java b/src/main/java/de/dennisguse/opentracks/content/TrackDataHub.java index 8d30c808c..5aea63904 100644 --- a/src/main/java/de/dennisguse/opentracks/content/TrackDataHub.java +++ b/src/main/java/de/dennisguse/opentracks/content/TrackDataHub.java @@ -32,12 +32,12 @@ import java.util.Collections; import java.util.Set; import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.content.data.Marker; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; import de.dennisguse.opentracks.content.data.TrackPointsColumns; import de.dennisguse.opentracks.content.data.TracksColumns; -import de.dennisguse.opentracks.content.data.Waypoint; -import de.dennisguse.opentracks.content.data.WaypointsColumns; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.content.provider.TrackPointIterator; import de.dennisguse.opentracks.util.LocationUtils; @@ -132,7 +132,7 @@ public class TrackDataHub implements SharedPreferences.OnSharedPreferenceChangeL notifyWaypointsTableUpdate(trackDataManager.getListenerWaypoints()); } }; - contentResolver.registerContentObserver(WaypointsColumns.CONTENT_URI, false, waypointsTableObserver); + contentResolver.registerContentObserver(MarkerColumns.CONTENT_URI, false, waypointsTableObserver); trackPointsTableObserver = new ContentObserver(handler) { @Override @@ -312,10 +312,10 @@ public class TrackDataHub implements SharedPreferences.OnSharedPreferenceChangeL trackDataListener.clearWaypoints(); } - try (Cursor cursor = contentProviderUtils.getWaypointCursor(selectedTrackId, null, MAX_DISPLAYED_WAYPOINTS)) { + try (Cursor cursor = contentProviderUtils.getMarkerCursor(selectedTrackId, null, MAX_DISPLAYED_WAYPOINTS)) { if (cursor != null && cursor.moveToFirst()) { do { - Waypoint waypoint = contentProviderUtils.createWaypoint(cursor); + Marker waypoint = contentProviderUtils.createMarker(cursor); if (!LocationUtils.isValidLocation(waypoint.getLocation())) { continue; } diff --git a/src/main/java/de/dennisguse/opentracks/content/TrackDataListener.java b/src/main/java/de/dennisguse/opentracks/content/TrackDataListener.java index 353be5a07..4c7ef9272 100644 --- a/src/main/java/de/dennisguse/opentracks/content/TrackDataListener.java +++ b/src/main/java/de/dennisguse/opentracks/content/TrackDataListener.java @@ -16,9 +16,9 @@ package de.dennisguse.opentracks.content; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; /** * Listener for track data changes. @@ -69,11 +69,11 @@ public interface TrackDataListener { * * @param waypoint the waypoint */ - void onNewWaypoint(Waypoint waypoint); + void onNewWaypoint(Marker waypoint); /** * Called when finish sending new waypoints. - * This gets called after every batch of calls to {@link #clearWaypoints()} and {@link #onNewWaypoint(Waypoint)}. + * This gets called after every batch of calls to {@link #clearWaypoints()} and {@link #onNewWaypoint(Marker)}. */ void onNewWaypointsDone(); } diff --git a/src/main/java/de/dennisguse/opentracks/content/data/Waypoint.java b/src/main/java/de/dennisguse/opentracks/content/data/Marker.java similarity index 94% rename from src/main/java/de/dennisguse/opentracks/content/data/Waypoint.java rename to src/main/java/de/dennisguse/opentracks/content/data/Marker.java index a0ac55e26..fbec7213e 100644 --- a/src/main/java/de/dennisguse/opentracks/content/data/Waypoint.java +++ b/src/main/java/de/dennisguse/opentracks/content/data/Marker.java @@ -35,7 +35,7 @@ import de.dennisguse.opentracks.util.PreferencesUtils; * @author Leif Hendrik Wilden * @author Rodrigo Damazio */ -public final class Waypoint { +public final class Marker { private Id id; private String name = ""; @@ -50,15 +50,15 @@ public final class Waypoint { private String photoUrl = ""; @VisibleForTesting - public Waypoint(@NonNull TrackPoint trackPoint) { + public Marker(@NonNull TrackPoint trackPoint) { this.location = trackPoint.getLocation(); } - public Waypoint(@NonNull Location location) { + public Marker(@NonNull Location location) { this.location = location; } - public Waypoint(String name, String description, String category, String icon, @NonNull Track.Id trackId, double length, long duration, @NonNull Location location, String photoUrl) { + public Marker(String name, String description, String category, String icon, @NonNull Track.Id trackId, double length, long duration, @NonNull Location location, String photoUrl) { this.name = name; this.description = description; this.category = category; diff --git a/src/main/java/de/dennisguse/opentracks/content/data/WaypointsColumns.java b/src/main/java/de/dennisguse/opentracks/content/data/MarkerColumns.java similarity index 98% rename from src/main/java/de/dennisguse/opentracks/content/data/WaypointsColumns.java rename to src/main/java/de/dennisguse/opentracks/content/data/MarkerColumns.java index d8cbdb9ee..99cdd04c6 100644 --- a/src/main/java/de/dennisguse/opentracks/content/data/WaypointsColumns.java +++ b/src/main/java/de/dennisguse/opentracks/content/data/MarkerColumns.java @@ -26,7 +26,7 @@ import de.dennisguse.opentracks.content.provider.ContentProviderUtils; * * @author Leif Hendrik Wilden */ -public interface WaypointsColumns extends BaseColumns { +public interface MarkerColumns extends BaseColumns { String TABLE_NAME = "waypoints"; Uri CONTENT_URI = Uri.parse(ContentProviderUtils.CONTENT_BASE_URI + "/" + TABLE_NAME); diff --git a/src/main/java/de/dennisguse/opentracks/content/provider/ContentProviderUtils.java b/src/main/java/de/dennisguse/opentracks/content/provider/ContentProviderUtils.java index b58f24973..d0dc07e2f 100644 --- a/src/main/java/de/dennisguse/opentracks/content/provider/ContentProviderUtils.java +++ b/src/main/java/de/dennisguse/opentracks/content/provider/ContentProviderUtils.java @@ -40,12 +40,12 @@ import java.util.UUID; import de.dennisguse.opentracks.BuildConfig; import de.dennisguse.opentracks.android.ContentResolverWrapper; import de.dennisguse.opentracks.android.IContentResolver; +import de.dennisguse.opentracks.content.data.Marker; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; import de.dennisguse.opentracks.content.data.TrackPointsColumns; import de.dennisguse.opentracks.content.data.TracksColumns; -import de.dennisguse.opentracks.content.data.Waypoint; -import de.dennisguse.opentracks.content.data.WaypointsColumns; import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.util.FileUtils; import de.dennisguse.opentracks.util.TrackUtils; @@ -69,8 +69,8 @@ public class ContentProviderUtils { // The base URI for the app's content provider. public static final String CONTENT_BASE_URI = "content://" + AUTHORITY_PACKAGE; - // Maximum number of waypoints that will be loaded at one time. - public static final int MAX_LOADED_WAYPOINTS_POINTS = 10000; + // Maximum number of markers that will be loaded at one time. + public static final int MAX_LOADED_MARKERS = 10000; private static final String ID_SEPARATOR = ","; private final IContentResolver contentResolver; @@ -89,13 +89,13 @@ public class ContentProviderUtils { } /** - * Clears a track: removes waypoints and trackPoints. + * Clears a track: removes markers and trackPoints. * Only keeps the track id. * * @param trackId the track id */ public void clearTrack(Track.Id trackId) { - deleteTrackPointsAndWaypoints(trackId); + deleteTrackPointsAndMarkers(trackId); Track track = new Track(); track.setId(trackId); updateTrack(track); @@ -176,7 +176,7 @@ public class ContentProviderUtils { @VisibleForTesting public void deleteAllTracks(Context context) { contentResolver.delete(TrackPointsColumns.CONTENT_URI_BY_ID, null, null); - contentResolver.delete(WaypointsColumns.CONTENT_URI, null, null); + contentResolver.delete(MarkerColumns.CONTENT_URI, null, null); // Delete tracks last since it triggers a database vaccum call contentResolver.delete(TracksColumns.CONTENT_URI, null, null); @@ -193,7 +193,7 @@ public class ContentProviderUtils { if (trackId == null) { return; } - deleteTrackPointsAndWaypoints(trackId); + deleteTrackPointsAndMarkers(trackId); // Delete track folder resources. FileUtils.deleteDirectoryRecurse(FileUtils.getPhotoDir(context, trackId)); @@ -202,16 +202,11 @@ public class ContentProviderUtils { contentResolver.delete(TracksColumns.CONTENT_URI, TracksColumns._ID + "=?", new String[]{Long.toString(trackId.getId())}); } - /** - * Deletes trackPoints and waypoints of a track. - * - * @param trackId the track id - */ - private void deleteTrackPointsAndWaypoints(@NonNull Track.Id trackId) { + private void deleteTrackPointsAndMarkers(@NonNull Track.Id trackId) { String[] selectionArgs = new String[]{Long.toString(trackId.getId())}; contentResolver.delete(TrackPointsColumns.CONTENT_URI_BY_ID, TrackPointsColumns.TRACKID + "=?", selectionArgs); - contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns.TRACKID + "=?", selectionArgs); + contentResolver.delete(MarkerColumns.CONTENT_URI, MarkerColumns.TRACKID + "=?", selectionArgs); } @VisibleForTesting @@ -338,28 +333,22 @@ public class ContentProviderUtils { return values; } - - /** - * Creates a waypoint from a cursor. - * - * @param cursor the cursor pointing to the waypoint - */ - public Waypoint createWaypoint(Cursor cursor) { - int idIndex = cursor.getColumnIndexOrThrow(WaypointsColumns._ID); - int nameIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.NAME); - int descriptionIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.DESCRIPTION); - int categoryIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.CATEGORY); - int iconIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.ICON); - int trackIdIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TRACKID); - int lengthIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.LENGTH); - int durationIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.DURATION); - int longitudeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.LONGITUDE); - int latitudeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.LATITUDE); - int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME); - int altitudeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.ALTITUDE); - int accuracyIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.ACCURACY); - int bearingIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.BEARING); - int photoUrlIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.PHOTOURL); + public Marker createMarker(Cursor cursor) { + int idIndex = cursor.getColumnIndexOrThrow(MarkerColumns._ID); + int nameIndex = cursor.getColumnIndexOrThrow(MarkerColumns.NAME); + int descriptionIndex = cursor.getColumnIndexOrThrow(MarkerColumns.DESCRIPTION); + int categoryIndex = cursor.getColumnIndexOrThrow(MarkerColumns.CATEGORY); + int iconIndex = cursor.getColumnIndexOrThrow(MarkerColumns.ICON); + int trackIdIndex = cursor.getColumnIndexOrThrow(MarkerColumns.TRACKID); + int lengthIndex = cursor.getColumnIndexOrThrow(MarkerColumns.LENGTH); + int durationIndex = cursor.getColumnIndexOrThrow(MarkerColumns.DURATION); + int longitudeIndex = cursor.getColumnIndexOrThrow(MarkerColumns.LONGITUDE); + int latitudeIndex = cursor.getColumnIndexOrThrow(MarkerColumns.LATITUDE); + int timeIndex = cursor.getColumnIndexOrThrow(MarkerColumns.TIME); + int altitudeIndex = cursor.getColumnIndexOrThrow(MarkerColumns.ALTITUDE); + int accuracyIndex = cursor.getColumnIndexOrThrow(MarkerColumns.ACCURACY); + int bearingIndex = cursor.getColumnIndexOrThrow(MarkerColumns.BEARING); + int photoUrlIndex = cursor.getColumnIndexOrThrow(MarkerColumns.PHOTOURL); Location location = new Location(""); if (!cursor.isNull(longitudeIndex) && !cursor.isNull(latitudeIndex)) { @@ -379,59 +368,56 @@ public class ContentProviderUtils { location.setBearing(cursor.getFloat(bearingIndex)); } - Waypoint waypoint = new Waypoint(location); + Marker marker = new Marker(location); if (!cursor.isNull(idIndex)) { - waypoint.setId(new Waypoint.Id(cursor.getLong(idIndex))); + marker.setId(new Marker.Id(cursor.getLong(idIndex))); } if (!cursor.isNull(nameIndex)) { - waypoint.setName(cursor.getString(nameIndex)); + marker.setName(cursor.getString(nameIndex)); } if (!cursor.isNull(descriptionIndex)) { - waypoint.setDescription(cursor.getString(descriptionIndex)); + marker.setDescription(cursor.getString(descriptionIndex)); } if (!cursor.isNull(categoryIndex)) { - waypoint.setCategory(cursor.getString(categoryIndex)); + marker.setCategory(cursor.getString(categoryIndex)); } if (!cursor.isNull(iconIndex)) { - waypoint.setIcon(cursor.getString(iconIndex)); + marker.setIcon(cursor.getString(iconIndex)); } if (!cursor.isNull(trackIdIndex)) { - waypoint.setTrackId(new Track.Id(cursor.getLong(trackIdIndex))); + marker.setTrackId(new Track.Id(cursor.getLong(trackIdIndex))); } if (!cursor.isNull(lengthIndex)) { - waypoint.setLength(cursor.getFloat(lengthIndex)); + marker.setLength(cursor.getFloat(lengthIndex)); } if (!cursor.isNull(durationIndex)) { - waypoint.setDuration(cursor.getLong(durationIndex)); + marker.setDuration(cursor.getLong(durationIndex)); } if (!cursor.isNull(photoUrlIndex)) { - waypoint.setPhotoUrl(cursor.getString(photoUrlIndex)); + marker.setPhotoUrl(cursor.getString(photoUrlIndex)); } - return waypoint; + return marker; } - public void deleteWaypoint(Context context, Waypoint.Id waypointId) { - final Waypoint waypoint = getWaypoint(waypointId); - deleteWaypointPhoto(context, waypoint); - contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns._ID + "=?", new String[]{Long.toString(waypointId.getId())}); + public void deleteMarker(Context context, Marker.Id markerId) { + final Marker marker = getMarker(markerId); + deleteMarkerPhoto(context, marker); + contentResolver.delete(MarkerColumns.CONTENT_URI, MarkerColumns._ID + "=?", new String[]{Long.toString(markerId.getId())}); } /** - * Gets the next waypoint number. - * - * @param trackId the track id - * @return -1 if not able to get the next waypoint number. + * @return -1 if not able to get the next marker number. */ - public int getNextWaypointNumber(Track.Id trackId) { + public int getNextMarkerNumber(Track.Id trackId) { if (!trackId.isValid()) { return -1; } - String[] projection = {WaypointsColumns._ID}; - String selection = WaypointsColumns.TRACKID + "=?"; + String[] projection = {MarkerColumns._ID}; + String selection = MarkerColumns.TRACKID + "=?"; String[] selectionArgs = new String[]{Long.toString(trackId.getId())}; - try (Cursor cursor = getWaypointCursor(projection, selection, selectionArgs, WaypointsColumns._ID, -1)) { + try (Cursor cursor = getMarkerCursor(projection, selection, selectionArgs, MarkerColumns._ID, -1)) { if (cursor != null) { return cursor.getCount(); } @@ -439,99 +425,94 @@ public class ContentProviderUtils { return -1; } - public Waypoint getWaypoint(Waypoint.Id waypointId) { - if (!waypointId.isValid()) { + public Marker getMarker(Marker.Id markerId) { + if (!markerId.isValid()) { return null; } - try (Cursor cursor = getWaypointCursor(null, WaypointsColumns._ID + "=?", - new String[]{Long.toString(waypointId.getId())}, WaypointsColumns._ID, 1)) { + try (Cursor cursor = getMarkerCursor(null, MarkerColumns._ID + "=?", + new String[]{Long.toString(markerId.getId())}, MarkerColumns._ID, 1)) { if (cursor != null && cursor.moveToFirst()) { - return createWaypoint(cursor); + return createMarker(cursor); } } return null; } /** - * Gets a waypoint cursor. - * he caller owns the returned cursor and is responsible for closing it. + * The caller owns the returned cursor and is responsible for closing it. * * @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 maxCount the maximum number of markers to return. -1 for no limit */ - public Cursor getWaypointCursor(String selection, String[] selectionArgs, String sortOrder, int maxWaypoints) { - return getWaypointCursor(null, selection, selectionArgs, sortOrder, maxWaypoints); + public Cursor getMarkerCursor(String selection, String[] selectionArgs, String sortOrder, int maxCount) { + return getMarkerCursor(null, selection, selectionArgs, sortOrder, maxCount); } /** - * Gets a waypoint cursor for a track. * The caller owns the returned cursor and is responsible for closing it. * - * @param trackId the track id - * @param minWaypointId the minimum waypoint id. null to ignore - * @param maxWaypoints the maximum number of waypoints to return. -1 for no limit + * @param trackId the track id + * @param minMarkerId the minimum marker id. null to ignore + * @param maxCount the maximum number of markers to return. -1 for no limit */ - public Cursor getWaypointCursor(Track.Id trackId, @Nullable Waypoint.Id minWaypointId, int maxWaypoints) { + public Cursor getMarkerCursor(Track.Id trackId, @Nullable Marker.Id minMarkerId, int maxCount) { if (!trackId.isValid()) { return null; } String selection; String[] selectionArgs; - if (minWaypointId != null && minWaypointId.isValid()) { - selection = WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + ">=?"; - selectionArgs = new String[]{Long.toString(trackId.getId()), Long.toString(minWaypointId.getId())}; + if (minMarkerId != null && minMarkerId.isValid()) { + selection = MarkerColumns.TRACKID + "=? AND " + MarkerColumns._ID + ">=?"; + selectionArgs = new String[]{Long.toString(trackId.getId()), Long.toString(minMarkerId.getId())}; } else { - selection = WaypointsColumns.TRACKID + "=?"; + selection = MarkerColumns.TRACKID + "=?"; selectionArgs = new String[]{Long.toString(trackId.getId())}; } - return getWaypointCursor(null, selection, selectionArgs, WaypointsColumns._ID, maxWaypoints); + return getMarkerCursor(null, selection, selectionArgs, MarkerColumns._ID, maxCount); } + @Deprecated //TODO Move to test package @VisibleForTesting - public List getWaypoints(Track.Id trackId) { - ArrayList waypoints = new ArrayList<>(); - try (Cursor cursor = getWaypointCursor(trackId, null, -1)) { + public List getMarkers(Track.Id trackId) { + ArrayList markers = new ArrayList<>(); + try (Cursor cursor = getMarkerCursor(trackId, null, -1)) { if (cursor.moveToFirst()) { do { - waypoints.add(createWaypoint(cursor)); + markers.add(createMarker(cursor)); } while (cursor.moveToNext()); } } - return waypoints; + return markers; } - public static Loader getWaypointsLoader(Context context, @Nullable Track.Id trackId) { - final String[] PROJECTION = new String[]{WaypointsColumns._ID, - WaypointsColumns.NAME, WaypointsColumns.DESCRIPTION, WaypointsColumns.CATEGORY, - WaypointsColumns.TIME, WaypointsColumns.PHOTOURL, - WaypointsColumns.LATITUDE, WaypointsColumns.LONGITUDE}; + public static Loader getMarkersLoader(Context context, @Nullable Track.Id trackId) { + final String[] PROJECTION = new String[]{MarkerColumns._ID, + MarkerColumns.NAME, MarkerColumns.DESCRIPTION, MarkerColumns.CATEGORY, + MarkerColumns.TIME, MarkerColumns.PHOTOURL, + MarkerColumns.LATITUDE, MarkerColumns.LONGITUDE}; if (trackId != null) { - return new CursorLoader(context, WaypointsColumns.CONTENT_URI, PROJECTION, - WaypointsColumns.TRACKID + "=?", + return new CursorLoader(context, MarkerColumns.CONTENT_URI, PROJECTION, + MarkerColumns.TRACKID + "=?", new String[]{String.valueOf(trackId.getId())}, null); } else { - return new CursorLoader(context, WaypointsColumns.CONTENT_URI, PROJECTION, null, null, null); + return new CursorLoader(context, MarkerColumns.CONTENT_URI, PROJECTION, null, null, null); } } - /** - * Gets the number of waypoints for a track. - * - * @param trackId the track id - */ - public int getWaypointCount(Track.Id trackId) { + @Deprecated //TODO Expose information via Cursor + public int getMarkerCount(Track.Id trackId) { if (!trackId.isValid()) { return 0; } String[] projection = new String[]{"count(*) AS count"}; - String selection = WaypointsColumns.TRACKID + "=?"; + String selection = MarkerColumns.TRACKID + "=?"; String[] selectionArgs = new String[]{Long.toString(trackId.getId())}; - try (Cursor cursor = contentResolver.query(WaypointsColumns.CONTENT_URI, projection, selection, selectionArgs, WaypointsColumns._ID)) { + try (Cursor cursor = contentResolver.query(MarkerColumns.CONTENT_URI, projection, selection, selectionArgs, MarkerColumns._ID)) { if (cursor == null) { return 0; } @@ -541,26 +522,17 @@ public class ContentProviderUtils { } /** - * Inserts a waypoint. - * - * @param waypoint the waypoint - * @return the content provider URI of the inserted waypoint. + * @return the content provider URI of the inserted marker. */ - public Uri insertWaypoint(@NonNull Waypoint waypoint) { - waypoint.setId(null); - return contentResolver.insert(WaypointsColumns.CONTENT_URI, createContentValues(waypoint)); + public Uri insertMarker(@NonNull Marker marker) { + marker.setId(null); + return contentResolver.insert(MarkerColumns.CONTENT_URI, createContentValues(marker)); } - /** - * Delete waypoint's photo if any. - * - * @param context the context object. - * @param waypoint the waypoint object. - */ - private void deleteWaypointPhoto(Context context, Waypoint waypoint) { - if (waypoint != null && waypoint.hasPhoto()) { - Uri uri = waypoint.getPhotoURI(); - File file = FileUtils.getPhotoFileIfExists(context, waypoint.getTrackId(), uri); + private void deleteMarkerPhoto(Context context, Marker marker) { + if (marker != null && marker.hasPhoto()) { + Uri uri = marker.getPhotoURI(); + File file = FileUtils.getPhotoFileIfExists(context, marker.getTrackId(), uri); if (file.exists()) { File parent = file.getParentFile(); file.delete(); @@ -572,71 +544,67 @@ public class ContentProviderUtils { } /** - * Updates a waypoint. - * Returns true if successful. - * - * @param updatedWaypoint the waypoint with updated data. + * @param updateMarker the marker with updated data. + * @return true if successful. */ - public boolean updateWaypoint(Context context, Waypoint updatedWaypoint) { - Waypoint savedWaypoint = getWaypoint(updatedWaypoint.getId()); - if (!updatedWaypoint.hasPhoto()) { - deleteWaypointPhoto(context, savedWaypoint); + public boolean updateMarker(Context context, Marker updateMarker) { + Marker savedMarker = getMarker(updateMarker.getId()); + if (!updateMarker.hasPhoto()) { + deleteMarkerPhoto(context, savedMarker); } - int rows = contentResolver.update(WaypointsColumns.CONTENT_URI, createContentValues(updatedWaypoint), WaypointsColumns._ID + "=?", new String[]{Long.toString(updatedWaypoint.getId().getId())}); + int rows = contentResolver.update(MarkerColumns.CONTENT_URI, createContentValues(updateMarker), MarkerColumns._ID + "=?", new String[]{Long.toString(updateMarker.getId().getId())}); return rows == 1; } - ContentValues createContentValues(@NonNull Waypoint waypoint) { + ContentValues createContentValues(@NonNull Marker marker) { ContentValues values = new ContentValues(); - if (waypoint.getId() != null && waypoint.getId().isValid()) { - values.put(WaypointsColumns._ID, waypoint.getId().getId()); + if (marker.getId() != null && marker.getId().isValid()) { + values.put(MarkerColumns._ID, marker.getId().getId()); } - values.put(WaypointsColumns.NAME, waypoint.getName()); - values.put(WaypointsColumns.DESCRIPTION, waypoint.getDescription()); - values.put(WaypointsColumns.CATEGORY, waypoint.getCategory()); - values.put(WaypointsColumns.ICON, waypoint.getIcon()); - if (waypoint.getTrackId() != null) { - values.put(WaypointsColumns.TRACKID, waypoint.getTrackId().getId()); + values.put(MarkerColumns.NAME, marker.getName()); + values.put(MarkerColumns.DESCRIPTION, marker.getDescription()); + values.put(MarkerColumns.CATEGORY, marker.getCategory()); + values.put(MarkerColumns.ICON, marker.getIcon()); + if (marker.getTrackId() != null) { + values.put(MarkerColumns.TRACKID, marker.getTrackId().getId()); } - values.put(WaypointsColumns.LENGTH, waypoint.getLength()); - values.put(WaypointsColumns.DURATION, waypoint.getDuration()); + values.put(MarkerColumns.LENGTH, marker.getLength()); + values.put(MarkerColumns.DURATION, marker.getDuration()); - Location location = waypoint.getLocation(); - values.put(WaypointsColumns.LONGITUDE, (int) (location.getLongitude() * 1E6)); - values.put(WaypointsColumns.LATITUDE, (int) (location.getLatitude() * 1E6)); - values.put(WaypointsColumns.TIME, location.getTime()); + Location location = marker.getLocation(); + values.put(MarkerColumns.LONGITUDE, (int) (location.getLongitude() * 1E6)); + values.put(MarkerColumns.LATITUDE, (int) (location.getLatitude() * 1E6)); + values.put(MarkerColumns.TIME, location.getTime()); if (location.hasAltitude()) { - values.put(WaypointsColumns.ALTITUDE, location.getAltitude()); + values.put(MarkerColumns.ALTITUDE, location.getAltitude()); } if (location.hasAccuracy()) { - values.put(WaypointsColumns.ACCURACY, location.getAccuracy()); + values.put(MarkerColumns.ACCURACY, location.getAccuracy()); } if (location.hasBearing()) { - values.put(WaypointsColumns.BEARING, location.getBearing()); + values.put(MarkerColumns.BEARING, location.getBearing()); } - values.put(WaypointsColumns.PHOTOURL, waypoint.getPhotoUrl()); + values.put(MarkerColumns.PHOTOURL, marker.getPhotoUrl()); return values; } /** - * Gets a waypoint cursor. - * * @param projection the projection * @param selection the selection * @param selectionArgs the selection args * @param sortOrder the sort order - * @param maxWaypoints the maximum number of waypoints + * @param maxCount the maximum number of markers */ - private Cursor getWaypointCursor(String[] projection, String selection, String[] selectionArgs, String sortOrder, int maxWaypoints) { + private Cursor getMarkerCursor(String[] projection, String selection, String[] selectionArgs, String sortOrder, int maxCount) { if (sortOrder == null) { - sortOrder = WaypointsColumns._ID; + sortOrder = MarkerColumns._ID; } - if (maxWaypoints >= 0) { - sortOrder += " LIMIT " + maxWaypoints; + if (maxCount >= 0) { + sortOrder += " LIMIT " + maxCount; } - return contentResolver.query(WaypointsColumns.CONTENT_URI, projection, selection, selectionArgs, sortOrder); + return contentResolver.query(MarkerColumns.CONTENT_URI, projection, selection, selectionArgs, sortOrder); } /** diff --git a/src/main/java/de/dennisguse/opentracks/content/provider/CustomContentProvider.java b/src/main/java/de/dennisguse/opentracks/content/provider/CustomContentProvider.java index 44c40bc1f..e3eb42860 100644 --- a/src/main/java/de/dennisguse/opentracks/content/provider/CustomContentProvider.java +++ b/src/main/java/de/dennisguse/opentracks/content/provider/CustomContentProvider.java @@ -33,9 +33,9 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.TrackPointsColumns; import de.dennisguse.opentracks.content.data.TracksColumns; -import de.dennisguse.opentracks.content.data.WaypointsColumns; /** * A {@link ContentProvider} that handles access to track points, tracks, and waypoints tables. @@ -61,9 +61,9 @@ public class CustomContentProvider extends ContentProvider { uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, TracksColumns.CONTENT_URI.getPath(), UrlType.TRACKS.ordinal()); uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, TracksColumns.CONTENT_URI.getPath() + "/*", UrlType.TRACKS_BY_ID.ordinal()); - uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, WaypointsColumns.CONTENT_URI.getPath(), UrlType.WAYPOINTS.ordinal()); - uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, WaypointsColumns.CONTENT_URI.getPath() + "/#", UrlType.WAYPOINTS_BY_ID.ordinal()); - uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, WaypointsColumns.CONTENT_URI_BY_TRACKID.getPath() + "/*", UrlType.WAYPOINTS_BY_TRACKID.ordinal()); + uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, MarkerColumns.CONTENT_URI.getPath(), UrlType.WAYPOINTS.ordinal()); + uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, MarkerColumns.CONTENT_URI.getPath() + "/#", UrlType.WAYPOINTS_BY_ID.ordinal()); + uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, MarkerColumns.CONTENT_URI_BY_TRACKID.getPath() + "/*", UrlType.WAYPOINTS_BY_TRACKID.ordinal()); } @Override @@ -101,7 +101,7 @@ public class CustomContentProvider extends ContentProvider { shouldVacuum = true; break; case WAYPOINTS: - table = WaypointsColumns.TABLE_NAME; + table = MarkerColumns.TABLE_NAME; break; default: throw new IllegalArgumentException("Unknown URL " + url); @@ -139,10 +139,10 @@ public class CustomContentProvider extends ContentProvider { case TRACKS_BY_ID: return TracksColumns.CONTENT_ITEMTYPE; case WAYPOINTS: - return WaypointsColumns.CONTENT_TYPE; + return MarkerColumns.CONTENT_TYPE; case WAYPOINTS_BY_ID: case WAYPOINTS_BY_TRACKID: - return WaypointsColumns.CONTENT_ITEMTYPE; + return MarkerColumns.CONTENT_ITEMTYPE; default: throw new IllegalArgumentException("Unknown URL " + url); } @@ -214,16 +214,16 @@ public class CustomContentProvider extends ContentProvider { queryBuilder.appendWhere(TracksColumns._ID + " IN (" + TextUtils.join(SQL_LIST_DELIMITER, ContentProviderUtils.parseTrackIdsFromUri(url)) + ")"); break; case WAYPOINTS: - queryBuilder.setTables(WaypointsColumns.TABLE_NAME); - sortOrder = sort != null ? sort : WaypointsColumns.DEFAULT_SORT_ORDER; + queryBuilder.setTables(MarkerColumns.TABLE_NAME); + sortOrder = sort != null ? sort : MarkerColumns.DEFAULT_SORT_ORDER; break; case WAYPOINTS_BY_ID: - queryBuilder.setTables(WaypointsColumns.TABLE_NAME); - queryBuilder.appendWhere(WaypointsColumns._ID + "=" + ContentUris.parseId(url)); + queryBuilder.setTables(MarkerColumns.TABLE_NAME); + queryBuilder.appendWhere(MarkerColumns._ID + "=" + ContentUris.parseId(url)); break; case WAYPOINTS_BY_TRACKID: - queryBuilder.setTables(WaypointsColumns.TABLE_NAME); - queryBuilder.appendWhere(WaypointsColumns.TRACKID + " IN (" + TextUtils.join(SQL_LIST_DELIMITER, ContentProviderUtils.parseTrackIdsFromUri(url)) + ")"); + queryBuilder.setTables(MarkerColumns.TABLE_NAME); + queryBuilder.appendWhere(MarkerColumns.TRACKID + " IN (" + TextUtils.join(SQL_LIST_DELIMITER, ContentProviderUtils.parseTrackIdsFromUri(url)) + ")"); break; default: throw new IllegalArgumentException("Unknown url " + url); @@ -262,12 +262,12 @@ public class CustomContentProvider extends ContentProvider { } break; case WAYPOINTS: - table = WaypointsColumns.TABLE_NAME; + table = MarkerColumns.TABLE_NAME; whereClause = where; break; case WAYPOINTS_BY_ID: - table = WaypointsColumns.TABLE_NAME; - whereClause = WaypointsColumns._ID + "=" + ContentUris.parseId(url); + table = MarkerColumns.TABLE_NAME; + whereClause = MarkerColumns._ID + "=" + ContentUris.parseId(url); if (!TextUtils.isEmpty(where)) { whereClause += " AND (" + where + ")"; } @@ -368,9 +368,9 @@ public class CustomContentProvider extends ContentProvider { * @param contentValues the content values */ private Uri insertWaypoint(Uri url, ContentValues contentValues) { - long rowId = db.insert(WaypointsColumns.TABLE_NAME, WaypointsColumns._ID, contentValues); + long rowId = db.insert(MarkerColumns.TABLE_NAME, MarkerColumns._ID, contentValues); if (rowId >= 0) { - return ContentUris.appendId(WaypointsColumns.CONTENT_URI.buildUpon(), rowId).build(); + return ContentUris.appendId(MarkerColumns.CONTENT_URI.buildUpon(), rowId).build(); } throw new SQLException("Failed to insert a waypoint " + url); } diff --git a/src/main/java/de/dennisguse/opentracks/content/provider/CustomSQLiteOpenHelper.java b/src/main/java/de/dennisguse/opentracks/content/provider/CustomSQLiteOpenHelper.java index 0e05d6328..3d434132e 100644 --- a/src/main/java/de/dennisguse/opentracks/content/provider/CustomSQLiteOpenHelper.java +++ b/src/main/java/de/dennisguse/opentracks/content/provider/CustomSQLiteOpenHelper.java @@ -11,10 +11,10 @@ import androidx.annotation.VisibleForTesting; import java.util.UUID; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPointsColumns; import de.dennisguse.opentracks.content.data.TracksColumns; -import de.dennisguse.opentracks.content.data.WaypointsColumns; import de.dennisguse.opentracks.util.UUIDUtils; /** @@ -52,8 +52,8 @@ public class CustomSQLiteOpenHelper extends SQLiteOpenHelper { db.execSQL(TracksColumns.CREATE_TABLE); db.execSQL(TracksColumns.CREATE_TABLE_INDEX); - db.execSQL(WaypointsColumns.CREATE_TABLE); - db.execSQL(WaypointsColumns.CREATE_TABLE_INDEX); + db.execSQL(MarkerColumns.CREATE_TABLE); + db.execSQL(MarkerColumns.CREATE_TABLE_INDEX); } @Override diff --git a/src/main/java/de/dennisguse/opentracks/fragments/ChartFragment.java b/src/main/java/de/dennisguse/opentracks/fragments/ChartFragment.java index cedd9f674..7bb97c5aa 100644 --- a/src/main/java/de/dennisguse/opentracks/fragments/ChartFragment.java +++ b/src/main/java/de/dennisguse/opentracks/fragments/ChartFragment.java @@ -37,9 +37,9 @@ import de.dennisguse.opentracks.chart.ChartPoint; import de.dennisguse.opentracks.chart.ChartView; import de.dennisguse.opentracks.content.TrackDataHub; import de.dennisguse.opentracks.content.TrackDataListener; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.TrackStatisticsUpdater; import de.dennisguse.opentracks.util.LocationUtils; @@ -249,7 +249,7 @@ public class ChartFragment extends Fragment implements TrackDataListener { } @Override - public void onNewWaypoint(Waypoint waypoint) { + public void onNewWaypoint(Marker waypoint) { if (isResumed() && waypoint != null && LocationUtils.isValidLocation(waypoint.getLocation())) { chartView.addWaypoint(waypoint); } diff --git a/src/main/java/de/dennisguse/opentracks/fragments/DeleteMarkerDialogFragment.java b/src/main/java/de/dennisguse/opentracks/fragments/DeleteMarkerDialogFragment.java index 3d02bbbe5..53858f468 100644 --- a/src/main/java/de/dennisguse/opentracks/fragments/DeleteMarkerDialogFragment.java +++ b/src/main/java/de/dennisguse/opentracks/fragments/DeleteMarkerDialogFragment.java @@ -26,7 +26,7 @@ import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import de.dennisguse.opentracks.R; -import de.dennisguse.opentracks.content.data.Waypoint; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.util.DialogUtils; @@ -42,7 +42,7 @@ public class DeleteMarkerDialogFragment extends DialogFragment { private DeleteMarkerCaller caller; - public static void showDialog(FragmentManager fragmentManager, Waypoint.Id... waypointIds) { + public static void showDialog(FragmentManager fragmentManager, Marker.Id... waypointIds) { Bundle bundle = new Bundle(); bundle.putParcelableArray(KEY_MARKER_IDS, waypointIds); @@ -64,7 +64,7 @@ public class DeleteMarkerDialogFragment extends DialogFragment { @Override @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { - final Waypoint.Id[] waypointIds = (Waypoint.Id[]) getArguments().getParcelableArray(KEY_MARKER_IDS); + final Marker.Id[] waypointIds = (Marker.Id[]) getArguments().getParcelableArray(KEY_MARKER_IDS); final FragmentActivity fragmentActivity = getActivity(); int titleId; @@ -79,8 +79,8 @@ public class DeleteMarkerDialogFragment extends DialogFragment { return DialogUtils.createConfirmationDialog( fragmentActivity, titleId, getString(messageId), (dialog, which) -> new Thread(() -> { ContentProviderUtils contentProviderUtils = new ContentProviderUtils(fragmentActivity); - for (Waypoint.Id waypointId : waypointIds) { - contentProviderUtils.deleteWaypoint(getContext(), waypointId); + for (Marker.Id waypointId : waypointIds) { + contentProviderUtils.deleteMarker(getContext(), waypointId); } caller.onDeleteMarkerDone(); }).start()); diff --git a/src/main/java/de/dennisguse/opentracks/fragments/MarkerDetailFragment.java b/src/main/java/de/dennisguse/opentracks/fragments/MarkerDetailFragment.java index e9bb726c1..bd6d40e3f 100644 --- a/src/main/java/de/dennisguse/opentracks/fragments/MarkerDetailFragment.java +++ b/src/main/java/de/dennisguse/opentracks/fragments/MarkerDetailFragment.java @@ -40,7 +40,7 @@ import androidx.fragment.app.FragmentActivity; import de.dennisguse.opentracks.MarkerEditActivity; import de.dennisguse.opentracks.R; -import de.dennisguse.opentracks.content.data.Waypoint; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.util.IntentUtils; import de.dennisguse.opentracks.util.ListItemUtils; @@ -67,7 +67,7 @@ public class MarkerDetailFragment extends Fragment { private ImageView photoView; private ImageView textGradient; private LinearLayout waypointInfo; - private Waypoint waypoint; + private Marker waypoint; private final Runnable hideText = new Runnable() { @Override public void run() { @@ -93,7 +93,7 @@ public class MarkerDetailFragment extends Fragment { } }; - public static MarkerDetailFragment newInstance(Waypoint.Id waypointId) { + public static MarkerDetailFragment newInstance(Marker.Id waypointId) { Bundle bundle = new Bundle(); bundle.putParcelable(KEY_MARKER_ID, waypointId); @@ -106,7 +106,7 @@ public class MarkerDetailFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Waypoint.Id waypointId = getArguments().getParcelable(KEY_MARKER_ID); + Marker.Id waypointId = getArguments().getParcelable(KEY_MARKER_ID); if (waypointId == null) { Log.d(TAG, "invalid marker id"); getParentFragmentManager().popBackStack(); @@ -182,7 +182,7 @@ public class MarkerDetailFragment extends Fragment { @Override public boolean onOptionsItemSelected(MenuItem item) { - Waypoint.Id waypointId = getArguments().getParcelable(KEY_MARKER_ID); //TODO Should only happen in onCreate? + Marker.Id waypointId = getArguments().getParcelable(KEY_MARKER_ID); //TODO Should only happen in onCreate? FragmentActivity fragmentActivity = getActivity(); Intent intent; switch (item.getItemId()) { @@ -216,7 +216,7 @@ public class MarkerDetailFragment extends Fragment { */ private void updateWaypoint(boolean refresh) { if (refresh || waypoint == null) { - waypoint = contentProviderUtils.getWaypoint(getArguments().getParcelable(KEY_MARKER_ID)); //TODO Should only happen in onCreate? + waypoint = contentProviderUtils.getMarker(getArguments().getParcelable(KEY_MARKER_ID)); //TODO Should only happen in onCreate? if (waypoint == null) { Log.d(TAG, "waypoint is null"); getParentFragmentManager().popBackStack(); diff --git a/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordingFragment.java b/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordingFragment.java index c9b4e4cbd..558021ccb 100644 --- a/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordingFragment.java +++ b/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordingFragment.java @@ -22,9 +22,9 @@ import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.TrackRecordingActivity; import de.dennisguse.opentracks.content.TrackDataHub; import de.dennisguse.opentracks.content.TrackDataListener; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.sensor.SensorDataCycling; import de.dennisguse.opentracks.content.sensor.SensorDataHeartRate; import de.dennisguse.opentracks.content.sensor.SensorDataSet; @@ -355,7 +355,7 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi } @Override - public void onNewWaypoint(Waypoint wpt) { + public void onNewWaypoint(Marker wpt) { // We don't care. } diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/FileTrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/FileTrackExporter.java index 69b8ba4b9..517d0d7bd 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/FileTrackExporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/FileTrackExporter.java @@ -23,9 +23,9 @@ import androidx.annotation.NonNull; import java.io.OutputStream; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.content.provider.TrackPointIterator; import de.dennisguse.opentracks.util.LocationUtils; @@ -98,7 +98,7 @@ public class FileTrackExporter implements TrackExporter { * I am leaving the number of waypoints very high which should not be a problem, because we don't try to load them into objects all at the same time. */ boolean hasWaypoints = false; - try (Cursor cursor = contentProviderUtils.getWaypointCursor(track.getId(), null, ContentProviderUtils.MAX_LOADED_WAYPOINTS_POINTS)) { + try (Cursor cursor = contentProviderUtils.getMarkerCursor(track.getId(), null, ContentProviderUtils.MAX_LOADED_MARKERS)) { if (cursor != null && cursor.moveToFirst()) { for (int i = 0; i < cursor.getCount(); i++) { if (Thread.interrupted()) { @@ -108,7 +108,7 @@ public class FileTrackExporter implements TrackExporter { trackWriter.writeBeginWaypoints(track); hasWaypoints = true; } - Waypoint waypoint = contentProviderUtils.createWaypoint(cursor); + Marker waypoint = contentProviderUtils.createMarker(cursor); trackWriter.writeWaypoint(waypoint); cursor.moveToNext(); diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/GpxTrackWriter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/GpxTrackWriter.java index 178142e51..69971304f 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/GpxTrackWriter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/GpxTrackWriter.java @@ -23,9 +23,9 @@ import java.io.PrintWriter; import java.text.NumberFormat; import java.util.Locale; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.util.StringUtils; /** @@ -130,7 +130,7 @@ public class GpxTrackWriter implements TrackWriter { } @Override - public void writeWaypoint(Waypoint waypoint) { + public void writeWaypoint(Marker waypoint) { if (printWriter != null) { Location location = waypoint.getLocation(); printWriter.println(""); diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmlTrackWriter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmlTrackWriter.java index 7ebee27bf..3311e32c8 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmlTrackWriter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmlTrackWriter.java @@ -26,9 +26,9 @@ import java.util.List; import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.content.DescriptionGenerator; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.util.FileUtils; import de.dennisguse.opentracks.util.StringUtils; @@ -163,7 +163,7 @@ public class KmlTrackWriter implements TrackWriter { } @Override - public void writeWaypoint(Waypoint waypoint) { + public void writeWaypoint(Marker waypoint) { if (printWriter != null && exportTrackDetail) { boolean existsPhoto = FileUtils.getPhotoFileIfExists(context, waypoint.getTrackId(), waypoint.getPhotoURI()) != null; if (waypoint.hasPhoto() && exportPhotos && existsPhoto) { @@ -335,7 +335,7 @@ public class KmlTrackWriter implements TrackWriter { * @param waypoint Waypoint object. * @param heading the heading. */ - private void writePhotoOverlay(Waypoint waypoint, float heading) { + private void writePhotoOverlay(Marker waypoint, float heading) { if (exportTrackDetail) { printWriter.println(""); printWriter.println("" + StringUtils.formatCData(waypoint.getName()) + ""); diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmzTrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmzTrackExporter.java index 796372c5a..e59b7a228 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmzTrackExporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmzTrackExporter.java @@ -31,8 +31,8 @@ import java.io.OutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.util.FileUtils; @@ -99,13 +99,13 @@ public class KmzTrackExporter implements TrackExporter { private void addImages(Context context, Track[] tracks, ZipOutputStream zipOutputStream) throws InterruptedException, IOException { for (Track track : tracks) { - try (Cursor cursor = contentProviderUtils.getWaypointCursor(track.getId(), null, -1)) { + try (Cursor cursor = contentProviderUtils.getMarkerCursor(track.getId(), null, -1)) { if (cursor != null && cursor.moveToFirst()) { for (int i = 0; i < cursor.getCount(); i++) { if (Thread.interrupted()) { throw new InterruptedException(); } - Waypoint waypoint = contentProviderUtils.createWaypoint(cursor); + Marker waypoint = contentProviderUtils.createMarker(cursor); if (waypoint.hasPhoto()) { Uri uriPhoto = waypoint.getPhotoURI(); boolean existsPhoto = FileUtils.getPhotoFileIfExists(context, track.getId(), uriPhoto) != null; @@ -121,7 +121,7 @@ public class KmzTrackExporter implements TrackExporter { } } - private void addImage(Context context, ZipOutputStream zipOutputStream, Uri uri, Waypoint waypoint) throws IOException { + private void addImage(Context context, ZipOutputStream zipOutputStream, Uri uri, Marker waypoint) throws IOException { try (InputStream inputStream = context.getContentResolver().openInputStream(uri)) { ZipEntry zipEntry = new ZipEntry(buildKmzImageFilePath(waypoint)); zipOutputStream.putNextEntry(zipEntry); @@ -150,7 +150,7 @@ public class KmzTrackExporter implements TrackExporter { * * @param waypoint Waypoint object. */ - public static String buildKmzImageFilePath(Waypoint waypoint) { + public static String buildKmzImageFilePath(Marker waypoint) { String ext = FileUtils.getExtension(waypoint.getPhotoUrl()); ext = ext == null ? "" : "." + ext; return KMZ_IMAGES_DIR + File.separatorChar + FileUtils.sanitizeFileName(waypoint.getId() + ext); diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/TrackWriter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/TrackWriter.java index 930408174..363788173 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/TrackWriter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/TrackWriter.java @@ -17,9 +17,9 @@ package de.dennisguse.opentracks.io.file.exporter; import java.io.OutputStream; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; /** * Interface for writing tracks to a file. The expected sequence of calls is: @@ -30,7 +30,7 @@ import de.dennisguse.opentracks.content.data.Waypoint; * For each track: * {@link #writeBeginWaypoints(Track)} * For each waypoint: - * {@link #writeWaypoint(Waypoint)} + * {@link #writeWaypoint(Marker)} * {@link #writeEndWaypoints()} * {@link #writeMultiTrackBegin()} * For each track: @@ -91,7 +91,7 @@ public interface TrackWriter { * * @param waypoint the waypoint */ - void writeWaypoint(Waypoint waypoint); + void writeWaypoint(Marker waypoint); /** * Writes the beginning of the tracks. diff --git a/src/main/java/de/dennisguse/opentracks/io/file/importer/AbstractFileTrackImporter.java b/src/main/java/de/dennisguse/opentracks/io/file/importer/AbstractFileTrackImporter.java index 93f83240d..f0888c488 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/importer/AbstractFileTrackImporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/importer/AbstractFileTrackImporter.java @@ -39,9 +39,9 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.content.provider.TrackPointIterator; import de.dennisguse.opentracks.stats.TrackStatisticsUpdater; @@ -70,7 +70,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track private Track.Id importTrackId; private final List trackIds = new ArrayList<>(); - private final List waypoints = new ArrayList<>(); + private final List waypoints = new ArrayList<>(); // The current element content //TODO Should be made private and getter be used by child classes. @@ -160,7 +160,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track } int waypointPosition = -1; - Waypoint waypoint = null; + Marker waypoint = null; TrackPoint trackPoint = null; TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater(track.getTrackStatistics().getStartTime_ms()); // TODO Should not be necessary anymore? @@ -209,8 +209,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track long duration = trackStatisticsUpdater.getTrackStatistics().getTotalTime(); // Insert waypoint - Waypoint newWaypoint = new Waypoint(waypoint.getName(), waypointDescription, waypoint.getCategory(), icon, track.getId(), length, duration, trackPoint.getLocation(), waypoint.getPhotoUrl()); - contentProviderUtils.insertWaypoint(newWaypoint); + Marker newWaypoint = new Marker(waypoint.getName(), waypointDescription, waypoint.getCategory(), icon, track.getId(), length, duration, trackPoint.getLocation(), waypoint.getPhotoUrl()); + contentProviderUtils.insertMarker(newWaypoint); } // Load the next waypoint @@ -314,7 +314,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track if (!LocationUtils.isValidLocation(trackPoint.getLocation())) { throw new SAXException(createErrorMessage("Invalid location detected: " + trackPoint)); } - Waypoint waypoint = new Waypoint(trackPoint.getLocation()); + Marker waypoint = new Marker(trackPoint.getLocation()); if (name != null) { waypoint.setName(name); diff --git a/src/main/java/de/dennisguse/opentracks/io/file/importer/KmzTrackImporter.java b/src/main/java/de/dennisguse/opentracks/io/file/importer/KmzTrackImporter.java index 853749bad..d7c3c0c84 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/importer/KmzTrackImporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/importer/KmzTrackImporter.java @@ -32,8 +32,8 @@ import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.io.file.exporter.KmzTrackExporter; import de.dennisguse.opentracks.util.FileUtils; @@ -200,9 +200,9 @@ public class KmzTrackImporter implements TrackImporter { if (!trackId.isValid()) { // 1.- Gets all photo names in the waypoints of the track identified by id. ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context); - List waypoints = contentProviderUtils.getWaypoints(trackId); + List waypoints = contentProviderUtils.getMarkers(trackId); List photosName = new ArrayList<>(); - for (Waypoint w : waypoints) { + for (Marker w : waypoints) { if (w.hasPhoto()) { String photoUrl = Uri.decode(w.getPhotoUrl()); photosName.add(photoUrl.substring(photoUrl.lastIndexOf(File.separatorChar) + 1)); diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java index 3d2e877d4..4e2cb202b 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java @@ -39,9 +39,9 @@ import java.util.List; import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.TrackListActivity; import de.dennisguse.opentracks.TrackRecordingActivity; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.content.provider.CustomContentProvider; import de.dennisguse.opentracks.content.provider.TrackPointIterator; @@ -230,13 +230,13 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand * * @return the waypoint id */ - public Waypoint.Id insertWaypoint(String name, String category, String description, String photoUrl) { + public Marker.Id insertWaypoint(String name, String category, String description, String photoUrl) { if (!isRecording() || isPaused()) { return null; } if (name == null) { - int nextWaypointNumber = contentProviderUtils.getNextWaypointNumber(recordingTrackId); + int nextWaypointNumber = contentProviderUtils.getNextMarkerNumber(recordingTrackId); if (nextWaypointNumber == -1) { nextWaypointNumber = 1; } @@ -259,9 +259,9 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand long duration = stats.getTotalTime(); // Insert waypoint - Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, length, duration, trackPoint.getLocation(), photoUrl); - Uri uri = contentProviderUtils.insertWaypoint(waypoint); - return new Waypoint.Id(ContentUris.parseId(uri)); + Marker waypoint = new Marker(name, description, category, icon, recordingTrackId, length, duration, trackPoint.getLocation(), photoUrl); + Uri uri = contentProviderUtils.insertMarker(waypoint); + return new Marker.Id(ContentUris.parseId(uri)); } /** diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceBinder.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceBinder.java index 5d65c447c..6013642f9 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceBinder.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceBinder.java @@ -2,9 +2,9 @@ package de.dennisguse.opentracks.services; import androidx.annotation.VisibleForTesting; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.sensor.SensorDataSet; import de.dennisguse.opentracks.services.handlers.GpsStatusValue; import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager; @@ -90,7 +90,7 @@ class TrackRecordingServiceBinder extends android.os.Binder implements TrackReco } @Override - public Waypoint.Id insertWaypoint(String name, String category, String description, String photoUrl) { + public Marker.Id insertWaypoint(String name, String category, String description, String photoUrl) { return trackRecordingService.insertWaypoint(name, category, description, photoUrl); } diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java index a3c2004f5..2ee1e2c72 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java @@ -31,8 +31,8 @@ import androidx.annotation.NonNull; import de.dennisguse.opentracks.BuildConfig; import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.TrackEditActivity; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.util.IntentUtils; import de.dennisguse.opentracks.util.PreferencesUtils; @@ -181,13 +181,13 @@ public class TrackRecordingServiceConnection implements ServiceConnection, Death * * @return the id of the marker or null if none could be created. */ - public Waypoint.Id addMarker(Context context, String name, String category, String description, String photoUrl) { + public Marker.Id addMarker(Context context, String name, String category, String description, String photoUrl) { TrackRecordingServiceInterface trackRecordingService = getServiceIfBound(); if (trackRecordingService == null) { Log.d(TAG, "Unable to add marker, no track recording service"); } else { try { - Waypoint.Id waypoint = trackRecordingService.insertWaypoint(name, category, description, photoUrl); + Marker.Id waypoint = trackRecordingService.insertWaypoint(name, category, description, photoUrl); if (waypoint != null) { Toast.makeText(context, R.string.marker_add_success, Toast.LENGTH_SHORT).show(); return waypoint; diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceInterface.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceInterface.java index 79baa5827..4811d6957 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceInterface.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceInterface.java @@ -17,9 +17,9 @@ package de.dennisguse.opentracks.services; import androidx.annotation.VisibleForTesting; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.sensor.SensorDataSet; import de.dennisguse.opentracks.services.handlers.GpsStatusValue; import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager; @@ -93,7 +93,7 @@ public interface TrackRecordingServiceInterface { * * @return the ID of the inserted waypoint */ - Waypoint.Id insertWaypoint(String name, String category, String description, String photoUrl); + Marker.Id insertWaypoint(String name, String category, String description, String photoUrl); /** * Gets the current sensor data. Returns null if there is no data. diff --git a/src/main/java/de/dennisguse/opentracks/util/IntentDashboardUtils.java b/src/main/java/de/dennisguse/opentracks/util/IntentDashboardUtils.java index 9247d3356..44f47fc22 100644 --- a/src/main/java/de/dennisguse/opentracks/util/IntentDashboardUtils.java +++ b/src/main/java/de/dennisguse/opentracks/util/IntentDashboardUtils.java @@ -11,10 +11,10 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Set; +import de.dennisguse.opentracks.content.data.MarkerColumns; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPointsColumns; import de.dennisguse.opentracks.content.data.TracksColumns; -import de.dennisguse.opentracks.content.data.WaypointsColumns; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; /** @@ -55,7 +55,7 @@ public class IntentDashboardUtils { ArrayList uris = new ArrayList<>(); uris.add(TRACK_URI_INDEX, Uri.withAppendedPath(TracksColumns.CONTENT_URI, trackIdList)); uris.add(TRACKPOINTS_URI_INDEX, Uri.withAppendedPath(TrackPointsColumns.CONTENT_URI_BY_TRACKID, trackIdList)); - uris.add(WAYPOINTS_URI_INDEX, Uri.withAppendedPath(WaypointsColumns.CONTENT_URI_BY_TRACKID, trackIdList)); + uris.add(WAYPOINTS_URI_INDEX, Uri.withAppendedPath(MarkerColumns.CONTENT_URI_BY_TRACKID, trackIdList)); Intent intent = new Intent(ACTION_DASHBOARD); intent.putParcelableArrayListExtra(ACTION_DASHBOARD_PAYLOAD, uris); diff --git a/src/main/java/de/dennisguse/opentracks/util/IntentUtils.java b/src/main/java/de/dennisguse/opentracks/util/IntentUtils.java index 2ae273bf8..47e4e5af6 100644 --- a/src/main/java/de/dennisguse/opentracks/util/IntentUtils.java +++ b/src/main/java/de/dennisguse/opentracks/util/IntentUtils.java @@ -32,8 +32,8 @@ import java.util.Date; import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.content.DescriptionGenerator; +import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Track; -import de.dennisguse.opentracks.content.data.Waypoint; import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.content.provider.ShareContentProvider; @@ -128,7 +128,7 @@ public class IntentUtils { .putExtra(Intent.EXTRA_TEXT, context.getString(R.string.share_image_body)); } - public static void showCoordinateOnMap(Context context, Waypoint waypoint) { + public static void showCoordinateOnMap(Context context, Marker waypoint) { showCoordinateOnMap(context, waypoint.getLocation().getLatitude(), waypoint.getLocation().getLongitude(), waypoint.getName()); }