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
@@ -324,21 +324,21 @@ public class StringUtils {
}
/**
* Sets an elevation value.
* Sets an elevation_m value.
*
* @param context the context
* @param elevation the elevation in meters
* @param elevation_m the elevation_m
* @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 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) {
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);
}