Skip to content

Commit

Permalink
remove marker mapping to trackpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorch committed Jul 25, 2024
1 parent 8bcfa01 commit c2acaa5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void kml22_with_statistics_marker() throws IOException {
assertEquals(ActivityType.UNKNOWN, importedTrack.getActivityType());

// 2. markers
assertEquals(0, contentProviderUtils.getMarkers(importTrackId).size());
assertEquals(1, contentProviderUtils.getMarkers(importTrackId).size());

// 3. trackpoints
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.data.ContentProviderUtils;
Expand All @@ -26,7 +25,6 @@
import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.stats.TrackStatistics;
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
import de.dennisguse.opentracks.ui.markers.MarkerUtils;
import de.dennisguse.opentracks.util.FileUtils;
Expand Down Expand Up @@ -158,7 +156,7 @@ private void finishTrack() {
contentProviderUtils.bulkInsertTrackPoint(trackPoints, trackId);

// Store Markers
matchMarkers2TrackPoints(trackId);
updateMarkers(trackId);
for (Marker marker : markers)
marker.setTrackId(trackId); //TODO Should happen in bulkInsertMarkers

Expand Down Expand Up @@ -217,41 +215,16 @@ private void adjustTrackPoints() {
}

/**
* NOTE: Modifies content of markers (incl. removal).
* NOTE: Modifies content of markers.
*/
private void matchMarkers2TrackPoints(Track.Id trackId) {
List<Marker> todoMarkers = new LinkedList<>(markers);
List<Marker> doneMarkers = new LinkedList<>();
markers.clear();

if (todoMarkers.isEmpty()) {
Log.w(TAG, "Some markers could not be attached to TrackPoints; those are not imported.");
return;
}
private void updateMarkers(Track.Id trackId) {
markers.forEach(marker -> {
if (marker.hasPhoto()) {
marker.setPhotoUrl(getInternalPhotoUrl(trackId, marker.getPhotoUrl()));
}

// TODO: why do we need to match the markers with the TrackPoints? We will loose the manual added from the map.
trackPoints.stream()
.filter(TrackPoint::hasLocation)
.forEach(trackPoint -> {
List<Marker> matchedMarkers = todoMarkers.stream()
.filter(it -> trackPoint.getLatitude() == it.getLatitude()
&& trackPoint.getLongitude() == it.getLongitude()
&& trackPoint.getTime().equals(it.getTime())
).peek(marker -> {
if (marker.hasPhoto()) {
marker.setPhotoUrl(getInternalPhotoUrl(trackId, marker.getPhotoUrl()));
}

marker.setIcon(context.getString(R.string.marker_icon_url)); //TODO Why?
marker.setTrackPoint(trackPoint);
})
.toList();

todoMarkers.removeAll(matchedMarkers);
doneMarkers.addAll(matchedMarkers);
});

markers.addAll(doneMarkers);
marker.setIcon(context.getString(R.string.marker_icon_url)); //TODO Why?
});
}

/**
Expand Down

0 comments on commit c2acaa5

Please sign in to comment.