lawlorslaw
04/08/2023, 3:41 AMBoolean method 'isNotOnMetricSystem' is always inverted
even after I changed to the following.
fun isNotOnMetricSystem(context: Context): Boolean {
val country = getCountry(context)
return country == context.getString(R.string.united_states_region_code)
}
i previously had the inverse logic but that same warning. What do i have to change to in order to resolve the warning message?itnoles
04/08/2023, 4:18 AMlawlorslaw
04/08/2023, 4:19 AMlawlorslaw
04/08/2023, 4:20 AMString
itnoles
04/08/2023, 4:23 AMlawlorslaw
04/08/2023, 4:42 AMfun getDistanceUnit(context: Context): DistanceUnit {
val preferences = getSharedPreferences(context)
val isOnImperialSystem = LocaleUtility.isOnImperialSystem(context)
val defaultDistanceUnit =
if (isOnImperialSystem) DistanceUnit.MILES else DistanceUnit.KILOMETERS
return DistanceUnit.valueOf(
preferences.getString(
KEY_DISTANCE_UNIT,
defaultDistanceUnit.toString()
)!!
)
}
object LocaleUtility {
fun isOnImperialSystem(context: Context): Boolean {
val country = getCountry(context)
return country == context.getString(R.string.united_states_region_code)
}
private fun getCountry(context: Context): String {
val currentLocale = context.resources.configuration.locales.get(0)
return currentLocale.country
}
}
lawlorslaw
04/08/2023, 4:43 AMlawlorslaw
04/08/2023, 4:48 AMChrimaeon
04/08/2023, 11:15 AM!isNotOnMetricSystem(context)
?lawlorslaw
04/09/2023, 6:25 AM