Skip to content

Commit

Permalink
remove length and duration from Marker, remove Marker from ChartView
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorch committed Jul 22, 2024
1 parent 766bc23 commit 31be6d0
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public static TrackData createTestingTrack(Track.Id trackId) {
stats.setTotalDistance(Distance.of(0));
stats.setTotalTime(Duration.ofMillis(0));
List<Marker> markers = List.of(
new Marker("Marker 1", "Marker description 1", "Marker category 3", "", trackId, stats, trackPoints.get(1), null),
new Marker("Marker 2", "Marker description 2", "Marker category 3", "", trackId, stats, trackPoints.get(4), null),
new Marker("Marker 3", "Marker description 3", "Marker category 3", "", trackId, stats, trackPoints.get(5), null)
new Marker("Marker 1", "Marker description 1", "Marker category 3", "", trackId, trackPoints.get(1), null),
new Marker("Marker 2", "Marker description 2", "Marker category 3", "", trackId, trackPoints.get(4), null),
new Marker("Marker 3", "Marker description 3", "Marker category 3", "", trackId, trackPoints.get(5), null)
);

return new TrackData(track, trackPoints, markers);
Expand Down Expand Up @@ -152,7 +152,7 @@ public static Marker createMarkerWithPhoto(Context context, Track.Id trackId, Tr
stats.setTotalDistance(Distance.of(0));
stats.setTotalTime(Duration.ofMillis(0));

return new Marker("Marker name", "Marker description", "Marker category", "", trackId, stats, trackPoint, photoUrl);
return new Marker("Marker name", "Marker description", "Marker category", "", trackId, trackPoint, photoUrl);
}

public static List<TrackPoint> getTrackPoints(ContentProviderUtils contentProviderUtils, Track.Id trackId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,20 @@ public void recording_GPSfix_createsMarker() {
service.stopUpdateRecordingData();

assertTrue(service.isRecording());
trackPointCreator.onNewTrackPoint(
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:03Z"))
.setLatitude(10)
.setLongitude(10)
);
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:03Z"))
.setLatitude(10)
.setLongitude(10);
trackPointCreator.onNewTrackPoint(trackPoint);

// when
Marker.Id markerId = service.insertMarker(null, null, null, null, null, null);
Marker.Id markerId = service.insertMarker(null, null, null, null, trackId, trackPoint);

// then
assertNotEquals(new Marker.Id(-1L), markerId);
Marker wpt = contentProviderUtils.getMarker(markerId);
assertEquals(context.getString(R.string.marker_icon_url), wpt.getIcon());
assertEquals(context.getString(R.string.marker_name_format, 1), wpt.getName());
assertEquals(trackId, wpt.getTrackId());
assertEquals(0.0, wpt.getLength().toM(), 0.01);
assertNotNull(wpt.getLocation());

trackPointCreator.setClock("2020-02-02T02:02:04Z");
Expand Down
58 changes: 0 additions & 58 deletions src/main/java/de/dennisguse/opentracks/chart/ChartView.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,31 +152,6 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
return true;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent event) {
// 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;
Marker nearestMarker = null;
synchronized (markers) {
for (Marker marker : markers) {
int distance = Math.abs(getX(getMarkerXValue(marker)) - (int) event.getX() - getScrollX());
if (distance < minDistance) {
minDistance = distance;
nearestMarker = marker;
}
}
}
if (nearestMarker != null && minDistance < markerWidth) {
Intent intent = IntentUtils.newIntent(getContext(), MarkerDetailActivity.class)
.putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, nearestMarker.getId());
getContext().startActivity(intent);
return true;
}
}

return false;
}
});

private final ScaleGestureDetector detectorZoom = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() {
Expand Down Expand Up @@ -589,7 +564,6 @@ protected void onDraw(Canvas canvas) {

clipToGraphArea(canvas);
drawDataSeries(canvas);
drawMarker(canvas);
drawGrid(canvas);

canvas.restore();
Expand Down Expand Up @@ -630,30 +604,6 @@ private void drawDataSeries(Canvas canvas) {
}
}

private void drawMarker(Canvas canvas) {
synchronized (markers) {
for (Marker marker : markers) {
double xValue = getMarkerXValue(marker);
double markerIconSizeInXaxisUnits = maxX*markerWidth/effectiveWidth / zoomLevel;
if (xValue > maxX + markerIconSizeInXaxisUnits * (1-MARKER_X_ANCHOR)) {
continue; // there is no chance that this marker will be visible
}
canvas.save();
float x = getX(getMarkerXValue(marker));
canvas.drawLine(x, topBorder + spacer + markerHeight / 2, x, topBorder + effectiveHeight, markerPaint);
// if marker is not near the end of the track then draw it normally
if (xValue < maxX - markerIconSizeInXaxisUnits*(1-MARKER_X_ANCHOR)) {
canvas.translate(x - (markerWidth * MARKER_X_ANCHOR), topBorder + spacer);
} else { // marker at the end needs to be drawn mirrored so that it is more visible
canvas.translate(x + (markerWidth * MARKER_X_ANCHOR), topBorder + spacer);
canvas.scale(-1, 1);
}
markerPin.draw(canvas);
canvas.restore();
}
}
}

/**
* Draws the grid.
*
Expand Down Expand Up @@ -1042,14 +992,6 @@ private int getY(ChartValueSeries chartValueSeries, double value) {
return topBorder + yAxisOffset + (int) ((1 - percentage) * rangeHeight);
}

private double getMarkerXValue(Marker marker) {
if (chartByDistance) {
return marker.getLength().toKM_Miles(unitSystem);
} else {
return marker.getDuration().toMillis();
}
}

/**
* Gets a paint's Rect for a string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,6 @@ public Marker createMarker(Cursor cursor) {
if (!cursor.isNull(iconIndex)) {
marker.setIcon(cursor.getString(iconIndex));
}
if (!cursor.isNull(lengthIndex)) {
marker.setLength(Distance.of(cursor.getFloat(lengthIndex)));
}
if (!cursor.isNull(durationIndex)) {
marker.setDuration(Duration.ofMillis(cursor.getLong(durationIndex)));
}

if (!cursor.isNull(photoUrlIndex)) {
marker.setPhotoUrl(cursor.getString(photoUrlIndex));
}
Expand Down Expand Up @@ -542,9 +535,6 @@ ContentValues createContentValues(@NonNull Marker marker) {
values.put(MarkerColumns.CATEGORY, marker.getCategory());
values.put(MarkerColumns.ICON, marker.getIcon());
values.put(MarkerColumns.TRACKID, marker.getTrackId().id());
values.put(MarkerColumns.LENGTH, marker.getLength().toM());
values.put(MarkerColumns.DURATION, marker.getDuration().toMillis());

values.put(MarkerColumns.LONGITUDE, (int) (marker.getLongitude() * 1E6));
values.put(MarkerColumns.LATITUDE, (int) (marker.getLatitude() * 1E6));
values.put(MarkerColumns.TIME, marker.getTime().toEpochMilli());
Expand Down
35 changes: 1 addition & 34 deletions src/main/java/de/dennisguse/opentracks/data/models/Marker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.time.Duration;
import java.time.Instant;

import de.dennisguse.opentracks.stats.TrackStatistics;

/**
* NOTE: A marker is indirectly (via it's location) assigned to one {@link TrackPoint} with trackPoint.hasLocation() == true.
*
Expand All @@ -53,10 +51,6 @@ public final class Marker {
private Altitude altitude;
private Float bearing;

//TODO It is the distance from the track starting point; rename to something more meaningful
private Distance length;
private Duration duration;

@Deprecated //TODO Make an URI instead of String
private String photoUrl = "";

Expand All @@ -65,7 +59,6 @@ public Marker(@Nullable Track.Id trackId, Instant time) {
this.time = time;
}

@Deprecated //TODO Marker cannot be created without length AND duration!
public Marker(@Nullable Track.Id trackId, @NonNull TrackPoint trackPoint) {
this.trackId = trackId;

Expand All @@ -75,25 +68,15 @@ public Marker(@Nullable Track.Id trackId, @NonNull TrackPoint trackPoint) {
throw new RuntimeException("Marker requires a trackpoint with a location.");

setTrackPoint(trackPoint);

this.length = Distance.of(0); //TODO Not cool!
this.duration = Duration.ofMillis(0); //TODO Not cool!
}

@Deprecated
public Marker(String name, String description, String category, String icon, @NonNull Track.Id trackId, TrackStatistics statistics, @NonNull TrackPoint trackPoint, String photoUrl) {
public Marker(String name, String description, String category, String icon, @NonNull Track.Id trackId, @NonNull TrackPoint trackPoint, String photoUrl) {
this(trackId, trackPoint);
this.name = name;
this.description = description;
this.category = category;
this.icon = icon;
if (statistics == null) {
this.length = Distance.of(0);
this.duration = Duration.ofMillis(0);
} else {
this.length = statistics.getTotalDistance();
this.duration = statistics.getTotalTime();
}
this.photoUrl = photoUrl;
}

Expand Down Expand Up @@ -239,22 +222,6 @@ public void setBearing(float bearing) {
this.bearing = bearing;
}

public Distance getLength() {
return length;
}

public void setLength(Distance length) {
this.length = length;
}

public Duration getDuration() {
return duration;
}

public void setDuration(@NonNull Duration duration) {
this.duration = duration;
}

public String getPhotoUrl() {
return photoUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ private void matchMarkers2TrackPoints(Track.Id trackId) {
}

marker.setIcon(context.getString(R.string.marker_icon_url)); //TODO Why?

marker.setLength(statistics.getTotalDistance());
marker.setDuration(statistics.getTotalTime());

marker.setTrackPoint(trackPoint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public Marker.Id insertMarker(String name, String category, String description,
photoUrl = photoUrl != null ? photoUrl : "";

// Insert marker
Marker marker = new Marker(name, description, category, icon, trackId, getTrackStatistics(), trackPoint, photoUrl);
Marker marker = new Marker(name, description, category, icon, trackId, trackPoint, photoUrl);
Uri uri = contentProviderUtils.insertMarker(marker);
return new Marker.Id(ContentUris.parseId(uri));
}
Expand Down

0 comments on commit 31be6d0

Please sign in to comment.