Last active
August 29, 2023 22:31
-
-
Save waseefakhtar/61ec7be5ff1a352baf2c1ce954936811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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