forked from upstream-mirrors/OpenTracks
Track is now a record.
This commit is contained in:
@@ -1,164 +1,46 @@
|
||||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package de.dennisguse.opentracks.data.models;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.UUID;
|
||||
|
||||
import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
|
||||
public record Track(
|
||||
// May be null if the track was not loaded from the database.
|
||||
@NonNull
|
||||
Id id,
|
||||
// May be null if the track was not loaded from the database.
|
||||
@NonNull
|
||||
UUID uuid,
|
||||
@NonNull
|
||||
String name,
|
||||
@NonNull
|
||||
String description,
|
||||
|
||||
/**
|
||||
* A track.
|
||||
*
|
||||
* @author Leif Hendrik Wilden
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
//TODO Do not default initialize attributes; might be confusing for debugging
|
||||
public class Track {
|
||||
@NonNull
|
||||
String activityTypeLocalized,
|
||||
@NonNull
|
||||
ActivityType activityType,
|
||||
@NonNull
|
||||
ZoneOffset zoneOffset,
|
||||
@NonNull
|
||||
Statistics statistics
|
||||
) {
|
||||
|
||||
private Track.Id id;
|
||||
private UUID uuid = UUID.randomUUID();
|
||||
|
||||
private String name = "";
|
||||
private String description = "";
|
||||
private String activityTypeLocalized = "";
|
||||
|
||||
private ActivityType activityType;
|
||||
|
||||
@NonNull
|
||||
private ZoneOffset zoneOffset;
|
||||
|
||||
@NonNull
|
||||
private Statistics trackStatistics;
|
||||
|
||||
@VisibleForTesting
|
||||
public Track(Statistics statistics) {
|
||||
this(ZoneOffset.UTC, statistics);
|
||||
}
|
||||
|
||||
public Track(@NonNull ZoneOffset zoneOffset, @NonNull Statistics trackStatistics) {
|
||||
this.zoneOffset = zoneOffset;
|
||||
this.trackStatistics = trackStatistics;
|
||||
}
|
||||
|
||||
/**
|
||||
* May be null if the track was not loaded from the database.
|
||||
*/
|
||||
@Nullable
|
||||
public Id getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Id id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getActivityTypeLocalized() {
|
||||
return activityTypeLocalized;
|
||||
}
|
||||
|
||||
public void setActivityTypeLocalized(String activityTypeLocalized) {
|
||||
this.activityTypeLocalized = activityTypeLocalized;
|
||||
}
|
||||
|
||||
public ActivityType getActivityType() {
|
||||
return activityType;
|
||||
}
|
||||
|
||||
public void setActivityType(ActivityType activityType) {
|
||||
this.activityType = activityType;
|
||||
}
|
||||
|
||||
public void setActivityTypeLocalizedAndUpdateActivityType(Context context, String activityTypeLocalized) {
|
||||
setActivityTypeLocalized(activityTypeLocalized);
|
||||
setActivityType(ActivityType.findByLocalizedString(context, activityTypeLocalized));
|
||||
}
|
||||
|
||||
public ZoneOffset getZoneOffset() {
|
||||
return zoneOffset;
|
||||
}
|
||||
|
||||
public void setZoneOffset(@NonNull ZoneOffset zoneOffset) {
|
||||
this.zoneOffset = zoneOffset;
|
||||
}
|
||||
|
||||
public OffsetDateTime getStartTime() {
|
||||
return trackStatistics
|
||||
public OffsetDateTime startTime() {
|
||||
return statistics
|
||||
.startTime().atOffset(zoneOffset);
|
||||
}
|
||||
|
||||
public OffsetDateTime getStopTime() {
|
||||
return trackStatistics
|
||||
public OffsetDateTime stopTime() {
|
||||
return statistics
|
||||
.stopTime().atOffset(zoneOffset);
|
||||
}
|
||||
|
||||
public Statistics getStatistics() {
|
||||
return trackStatistics;
|
||||
}
|
||||
|
||||
public void setStatistics(Statistics trackStatistics) {
|
||||
this.trackStatistics = trackStatistics;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Track{" +
|
||||
"name='" + name + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", activityTypeLocalized='" + activityTypeLocalized + '\'' +
|
||||
", activityType=" + activityType +
|
||||
'}';
|
||||
}
|
||||
|
||||
public record Id(long id) implements Parcelable {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user