Skip to content

Commit

Permalink
Defer new Marker creation to end of MarkerEditActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorch committed Jul 25, 2024
1 parent 91be7b9 commit f06dc85
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void setUp() throws TimeoutException {
Distance sensorDistance = Distance.of(10); // recording distance interval

sendLocation(trackPointCreator, "2020-02-02T02:02:03Z", 3, 14, 10, 13, 15, 10, 1f);
service.insertMarker("Marker 1", "Marker 1 category", "Marker 1 desc", null, null, null);
contentProviderUtils.insertMarker(new Marker("Marker 1", "Marker 1 desc", "Marker 1 category", null, trackId, service.getLastStoredTrackPointWithLocation(), ""));

// A sensor-only TrackPoint
trackPointCreator.setClock("2020-02-02T02:02:04Z");
Expand All @@ -156,7 +156,7 @@ public void setUp() throws TimeoutException {
mockSensorData(trackPointCreator, 5f, Distance.of(2), 69f, 3f, 50f, null); // Distance will be added to next TrackPoint

sendLocation(trackPointCreator, "2020-02-02T02:02:17Z", 3, 14.001, 10, 13, 15, 10, 0f);
service.insertMarker("Marker 2", "Marker 2 category", "Marker 2 desc", null, null, null);
contentProviderUtils.insertMarker(new Marker("Marker 2", "Marker 2 desc", "Marker 2 category", null, trackId, service.getLastStoredTrackPointWithLocation(), ""));

trackPointCreator.setClock("2020-02-02T02:02:18Z");
trackPointCreator.getSensorManager().sensorDataSet = new SensorDataSet();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.ui.markers.MarkerEditActivity;
import de.dennisguse.opentracks.util.IntentUtils;

Expand All @@ -26,12 +23,6 @@ public class CreateMarkerActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (!PreferencesUtils.isPublicAPIenabled()) {
Toast.makeText(this, R.string.publicapi_disabled, Toast.LENGTH_LONG).show();
finish();
return;
}

Track.Id trackId = new Track.Id(getIntent().getLongExtra(EXTRA_TRACK_ID, 0L));
Location location = getIntent().getParcelableExtra(EXTRA_LOCATION);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package de.dennisguse.opentracks.services;

import android.content.ContentUris;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Handler;
import android.util.Log;
import android.util.Pair;
Expand All @@ -19,7 +17,6 @@
import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.ActivityType;
import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
Expand Down Expand Up @@ -138,26 +135,6 @@ Pair<Track, Pair<TrackPoint, SensorDataSet>> getDataForUI() {
return new Pair<>(track, current);
}

public Marker.Id insertMarker(String name, String category, String description, String photoUrl, Track.Id trackId, TrackPoint trackPoint) {
if (name == null) {
Integer nextMarkerNumber = contentProviderUtils.getNextMarkerNumber(trackId);
if (nextMarkerNumber == null) {
nextMarkerNumber = 1;
}
name = context.getString(R.string.marker_name_format, nextMarkerNumber + 1);
}

category = category != null ? category : "";
description = description != null ? description : "";
String icon = context.getString(R.string.marker_icon_url);
photoUrl = photoUrl != null ? photoUrl : "";

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

@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void onIdle() {
Log.d(TAG, "Becoming idle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.util.Log;
import android.util.Pair;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.app.ServiceCompat;
Expand All @@ -38,7 +37,6 @@
import java.time.Duration;

import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
Expand Down Expand Up @@ -274,10 +272,6 @@ public void newGpsStatus(GpsStatusValue gpsStatusValue) {
gpsStatusObservable.postValue(gpsStatusValue);
}

public Marker.Id insertMarker(String name, String category, String description, String photoUrl, @NonNull Track.Id trackId, @NonNull TrackPoint trackPoint) {
return trackRecordingManager.insertMarker(name, category, description, photoUrl, trackId, trackPoint);
}

@Deprecated
@VisibleForTesting
public TrackPointCreator getTrackPointCreator() {
Expand Down
Loading

0 comments on commit f06dc85

Please sign in to comment.