forked from upstream-mirrors/OpenTracks
Bugfix: crash on recording start due to show latitude/longitude option.
Fixes #613.
This commit is contained in:
@@ -174,7 +174,23 @@ public class TrackPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasLocation() {
|
public boolean hasLocation() {
|
||||||
return latitude != null || longitude != null;
|
return latitude != null && longitude != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLatitude() {
|
||||||
|
return latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLatitude(double latitude) {
|
||||||
|
this.latitude = latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLongitude() {
|
||||||
|
return longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLongitude(double longitude) {
|
||||||
|
this.longitude = longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -222,22 +238,6 @@ public class TrackPoint {
|
|||||||
this.elevationLoss = elevationLoss;
|
this.elevationLoss = elevationLoss;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLatitude() {
|
|
||||||
return latitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLatitude(double latitude) {
|
|
||||||
this.latitude = latitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getLongitude() {
|
|
||||||
return longitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLongitude(double longitude) {
|
|
||||||
this.longitude = longitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Instant getTime() {
|
public Instant getTime() {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import de.dennisguse.opentracks.content.TrackDataListener;
|
|||||||
import de.dennisguse.opentracks.content.data.Marker;
|
import de.dennisguse.opentracks.content.data.Marker;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorData;
|
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataCycling;
|
import de.dennisguse.opentracks.content.sensor.SensorDataCycling;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
import de.dennisguse.opentracks.databinding.StatisticsRecordingBinding;
|
import de.dennisguse.opentracks.databinding.StatisticsRecordingBinding;
|
||||||
@@ -444,12 +443,13 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
|
|
||||||
viewBinding.statsCoordinateGroup.setVisibility(showCoordinate ? View.VISIBLE : View.GONE);
|
viewBinding.statsCoordinateGroup.setVisibility(showCoordinate ? View.VISIBLE : View.GONE);
|
||||||
if (showCoordinate) {
|
if (showCoordinate) {
|
||||||
double latitude = lastTrackPoint != null ? lastTrackPoint.getLatitude() : Double.NaN;
|
String latitudeText = getContext().getString(R.string.value_unknown);
|
||||||
String latitudeText = Double.isNaN(latitude) || Double.isInfinite(latitude) ? getContext().getString(R.string.value_unknown) : StringUtils.formatCoordinate(latitude);
|
String longitudeText = getContext().getString(R.string.value_unknown);
|
||||||
|
if (lastTrackPoint != null && lastTrackPoint.hasLocation()) {
|
||||||
|
latitudeText = StringUtils.formatCoordinate(lastTrackPoint.getLatitude());
|
||||||
|
longitudeText = StringUtils.formatCoordinate(lastTrackPoint.getLatitude());
|
||||||
|
}
|
||||||
viewBinding.statsLatitudeValue.setText(latitudeText);
|
viewBinding.statsLatitudeValue.setText(latitudeText);
|
||||||
|
|
||||||
double longitude = lastTrackPoint != null ? lastTrackPoint.getLongitude() : Double.NaN;
|
|
||||||
String longitudeText = Double.isNaN(longitude) || Double.isInfinite(longitude) ? getContext().getString(R.string.value_unknown) : StringUtils.formatCoordinate(longitude);
|
|
||||||
viewBinding.statsLongitudeValue.setText(longitudeText);
|
viewBinding.statsLongitudeValue.setText(longitudeText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ public class LocationUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a given location is a valid (i.e. physically possible) location on Earth.
|
* Checks if a given location is a valid (i.e. physically possible) location on Earth.
|
||||||
* Neither will locations with lat=0 and lng=0 as these are most likely "bad" measurements which often cause trouble.
|
|
||||||
*
|
*
|
||||||
* @param location the location to test
|
* @param location the location to test
|
||||||
* @return true if the location is a valid location.
|
* @return true if the location is a valid location.
|
||||||
@@ -50,8 +49,9 @@ public class LocationUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTrackPointOld(TrackPoint trackPoint) {
|
public static boolean isTrackPointOld(TrackPoint trackPoint) {
|
||||||
return Duration.between(trackPoint.getTime(), Instant.now())
|
Instant now = Instant.now();
|
||||||
|
return !(Duration.between(trackPoint.getTime(), now)
|
||||||
.minus(MAX_LOCATION_AGE)
|
.minus(MAX_LOCATION_AGE)
|
||||||
.isNegative();
|
.isNegative());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user