I’ve been going thru the Your First Kotlin Android App: Polishing the App
You can add parameters to the @Preview for changing the size of the preview device.
fun pointsForCurrentRound(): Int {
return when (val diff = abs( targetValue - sliderToInt )) {
0 -> { 200 }
1 -> { 149 }
2 -> { 123 }
else -> { min(100, 100 - diff) }
}
}
fun alertTitle(): Int {
val difference = abs(targetValue - sliderToInt)
val title: Int = when {
difference == 0 -> {
R.string.alert_title_1
}
difference < 5 -> {
R.string.alert_title_2
}
difference <= 10 -> {
R.string.alert_title_3
}
else -> {
R.string.alert_title_4
}
}
return title
}
The switch statement from most things, can be handled using a when.
The structure window helps you jumping between sections of code.