Am acest cod:
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")
}
și mă întrebam dacă aș putea să fac cazurile de when
declarație cu un comparator în loc de un întreg. Ceva de genul asta:
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
cufind
. Asta ar face mai mult sens aici.