From 55fa4d31b89da271ff1f62bc807900d834ec5151 Mon Sep 17 00:00:00 2001 From: Habeeb Dashti Date: Thu, 16 Nov 2023 23:15:48 -0500 Subject: [PATCH] Managing and retrieving the unit system preferences for Temperature unit; #187 - subtask. --- .../opentracks/settings/PreferencesUtils.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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);