Skip to content

Instantly share code, notes, and snippets.

@waseefakhtar
Last active August 29, 2023 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waseefakhtar/61ec7be5ff1a352baf2c1ce954936811 to your computer and use it in GitHub Desktop.
Save waseefakhtar/61ec7be5ff1a352baf2c1ce954936811 to your computer and use it in GitHub Desktop.
private fun validateMedication(
name: String,
dosage: Int,
recurrence: String,
endDate: Long,
morningSelection: Boolean,
afternoonSelection: Boolean,
eveningSelection: Boolean,
nightSelection: Boolean,
onInvalidate: (Int) -> Unit,
onValidate: () -> Unit
) {
if (name.isEmpty()) {
onInvalidate(R.string.medication_name)
return
}
if (dosage < 1) {
onInvalidate(R.string.dosage)
return
}
if (endDate < 1) {
onInvalidate(R.string.end_date)
return
}
if (!morningSelection && !afternoonSelection && !eveningSelection && !nightSelection) {
onInvalidate(R.string.times_of_day)
return
}
val timesOfDay = mutableListOf<TimesOfDay>()
if (morningSelection) timesOfDay.add(TimesOfDay.Morning)
if (afternoonSelection) timesOfDay.add(TimesOfDay.Afternoon)
if (eveningSelection) timesOfDay.add(TimesOfDay.Evening)
if (nightSelection) timesOfDay.add(TimesOfDay.Night)
// TODO: Out of scope for this blog post.
onValidate()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment