forked from upstream-mirrors/OpenTracks
Cleanup: move marker creation to MarkerEditActivity.
This commit is contained in:
@@ -24,15 +24,11 @@ import android.os.IBinder;
|
||||
import android.os.IBinder.DeathRecipient;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import de.dennisguse.opentracks.BuildConfig;
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
|
||||
/**
|
||||
* Wrapper for the track recording service.
|
||||
@@ -125,28 +121,6 @@ public class TrackRecordingServiceConnection {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Move to some other place; not needed here.
|
||||
@Nullable
|
||||
public Marker.Id addMarker(Context context, String name, String category, String description, String photoUrl) {
|
||||
if (trackRecordingService == null) {
|
||||
Log.d(TAG, "Unable to add marker, no track recording service");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Marker.Id marker = trackRecordingService.insertMarker(name, category, description, photoUrl);
|
||||
if (marker == null) {
|
||||
Toast.makeText(context, R.string.marker_add_error, Toast.LENGTH_LONG).show();
|
||||
return null;
|
||||
}
|
||||
|
||||
return marker;
|
||||
} catch (IllegalStateException e) {
|
||||
Log.e(TAG, "Unable to add marker.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void stopRecording(@NonNull Context context) {
|
||||
if (trackRecordingService == null) {
|
||||
Log.e(TAG, "TrackRecordingService not connected.");
|
||||
|
||||
@@ -47,6 +47,7 @@ import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.databinding.MarkerEditBinding;
|
||||
import de.dennisguse.opentracks.services.TrackRecordingService;
|
||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||
|
||||
/**
|
||||
@@ -158,15 +159,14 @@ public class MarkerEditActivity extends AbstractActivity {
|
||||
|
||||
|
||||
if (markerId == null) {
|
||||
new TrackRecordingServiceConnection((service, self) -> {
|
||||
Marker.Id newMarkerId = self.addMarker(MarkerEditActivity.this, "", "", "", null);
|
||||
TrackRecordingServiceConnection.execute(this, (service, self) -> {
|
||||
Marker.Id newMarkerId = createNewMarker(service);
|
||||
if (newMarkerId == null) {
|
||||
finish();
|
||||
} else {
|
||||
loadMarkerData(newMarkerId);
|
||||
}
|
||||
self.unbind(this);
|
||||
}).bind(this);
|
||||
});
|
||||
} else {
|
||||
loadMarkerData(markerId);
|
||||
}
|
||||
@@ -174,6 +174,21 @@ public class MarkerEditActivity extends AbstractActivity {
|
||||
setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar);
|
||||
}
|
||||
|
||||
private Marker.Id createNewMarker(TrackRecordingService trackRecordingService) {
|
||||
try {
|
||||
Marker.Id marker = trackRecordingService.insertMarker("", "", "", null);
|
||||
if (marker == null) {
|
||||
Toast.makeText(this, R.string.marker_add_error, Toast.LENGTH_LONG).show();
|
||||
return null;
|
||||
}
|
||||
|
||||
return marker;
|
||||
} catch (IllegalStateException e) {
|
||||
Log.e(TAG, "Unable to add marker.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadMarkerData(Marker.Id markerId) {
|
||||
viewModel.getMarkerData(markerId).observe(this, data -> {
|
||||
marker = data;
|
||||
|
||||
Reference in New Issue
Block a user