Units: add imperial with meters.

Fixes of #1609.
This commit is contained in:
Dennis Guse
2023-06-15 18:23:50 +02:00
parent 9f1ea4d745
commit eb8d28dfc1
17 changed files with 46 additions and 35 deletions
@@ -3,8 +3,6 @@ package de.dennisguse.opentracks.data.models;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Objects;
import de.dennisguse.opentracks.settings.UnitSystem;
public record Distance(double distance_m) {
@@ -57,7 +55,7 @@ public record Distance(double distance_m) {
public static Distance one(UnitSystem unitSystem) {
return switch (unitSystem) {
case METRIC -> Distance.ofKilometer(1);
case IMPERIAL -> Distance.ofMile(1);
case IMPERIAL_FEET, IMPERIAL_METER -> Distance.ofMile(1);
case NAUTICAL_IMPERIAL -> Distance.ofNauticalMile(1);
};
}
@@ -121,15 +119,15 @@ public record Distance(double distance_m) {
public double toKM_Miles(UnitSystem unitSystem) {
return switch (unitSystem) {
case METRIC -> toKM();
case IMPERIAL -> toMI();
case IMPERIAL_FEET, IMPERIAL_METER -> toMI();
case NAUTICAL_IMPERIAL -> toNauticalMiles();
};
}
public double toM_FT(UnitSystem unitSystem) {
return switch (unitSystem) {
case METRIC -> toM();
case NAUTICAL_IMPERIAL, IMPERIAL -> toFT();
case METRIC, IMPERIAL_METER -> toM();
case NAUTICAL_IMPERIAL, IMPERIAL_FEET -> toFT();
};
}
@@ -47,8 +47,9 @@ public class DistanceFormatter {
if (distance.isInvalid()) {
String valueUnknown = resources.getString(R.string.value_unknown);
return switch (unitSystem) {
case METRIC -> new Pair<>(valueUnknown, resources.getString(R.string.unit_meter));
case IMPERIAL, NAUTICAL_IMPERIAL ->
case METRIC, IMPERIAL_METER ->
new Pair<>(valueUnknown, resources.getString(R.string.unit_meter));
case IMPERIAL_FEET, NAUTICAL_IMPERIAL ->
new Pair<>(valueUnknown, resources.getString(R.string.unit_feet));
};
}
@@ -61,13 +62,20 @@ public class DistanceFormatter {
return new Pair<>(StringUtils.formatDecimal(distance.toM(), decimalCount), resources.getString(R.string.unit_meter));
}
}
case IMPERIAL -> {
case IMPERIAL_FEET -> {
if (distance.greaterThan(Distance.ofMile(threshold))) {
return new Pair<>(StringUtils.formatDecimal(distance.toMI(), decimalCount), resources.getString(R.string.unit_mile));
} else {
return new Pair<>(StringUtils.formatDecimal(distance.toFT(), decimalCount), resources.getString(R.string.unit_feet));
}
}
case IMPERIAL_METER -> {
if (distance.greaterThan(Distance.ofMile(threshold))) {
return new Pair<>(StringUtils.formatDecimal(distance.toMI(), decimalCount), resources.getString(R.string.unit_mile));
} else {
return new Pair<>(StringUtils.formatDecimal(distance.toM(), decimalCount), resources.getString(R.string.unit_meter));
}
}
case NAUTICAL_IMPERIAL -> {
if (distance.greaterThan(Distance.ofNauticalMile(threshold))) {
return new Pair<>(StringUtils.formatDecimal(distance.toNauticalMiles(), decimalCount), resources.getString(R.string.unit_nautical_mile));
@@ -1,9 +1,6 @@
package de.dennisguse.opentracks.data.models;
import androidx.annotation.NonNull;
import java.time.Duration;
import java.util.Objects;
import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.settings.UnitSystem;
@@ -111,7 +108,7 @@ public record Speed(double speed_mps) {
public double to(UnitSystem unitSystem) {
return switch (unitSystem) {
case METRIC -> toKMH();
case IMPERIAL -> toMPH();
case IMPERIAL_FEET, IMPERIAL_METER -> toMPH();
case NAUTICAL_IMPERIAL -> toKnots();
};
}
@@ -42,7 +42,7 @@ public class SpeedFormatter {
int unitId = switch (unitSystem) {
case METRIC ->
reportSpeedOrPace ? R.string.unit_kilometer_per_hour : R.string.unit_minute_per_kilometer;
case IMPERIAL ->
case IMPERIAL_FEET, IMPERIAL_METER ->
reportSpeedOrPace ? R.string.unit_mile_per_hour : R.string.unit_minute_per_mile;
case NAUTICAL_IMPERIAL ->
reportSpeedOrPace ? R.string.unit_knots : R.string.unit_minute_per_nautical_mile;