diff --git a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java index e0303a261..bec231152 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java +++ b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java @@ -233,7 +233,19 @@ public static void applyDefaultUnit() { } } } + public static TemperatureUnit getTemperatureUnit() { + final String TEMPERATURE_UNIT_DEFAULT = resources.getString(R.string.temperature_unit_default); + final String VALUE = getString(R.string.temperature_unit_key, TEMPERATURE_UNIT_DEFAULT); + return Arrays.stream(TemperatureUnit.values()) + .filter(d -> VALUE.equals(resources.getString(d.getPreferenceId(), TEMPERATURE_UNIT_DEFAULT))) + .findFirst() + .orElse(TemperatureUnit.defaultTemperatureUnit()); + } + + public static void setTemperatureUnit(TemperatureUnit temperatureUnit) { + setString(R.string.temperature_unit_key, temperatureUnit.getPreferenceId()); + } public static boolean isReportSpeed(String activityTypeLocalized) { final String STATS_RATE_DEFAULT = resources.getString(R.string.stats_rate_default); String currentStatsRate = getString(R.string.stats_rate_key, STATS_RATE_DEFAULT);