Skip to content

Commit

Permalink
provide Location to MarkerEditActivity via Intent
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorch committed Jul 19, 2024
1 parent 9bff3eb commit 766bc23
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import de.dennisguse.opentracks.data.TrackDataHub;
import de.dennisguse.opentracks.data.models.ActivityType;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.databinding.TrackRecordingBinding;
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
import de.dennisguse.opentracks.fragments.StatisticsRecordingFragment;
Expand Down Expand Up @@ -269,9 +270,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

if (item.getItemId() == R.id.track_detail_insert_marker) {
TrackPoint trackPoint = trackRecordingServiceConnection.getTrackRecordingService().getLastStoredTrackPointWithLocation();
if (trackPoint == null) {
return true;
}
Intent intent = IntentUtils
.newIntent(this, MarkerEditActivity.class)
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId);
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId)
.putExtra(MarkerEditActivity.EXTRA_LOCATION, trackPoint.getLocation());
startActivity(intent);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,21 @@ Pair<Track, Pair<TrackPoint, SensorDataSet>> getDataForUI() {
}

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

TrackPoint markerTrackPoint = trackPoint != null ? trackPoint : lastStoredTrackPointWithLocation;
if (markerTrackPoint == null) {
Log.i(TAG, "Could not create a marker as trackPoint is unknown.");
return null;
}

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, markerTrackId, getTrackStatistics(), markerTrackPoint, photoUrl);
Marker marker = new Marker(name, description, category, icon, trackId, getTrackStatistics(), trackPoint, photoUrl);
Uri uri = contentProviderUtils.insertMarker(marker);
return new Marker.Id(ContentUris.parseId(uri));
}
Expand Down Expand Up @@ -249,10 +242,7 @@ synchronized boolean onNewTrackPoint(@NonNull TrackPoint trackPoint) {
}

TrackStatistics getTrackStatistics() {
if (trackStatisticsUpdater == null) {
return null;
}
return trackStatisticsUpdater.getTrackStatistics();
return trackStatisticsUpdater == null ? null : trackStatisticsUpdater.getTrackStatistics();
}

private void insertTrackPoint(@NonNull TrackPoint trackPoint, boolean storeLastTrackPointIfUseful) {
Expand Down Expand Up @@ -313,6 +303,10 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
}

public TrackPoint getLastStoredTrackPointWithLocation() {
return lastStoredTrackPointWithLocation;
}

public interface IdleObserver {
void onIdle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
public static final RecordingData NOT_RECORDING = new RecordingData(null, null, null);
public static final GpsStatusValue STATUS_GPS_DEFAULT = GpsStatusValue.GPS_NONE;

public TrackPoint getLastStoredTrackPointWithLocation() {
return trackRecordingManager.getLastStoredTrackPointWithLocation();
}

public class Binder extends android.os.Binder {

private Binder() {
Expand Down Expand Up @@ -270,7 +274,7 @@ public void newGpsStatus(GpsStatusValue gpsStatusValue) {
}

public Marker.Id insertMarker(String name, String category, String description, String photoUrl, Track.Id trackId, TrackPoint trackPoint) {
if (!isRecording() && (trackId == null || trackPoint == null)) {
if (trackId == null || trackPoint == null) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ protected void onCreate(Bundle savedInstanceState) {

private Marker.Id createNewMarker(TrackRecordingService trackRecordingService) {
try {
TrackPoint trackPoint = null;
if (location != null) {
trackPoint = new TrackPoint(location, Instant.now());
if (location == null) {
throw new IllegalStateException("Location is null");
}
TrackPoint trackPoint = new TrackPoint(location, Instant.now());
Marker.Id marker = trackRecordingService.insertMarker("", "", "", null, trackId, trackPoint);
if (marker == null) {
Toast.makeText(this, R.string.marker_add_error, Toast.LENGTH_LONG).show();
Expand Down

0 comments on commit 766bc23

Please sign in to comment.