Your First Kotlin Android App: Polishing the App

Aug 22 2023 · Kotlin 1.8.20, Android 13, Android Studio Flamingo | 2022.2.1

Part 1: Build Out the App

06. Improve the Alert Title

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 05. Keep Track of Game Rounds Next episode: 07. Challenge: Add Bonus Points

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Perfect! You almost had it! Not bad. Are you even trying?


fun alertTitle(): Int {

}
val difference = abs(targetValue - sliderToInt)
//...
val title: Int = if (difference == 0) {
  R.string.alert_title_1
} else if (difference < 5) {
  R.string.alert_title_2
} else if (difference <= 10) {
  R.string.alert_title_3
} else {
  R.string.alert_title_4
}
//...
return title
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
  }
}
ResultDialog(
  dialogTitle = alertTitle(),
  //...
)
@Composable
fun ResultDialog(
  hideDialog: () -> Unit,
  dialogTitle: Int, // New Code
  //...
) {
  //...
    title = { Text(stringResource(id = dialogTitle)) }, // Updated Code
}
fun differenceAmount() = abs(targetValue - sliderToInt)
fun pointsForCurrentRound(): Int {
  //...
  val difference = differenceAmount() // Updated Code
  //...
}

fun alertTitle(): Int {
  val difference = differenceAmount() // Updated Code
  //...
}