I am getting the following warning `Boolean method...
# android
l
I am getting the following warning
Boolean method 'isNotOnMetricSystem' is always inverted
even after I changed to the following.
Copy code
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?
i
can getCounty to be null?
l
i previously had the logic on the left
i have it returning
String
l
i tried this
Copy code
fun 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
    }
}
but i get this warning
same issue here
c
the warning is in the scope of where you call the method. are you using it with
!isNotOnMetricSystem(context)
?
l
thats the thing. i am not negating when I am calling the function. i thinks its a bogus warning. probably a bug in their detection algo.