Skip to content

Commit

Permalink
simplify CreateMarkerActivity to MarkerEditActivity interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorch committed Jul 25, 2024
1 parent c2acaa5 commit 91be7b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import java.time.Instant;

import de.dennisguse.opentracks.AbstractActivity;
import de.dennisguse.opentracks.R;
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.services.TrackRecordingService;
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.ui.markers.MarkerEditActivity;
Expand All @@ -31,8 +22,6 @@ public class CreateMarkerActivity extends AppCompatActivity {
public static final String EXTRA_TRACK_ID = "track_id";
public static final String EXTRA_LOCATION = "location";

private static final String TAG = CreateMarkerActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -44,26 +33,16 @@ protected void onCreate(Bundle savedInstanceState) {
}

Track.Id trackId = new Track.Id(getIntent().getLongExtra(EXTRA_TRACK_ID, 0L));
TrackPoint trackPoint = new TrackPoint(getIntent().<Location>getParcelableExtra(EXTRA_LOCATION), Instant.now());
Location location = getIntent().getParcelableExtra(EXTRA_LOCATION);

TrackRecordingServiceConnection.execute(this, (service, self) -> {
Marker.Id marker = createNewMarker(trackId, trackPoint, service);
if (marker == null) {
Toast.makeText(this, R.string.create_marker_error, Toast.LENGTH_LONG).show();
} else {
Intent intent = IntentUtils
.newIntent(this, MarkerEditActivity.class)
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId)
.putExtra(MarkerEditActivity.EXTRA_MARKER_ID, marker)
.putExtra(MarkerEditActivity.EXTRA_IS_NEW_MARKER, true);
startActivity(intent);
}
Intent intent = IntentUtils
.newIntent(this, MarkerEditActivity.class)
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId)
.putExtra(MarkerEditActivity.EXTRA_LOCATION, location);
startActivity(intent);
finish();
});
}

private Marker.Id createNewMarker(@NonNull Track.Id trackId, @NonNull TrackPoint trackPoint, TrackRecordingService trackRecordingService) {
return trackRecordingService.insertMarker("", "", "", null, trackId, trackPoint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public class MarkerEditActivity extends AbstractActivity {
public static final String EXTRA_TRACK_ID = "track_id";
public static final String EXTRA_MARKER_ID = "marker_id";
public static final String EXTRA_LOCATION = "location";
public static final String EXTRA_IS_NEW_MARKER = "is_new_marker";

private static final String CAMERA_PHOTO_URI_KEY = "camera_photo_uri_key";

Expand Down Expand Up @@ -101,7 +100,7 @@ protected void onCreate(Bundle savedInstanceState) {
trackId = getIntent().getParcelableExtra(EXTRA_TRACK_ID);
location = getIntent().getParcelableExtra(EXTRA_LOCATION);
@Nullable Marker.Id markerId = getIntent().getParcelableExtra(EXTRA_MARKER_ID);
final boolean isNewMarker = markerId == null || getIntent().getBooleanExtra(EXTRA_IS_NEW_MARKER, false);
final boolean isNewMarker = markerId == null;

if (savedInstanceState != null) {
cameraPhotoUri = Uri.parse(savedInstanceState.getString(CAMERA_PHOTO_URI_KEY, ""));
Expand Down

0 comments on commit 91be7b9

Please sign in to comment.