mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Cleanup: move track.uuid generation to ContentProviderUtils.
Part of #2383.
This commit is contained in:
@@ -51,6 +51,7 @@ import de.dennisguse.opentracks.data.models.Speed;
|
||||
import de.dennisguse.opentracks.data.models.Statistics;
|
||||
import de.dennisguse.opentracks.data.models.Temperature;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.data.models.TrackBuilder;
|
||||
import de.dennisguse.opentracks.data.models.TrackPoint;
|
||||
import de.dennisguse.opentracks.data.statistics.SensorStatistics;
|
||||
import de.dennisguse.opentracks.data.tables.MarkerColumns;
|
||||
@@ -232,12 +233,16 @@ public class ContentProviderUtils {
|
||||
/**
|
||||
* Inserts a track.
|
||||
* NOTE: This doesn't insert any trackPoints.
|
||||
* NOTE: if the track.uuid is null, a random value will be assigned.
|
||||
*
|
||||
* @param track the track
|
||||
* @return the content provider URI of the inserted track.
|
||||
*/
|
||||
public Track.Id insertTrack(Track track) {
|
||||
//TODO Unset trackId
|
||||
//TODO Unset trackId as it should be database generated
|
||||
if (track.uuid() == null) {
|
||||
track = new TrackBuilder(track, UUID.randomUUID()).getTrack();
|
||||
}
|
||||
Uri uri = contentResolver.insert(CustomContentProvider.UrlType.TRACKS.getUri(), createContentValues(track));
|
||||
return new Track.Id(ContentUris.parseId(uri));
|
||||
}
|
||||
|
||||
@@ -57,6 +57,17 @@ public class TrackBuilder {
|
||||
this.trackStatistics = track.statistics();
|
||||
}
|
||||
|
||||
public TrackBuilder(Track track, UUID uuid) {
|
||||
this.id = track.id();
|
||||
this.uuid = uuid;
|
||||
this.name = track.name();
|
||||
this.description = track.description();
|
||||
this.activityTypeLocalized = track.activityTypeLocalized();
|
||||
this.activityType = track.activityType();
|
||||
this.zoneOffset = track.zoneOffset();
|
||||
this.trackStatistics = track.statistics();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -30,5 +30,6 @@ import de.dennisguse.opentracks.data.models.Track;
|
||||
*/
|
||||
public interface TrackExporter {
|
||||
|
||||
//TODO Pass track.Id instead of track?
|
||||
boolean writeTrack(List<Track> tracks, @NonNull OutputStream outputStream);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class TrackImporter {
|
||||
}
|
||||
|
||||
//TODO This is a workaround until we have proper UI.
|
||||
trackData.uuid = UUID.randomUUID();
|
||||
trackData.uuid = null;
|
||||
}
|
||||
|
||||
trackPoints.sort(Comparator.comparing(TrackPoint::getTime));
|
||||
|
||||
@@ -79,7 +79,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
|
||||
trackId = contentProviderUtils.insertTrack(
|
||||
new Track(
|
||||
null,
|
||||
UUID.randomUUID(), //TODO This is not really cool: should happen in ContentProviderUtils?
|
||||
null,
|
||||
"",
|
||||
"",
|
||||
activityTypeLocalized,
|
||||
|
||||
Reference in New Issue
Block a user