Skip to content

Instantly share code, notes, and snippets.

View waseefakhtar's full-sized avatar
🎯
Focusing

Waseef Akhtar waseefakhtar

🎯
Focusing
View GitHub Profile
private fun validateMedication(
name: String,
dosage: Int,
recurrence: String,
endDate: Long,
morningSelection: Boolean,
afternoonSelection: Boolean,
eveningSelection: Boolean,
nightSelection: Boolean,
onInvalidate: (Int) -> Unit,
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddMedicationScreen() {
// Previously implemented code.
Column(
modifier = Modifier
.padding(16.dp, 16.dp)
.verticalScroll(rememberScrollState()),
private fun showMaxSelectionToast(
numberOfDosage: String,
context: Context
) {
Toast.makeText(
context,
"You're selecting ${(numberOfDosage.toIntOrNull() ?: 0) + 1} time(s) of days which is more than the number of dosage.",
Toast.LENGTH_LONG
).show()
}
private fun handleSelection(
isSelected: Boolean,
selectionCount: Int,
canSelectMoreTimesOfDay: Boolean,
onStateChange: (Int, Boolean) -> Unit,
onShowMaxSelectionError: () -> Unit
) {
if (isSelected) {
onStateChange(selectionCount - 1, !isSelected)
} else {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddMedicationScreen() {
// Previously implemented code.
var isMorningSelected by rememberSaveable { mutableStateOf(false) }
var isAfternoonSelected by rememberSaveable { mutableStateOf(false) }
var isEveningSelected by rememberSaveable { mutableStateOf(false) }
var isNightSelected by rememberSaveable { mutableStateOf(false) }
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EndDateTextField(endDate: (Long) -> Unit) {
Text(
text = stringResource(id = R.string.end_date),
style = MaterialTheme.typography.bodyLarge
)
val interactionSource = remember { MutableInteractionSource() }
val isPressed: Boolean by interactionSource.collectIsPressedAsState()
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddMedicationScreen() {
// Previously implemented.
var endDate by rememberSaveable { mutableStateOf(Date().time) }
Column(
modifier = Modifier
enum class TimesOfDay {
Morning,
Afternoon,
Evening,
Night
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun RecurrenceDropdownMenu(recurrence: (String) -> Unit) {
Column(
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(
text = stringResource(id = R.string.recurrence),
style = MaterialTheme.typography.bodyLarge
)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddMedicationScreen() {
// Previously implememted.
var numberOfDosage by rememberSaveable { mutableStateOf("1") }
var recurrence by rememberSaveable { mutableStateOf(Recurrence.Daily.name) }
Column(
modifier = Modifier
.padding(16.dp, 16.dp)