diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt index ef8d78d..ae1ae89 100755 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt @@ -2,7 +2,10 @@ package com.tommasoberlose.anotherwidget.global import android.os.Build import androidx.appcompat.app.AppCompatDelegate.* +import androidx.core.os.ConfigurationCompat import com.chibatching.kotpref.KotprefModel +import com.tommasoberlose.anotherwidget.utils.isMetric +import java.util.* object Preferences : KotprefModel() { override val commitAllPropertiesByDefault: Boolean = true @@ -14,8 +17,8 @@ object Preferences : KotprefModel() { var showWeather by booleanPref(key = "PREF_SHOW_WEATHER", default = false) var weatherIcon by stringPref(key = "PREF_WEATHER_ICON", default = "") var weatherTemp by floatPref(key = "PREF_WEATHER_TEMP", default = 0f) - var weatherTempUnit by stringPref(key = "PREF_WEATHER_TEMP_UNIT", default = "F") - var weatherRealTempUnit by stringPref(key = "PREF_WEATHER_REAL_TEMP_UNIT", default = "F") + var weatherTempUnit by stringPref(key = "PREF_WEATHER_TEMP_UNIT", default = if (ConfigurationCompat.getLocales(context.resources.configuration)[0].isMetric()) "C" else "F") + var weatherRealTempUnit by stringPref(key = "PREF_WEATHER_REAL_TEMP_UNIT", default = if (ConfigurationCompat.getLocales(context.resources.configuration)[0].isMetric()) "C" else "F") var calendarAllDay by booleanPref(key = "PREF_CALENDAR_ALL_DAY", default = true) var calendarFilter by stringPref(key = "PREF_CALENDAR_FILTER", default = "") @@ -43,7 +46,7 @@ object Preferences : KotprefModel() { var weatherProviderApiWeatherApi by stringPref(default = "") var weatherProviderApiWeatherBit by stringPref(default = "") var weatherProviderApiAccuweather by stringPref(default = "") - var weatherProvider by intPref(default = Constants.WeatherProvider.OPEN_WEATHER.value) + var weatherProvider by intPref(default = if (ConfigurationCompat.getLocales(context.resources.configuration)[0].isMetric()) Constants.WeatherProvider.YR.value else Constants.WeatherProvider.WEATHER_GOV.value) var weatherProviderError by stringPref(default = "") var weatherProviderLocationError by stringPref(default = "") var eventAppName by stringPref(key = "PREF_EVENT_APP_NAME", default = "") diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/utils/Extensions.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/utils/Extensions.kt index 750655b..fa78156 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/utils/Extensions.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/utils/Extensions.kt @@ -257,4 +257,11 @@ fun Intent.isDefaultSet(context: Context): Boolean { } catch (ex: java.lang.Exception) { false } +} + +fun Locale.isMetric(): Boolean { + return when (country.toUpperCase(this)) { + "US", "LR", "MM", "GB" -> false + else -> true + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dde1815..c81498e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -164,7 +164,7 @@ location-access Background service Service used to update the weather based on the current location of the user. - Weather update + Updating the weather… We\'re updating the weather based on your current location.