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.IBinder.DeathRecipient;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.BuildConfig;
|
import de.dennisguse.opentracks.BuildConfig;
|
||||||
import de.dennisguse.opentracks.R;
|
|
||||||
import de.dennisguse.opentracks.data.models.Marker;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the track recording service.
|
* 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) {
|
public void stopRecording(@NonNull Context context) {
|
||||||
if (trackRecordingService == null) {
|
if (trackRecordingService == null) {
|
||||||
Log.e(TAG, "TrackRecordingService not connected.");
|
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.Marker;
|
||||||
import de.dennisguse.opentracks.data.models.Track;
|
import de.dennisguse.opentracks.data.models.Track;
|
||||||
import de.dennisguse.opentracks.databinding.MarkerEditBinding;
|
import de.dennisguse.opentracks.databinding.MarkerEditBinding;
|
||||||
|
import de.dennisguse.opentracks.services.TrackRecordingService;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,15 +159,14 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
|
|
||||||
|
|
||||||
if (markerId == null) {
|
if (markerId == null) {
|
||||||
new TrackRecordingServiceConnection((service, self) -> {
|
TrackRecordingServiceConnection.execute(this, (service, self) -> {
|
||||||
Marker.Id newMarkerId = self.addMarker(MarkerEditActivity.this, "", "", "", null);
|
Marker.Id newMarkerId = createNewMarker(service);
|
||||||
if (newMarkerId == null) {
|
if (newMarkerId == null) {
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
loadMarkerData(newMarkerId);
|
loadMarkerData(newMarkerId);
|
||||||
}
|
}
|
||||||
self.unbind(this);
|
});
|
||||||
}).bind(this);
|
|
||||||
} else {
|
} else {
|
||||||
loadMarkerData(markerId);
|
loadMarkerData(markerId);
|
||||||
}
|
}
|
||||||
@@ -174,6 +174,21 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar);
|
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) {
|
private void loadMarkerData(Marker.Id markerId) {
|
||||||
viewModel.getMarkerData(markerId).observe(this, data -> {
|
viewModel.getMarkerData(markerId).observe(this, data -> {
|
||||||
marker = data;
|
marker = data;
|
||||||
|
|||||||
Reference in New Issue
Block a user