forked from upstream-mirrors/OpenTracks
Elevation gain: make it optional as Float - and if null, then the UI just shows "-".
In TrackStatistics the elevation gain is now nullable.
This commit is contained in:
+1
-1
@@ -455,7 +455,7 @@ public class CustomContentProviderUtilsTest {
|
|||||||
statistics.setTotalTime(1500L);
|
statistics.setTotalTime(1500L);
|
||||||
statistics.setMovingTime(700L);
|
statistics.setMovingTime(700L);
|
||||||
statistics.setTotalDistance(750.0);
|
statistics.setTotalDistance(750.0);
|
||||||
statistics.setTotalElevationGain(50.0);
|
statistics.setTotalElevationGain(50.0f);
|
||||||
statistics.setMaxSpeed(60.0);
|
statistics.setMaxSpeed(60.0);
|
||||||
statistics.setMaxElevation(1250.0);
|
statistics.setMaxElevation(1250.0);
|
||||||
statistics.setMinElevation(1200.0);
|
statistics.setMinElevation(1200.0);
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public class TrackStatisticsTest {
|
|||||||
statistics2.setMovingTime(600L); // Result: 700+600
|
statistics2.setMovingTime(600L); // Result: 700+600
|
||||||
statistics.setTotalDistance(750.0);
|
statistics.setTotalDistance(750.0);
|
||||||
statistics2.setTotalDistance(350.0); // Result: 750+350
|
statistics2.setTotalDistance(350.0); // Result: 750+350
|
||||||
statistics.setTotalElevationGain(50.0);
|
statistics.setTotalElevationGain(50.0f);
|
||||||
statistics2.setTotalElevationGain(850.0); // Result: 850+50
|
statistics2.setTotalElevationGain(850.0f); // Result: 850+50
|
||||||
statistics.setMaxSpeed(60.0); // Resulting max speed
|
statistics.setMaxSpeed(60.0); // Resulting max speed
|
||||||
statistics2.setMaxSpeed(30.0);
|
statistics2.setMaxSpeed(30.0);
|
||||||
statistics.setMaxElevation(1250.0);
|
statistics.setMaxElevation(1250.0);
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ public class AggregatedStatisticsTest {
|
|||||||
statistics.setTotalTime(totalTime);
|
statistics.setTotalTime(totalTime);
|
||||||
statistics.setMovingTime(totalTime);
|
statistics.setMovingTime(totalTime);
|
||||||
statistics.setTotalDistance(totalDistance);
|
statistics.setTotalDistance(totalDistance);
|
||||||
statistics.setTotalElevationGain(50.0);
|
statistics.setTotalElevationGain(50.0f);
|
||||||
statistics.setMaxSpeed(50.0); // Resulting max speed
|
statistics.setMaxSpeed(50.0); // Resulting max speed
|
||||||
statistics.setMaxElevation(1250.0);
|
statistics.setMaxElevation(1250.0);
|
||||||
statistics.setMinElevation(1200.0); // Resulting min elevation
|
statistics.setMinElevation(1200.0); // Resulting min elevation
|
||||||
|
|||||||
@@ -136,7 +136,9 @@ public class DescriptionGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Elevation gain
|
// Elevation gain
|
||||||
writeElevation(stats.getTotalElevationGain(), builder, R.string.description_elevation_gain, lineBreak);
|
if (stats.hasTotalElevationGain()) {
|
||||||
|
writeElevation(stats.getTotalElevationGain(), builder, R.string.description_elevation_gain, lineBreak);
|
||||||
|
}
|
||||||
|
|
||||||
// Recorded time
|
// Recorded time
|
||||||
builder.append(context.getString(R.string.description_recorded_time, StringUtils.formatDateTime(context, stats.getStartTime_ms())));
|
builder.append(context.getString(R.string.description_recorded_time, StringUtils.formatDateTime(context, stats.getStartTime_ms())));
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ public class StatisticsRecordedFragment extends Fragment {
|
|||||||
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
|
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
|
||||||
elevationGroup.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
elevationGroup.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
double elevationGain_m = trackStatistics != null ? trackStatistics.getTotalElevationGain() : 0f;
|
Float elevationGain_m = trackStatistics != null ? trackStatistics.getTotalElevationGain() : null;
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.formatElevation(getContext(), elevationGain_m, metricUnits);
|
Pair<String, String> parts = StringUtils.formatElevation(getContext(), elevationGain_m, metricUnits);
|
||||||
elevationTotalGainValue.setText(parts.first);
|
elevationTotalGainValue.setText(parts.first);
|
||||||
|
|||||||
@@ -481,14 +481,17 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
|
|
||||||
// Set elevation gain
|
// Set elevation gain
|
||||||
private void setTotalElevationGain(Float elevationGain_m) {
|
private void setTotalElevationGain(Float elevationGain_m) {
|
||||||
|
//TODO Check if we can distribute the total elevation gain via trackStatistics instead of doing some computation in the UI layer.
|
||||||
boolean metricUnits = PreferencesUtils.isMetricUnits(getContext());
|
boolean metricUnits = PreferencesUtils.isMetricUnits(getContext());
|
||||||
|
|
||||||
float totalElevationGain = 0;
|
Float totalElevationGain = elevationGain_m;
|
||||||
if (elevationGain_m != null) {
|
|
||||||
totalElevationGain = elevationGain_m;
|
if (lastTrackStatistics != null && lastTrackStatistics.hasTotalElevationGain()) {
|
||||||
}
|
if (elevationGain_m == null) {
|
||||||
if (lastTrackStatistics != null) {
|
totalElevationGain = lastTrackStatistics.getTotalElevationGain();
|
||||||
totalElevationGain += (float) lastTrackStatistics.getTotalElevationGain();
|
} else {
|
||||||
|
totalElevationGain += lastTrackStatistics.getTotalElevationGain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.formatElevation(getContext(), totalElevationGain, metricUnits);
|
Pair<String, String> parts = StringUtils.formatElevation(getContext(), totalElevationGain, metricUnits);
|
||||||
@@ -626,7 +629,7 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
|
|
||||||
if (showElevation) {
|
if (showElevation) {
|
||||||
// Current elevation
|
// Current elevation
|
||||||
double altitude = lastTrackPoint != null && lastTrackPoint.hasAltitude() ? lastTrackPoint.getAltitude() : Double.NaN;
|
Float altitude = lastTrackPoint != null && lastTrackPoint.hasAltitude() ? (float) lastTrackPoint.getAltitude() : null;
|
||||||
Pair<String, String> parts = StringUtils.formatElevation(getContext(), altitude, metricUnits);
|
Pair<String, String> parts = StringUtils.formatElevation(getContext(), altitude, metricUnits);
|
||||||
elevationCurrentValue.setText(parts.first);
|
elevationCurrentValue.setText(parts.first);
|
||||||
elevationCurrentUnit.setText(parts.second);
|
elevationCurrentUnit.setText(parts.second);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package de.dennisguse.opentracks.stats;
|
package de.dennisguse.opentracks.stats;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statistical data about a {@link de.dennisguse.opentracks.content.data.Track}.
|
* Statistical data about a {@link de.dennisguse.opentracks.content.data.Track}.
|
||||||
@@ -24,6 +25,7 @@ import androidx.annotation.NonNull;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
|
//TODO Use null instead of Double.isInfinite
|
||||||
public class TrackStatistics {
|
public class TrackStatistics {
|
||||||
|
|
||||||
// The min and max elevation (meters) seen on this track.
|
// The min and max elevation (meters) seen on this track.
|
||||||
@@ -42,7 +44,7 @@ public class TrackStatistics {
|
|||||||
// The maximum speed (meters/second) that we believe is valid.
|
// The maximum speed (meters/second) that we believe is valid.
|
||||||
private double maxSpeed_mps;
|
private double maxSpeed_mps;
|
||||||
// The total elevation gained (meters).
|
// The total elevation gained (meters).
|
||||||
private double totalElevationGain_m;
|
private Float totalElevationGain_m = null;
|
||||||
|
|
||||||
public TrackStatistics() {
|
public TrackStatistics() {
|
||||||
}
|
}
|
||||||
@@ -80,7 +82,15 @@ public class TrackStatistics {
|
|||||||
elevationExtremities.update(other.elevationExtremities.getMin());
|
elevationExtremities.update(other.elevationExtremities.getMin());
|
||||||
elevationExtremities.update(other.elevationExtremities.getMax());
|
elevationExtremities.update(other.elevationExtremities.getMax());
|
||||||
}
|
}
|
||||||
totalElevationGain_m += other.totalElevationGain_m;
|
if (totalElevationGain_m == null) {
|
||||||
|
if (other.totalElevationGain_m != null) {
|
||||||
|
totalElevationGain_m = other.totalElevationGain_m;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (other.totalElevationGain_m != null) {
|
||||||
|
totalElevationGain_m += other.totalElevationGain_m;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,18 +237,23 @@ public class TrackStatistics {
|
|||||||
elevationExtremities.update(elevation_m);
|
elevationExtremities.update(elevation_m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public boolean hasTotalElevationGain() {
|
||||||
* Gets the total elevation gain in meters.
|
return totalElevationGain_m != null;
|
||||||
*/
|
}
|
||||||
public double getTotalElevationGain() {
|
|
||||||
|
public @Nullable
|
||||||
|
Float getTotalElevationGain() {
|
||||||
return totalElevationGain_m;
|
return totalElevationGain_m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTotalElevationGain(double totalElevationGain_m) {
|
public void setTotalElevationGain(float totalElevationGain_m) {
|
||||||
this.totalElevationGain_m = totalElevationGain_m;
|
this.totalElevationGain_m = totalElevationGain_m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTotalElevationGain(double gain_m) {
|
public void addTotalElevationGain(float gain_m) {
|
||||||
|
if (totalElevationGain_m == null) {
|
||||||
|
totalElevationGain_m = 0f;
|
||||||
|
}
|
||||||
totalElevationGain_m += gain_m;
|
totalElevationGain_m += gain_m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -324,21 +324,21 @@ public class StringUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an elevation value.
|
* Sets an elevation_m value.
|
||||||
*
|
*
|
||||||
* @param context the context
|
* @param context the context
|
||||||
* @param elevation the elevation in meters
|
* @param elevation_m the elevation_m
|
||||||
* @param metricUnits true if metric units
|
* @param metricUnits true if metric units
|
||||||
* @return the formatted elevation (or null) and it's unit as {@link Pair}
|
* @return the formatted elevation_m (or null) and it's unit as {@link Pair}
|
||||||
*/
|
*/
|
||||||
public static Pair<String, String> formatElevation(Context context, double elevation, boolean metricUnits) {
|
public static Pair<String, String> formatElevation(Context context, Float elevation_m, boolean metricUnits) {
|
||||||
String value = context.getString(R.string.value_unknown);
|
String value = context.getString(R.string.value_unknown);
|
||||||
String unit = context.getString(metricUnits ? R.string.unit_meter : R.string.unit_feet);
|
String unit = context.getString(metricUnits ? R.string.unit_meter : R.string.unit_feet);
|
||||||
if (!Double.isNaN(elevation) && !Double.isInfinite(elevation)) {
|
if (elevation_m != null) {
|
||||||
if (!metricUnits) {
|
if (!metricUnits) {
|
||||||
elevation *= UnitConversions.M_TO_FT;
|
elevation_m *= (float) UnitConversions.M_TO_FT;
|
||||||
}
|
}
|
||||||
value = StringUtils.formatDecimal(elevation, 0);
|
value = StringUtils.formatDecimal(elevation_m, 0);
|
||||||
}
|
}
|
||||||
return new Pair<>(value, unit);
|
return new Pair<>(value, unit);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user