Skip to content

Instantly share code, notes, and snippets.

@waseefakhtar
Created August 29, 2023 22:05
Show Gist options
  • Save waseefakhtar/2f8bbfebea346dc6ec4d304dfcb8ba0c to your computer and use it in GitHub Desktop.
Save waseefakhtar/2f8bbfebea346dc6ec4d304dfcb8ba0c to your computer and use it in GitHub Desktop.
private fun handleSelection(
isSelected: Boolean,
selectionCount: Int,
canSelectMoreTimesOfDay: Boolean,
onStateChange: (Int, Boolean) -> Unit,
onShowMaxSelectionError: () -> Unit
) {
if (isSelected) {
onStateChange(selectionCount - 1, !isSelected)
} else {
if (canSelectMoreTimesOfDay) {
onStateChange(selectionCount + 1, !isSelected)
} else {
onShowMaxSelectionError()
}
}
}
private fun canSelectMoreTimesOfDay(selectionCount: Int, numberOfDosage: Int): Boolean {
return selectionCount < numberOfDosage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment