Hello, how do I write a when clause for density ra...
# android
n
Hello, how do I write a when clause for density range? I don’t want to hardcode magic numbers
Copy code
val scale = when (Resources.getSystem().displayMetrics.densityDpi) {
    DENSITY_MEDIUM -> 1
    ...
    else -> 1
}
above works but below not
Copy code
val scale = when (Resources.getSystem().displayMetrics.densityDpi) {
    DENSITY_LOW..DENSITY_MEDIUM -> 1 -> // compile error
    ...
    else -> 1
}
It gives
Incompatible types: IntRange and Int
1
l
To check if the value is in a range:
in DENSITY_LOW..DENSITY_MEDIUM -> ...
n
damn how I missed that lol thank you!