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:
Dennis Guse
2020-09-05 12:36:12 +02:00
parent 6845ce4984
commit 5099118dd7
8 changed files with 48 additions and 28 deletions
@@ -284,7 +284,7 @@ public class StatisticsRecordedFragment extends Fragment {
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
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);
elevationTotalGainValue.setText(parts.first);
@@ -481,14 +481,17 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
// Set elevation gain
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());
float totalElevationGain = 0;
if (elevationGain_m != null) {
totalElevationGain = elevationGain_m;
}
if (lastTrackStatistics != null) {
totalElevationGain += (float) lastTrackStatistics.getTotalElevationGain();
Float totalElevationGain = elevationGain_m;
if (lastTrackStatistics != null && lastTrackStatistics.hasTotalElevationGain()) {
if (elevationGain_m == null) {
totalElevationGain = lastTrackStatistics.getTotalElevationGain();
} else {
totalElevationGain += lastTrackStatistics.getTotalElevationGain();
}
}
Pair<String, String> parts = StringUtils.formatElevation(getContext(), totalElevationGain, metricUnits);
@@ -626,7 +629,7 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
if (showElevation) {
// 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);
elevationCurrentValue.setText(parts.first);
elevationCurrentUnit.setText(parts.second);