Eu tenho este código:
statisticsSettings = when (ScreenHandler.convertPixelsToDp(width, context).toInt()){
320 -> StatisticsSettings.SMALL_PHONE
480 -> StatisticsSettings.LARGE_PHONE
600 -> StatisticsSettings.SMALL_TABLET
720 -> StatisticsSettings.LARGE_TABLET
else -> throw IllegalArgumentException("Cannot compute dp")
}
e eu estava imaginando se eu poderia fazer casos de when
instrução com um comparador em vez de um número inteiro. Algo como isto:
statisticsSettings = when (ScreenHandler.convertPixelsToDp(width, context).toInt()){
ScreenHandler.convertPixelsToDp(width, context).toInt()) < 320 -> StatisticsSettings.SMALL_PHONE
ScreenHandler.convertPixelsToDp(width, context).toInt()) < 480 -> StatisticsSettings.LARGE_PHONE
ScreenHandler.convertPixelsToDp(width, context).toInt()) < 600 -> StatisticsSettings.SMALL_TABLET
ScreenHandler.convertPixelsToDp(width, context).toInt()) < 720 -> StatisticsSettings.LARGE_TABLET
else -> throw IllegalArgumentException("Cannot compute dp")
}
filter
comfind
. Que faria mais sentido aqui.