diff --git a/app/src/main/java/com/android/unio/ui/components/EventEditComponents.kt b/app/src/main/java/com/android/unio/ui/components/EventEditComponents.kt index d16f74fc3..424dbd2bc 100644 --- a/app/src/main/java/com/android/unio/ui/components/EventEditComponents.kt +++ b/app/src/main/java/com/android/unio/ui/components/EventEditComponents.kt @@ -41,6 +41,7 @@ import androidx.compose.material3.rememberTimePickerState import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -97,15 +98,28 @@ fun NominatimLocationPicker( var showDropdown by remember { mutableStateOf(false) } var shouldDisplayInitialLocation by remember { mutableStateOf(true) } + var selectedLocation by remember { mutableStateOf(initialLocation) } + val isError by remember { + derivedStateOf { + selectedLocation == null || selectedLocation!!.name.isEmpty() && locationQuery.isEmpty() + } + } Box(modifier = Modifier.fillMaxWidth()) { OutlinedTextField( value = if (shouldDisplayInitialLocation) initialLocation?.name ?: "" else locationQuery, onValueChange = { locationSearchViewModel.setQuery(it) + selectedLocation = null shouldDisplayInitialLocation = false showDropdown = true }, + isError = isError, + supportingText = { + if (isError) { + Text(context.getString(R.string.event_edit_location_error)) + } + }, label = { Text(context.getString(R.string.event_creation_location_label)) }, placeholder = { Text(context.getString(R.string.event_creation_location_input_label)) }, modifier = Modifier.fillMaxWidth().testTag(textFieldTestTag)) @@ -129,6 +143,7 @@ fun NominatimLocationPicker( }, onClick = { locationSearchViewModel.setQuery(location.name) + selectedLocation = location onLocationSelected(location) showDropdown = false }, @@ -271,6 +286,12 @@ fun DateAndTimePicker( ?: "", readOnly = true, onValueChange = {}, + isError = selectedDate == null && initialDate == null, + supportingText = { + if (selectedDate == null && initialDate == null) { + Text(context.getString(R.string.event_edit_date_error)) + } + }, trailingIcon = { Icon( Icons.Default.DateRange, @@ -299,6 +320,12 @@ fun DateAndTimePicker( ?: "", readOnly = true, onValueChange = {}, + isError = selectedTime == null && initialTime == null, + supportingText = { + if (selectedTime == null && initialTime == null) { + Text(context.getString(R.string.event_edit_time_error)) + } + }, trailingIcon = { Icon( Icons.Default.AccessTime, diff --git a/app/src/main/java/com/android/unio/ui/event/EventCreation.kt b/app/src/main/java/com/android/unio/ui/event/EventCreation.kt index a6f1c2ba7..cad4d1ded 100644 --- a/app/src/main/java/com/android/unio/ui/event/EventCreation.kt +++ b/app/src/main/java/com/android/unio/ui/event/EventCreation.kt @@ -119,6 +119,12 @@ fun EventCreationScreen( OutlinedTextField( modifier = Modifier.fillMaxWidth().testTag(EventCreationTestTags.EVENT_TITLE), value = name, + isError = name.isEmpty(), + supportingText = { + if (name.isEmpty()) { + Text(context.getString(R.string.event_creation_name_error)) + } + }, onValueChange = { if (Utils.checkInputLength(it, TextLength.SMALL)) { name = it @@ -144,6 +150,12 @@ fun EventCreationScreen( OutlinedTextField( modifier = Modifier.fillMaxWidth().testTag(EventCreationTestTags.SHORT_DESCRIPTION), value = shortDescription, + isError = shortDescription.isEmpty(), + supportingText = { + if (shortDescription.isEmpty()) { + Text(context.getString(R.string.event_creation_short_description_error)) + } + }, onValueChange = { if (Utils.checkInputLength(it, TextLength.MEDIUM)) { shortDescription = it @@ -197,6 +209,12 @@ fun EventCreationScreen( OutlinedTextField( modifier = Modifier.fillMaxWidth().testTag(EventCreationTestTags.DESCRIPTION), value = longDescription, + isError = longDescription.isEmpty(), + supportingText = { + if (longDescription.isEmpty()) { + Text(context.getString(R.string.event_creation_description_error)) + } + }, onValueChange = { if (Utils.checkInputLength(it, TextLength.LARGE)) { longDescription = it diff --git a/app/src/main/java/com/android/unio/ui/event/EventEdit.kt b/app/src/main/java/com/android/unio/ui/event/EventEdit.kt index 7f26a2afb..e76a4ad7c 100644 --- a/app/src/main/java/com/android/unio/ui/event/EventEdit.kt +++ b/app/src/main/java/com/android/unio/ui/event/EventEdit.kt @@ -83,9 +83,9 @@ fun EventEditScreen( val eventToEdit = remember { eventViewModel.selectedEvent.value!! } - var name by remember { mutableStateOf(eventToEdit.title) } - var shortDescription by remember { mutableStateOf(eventToEdit.catchyDescription) } - var longDescription by remember { mutableStateOf(eventToEdit.description) } + var name by remember { mutableStateOf(eventToEdit.title.trim()) } + var shortDescription by remember { mutableStateOf(eventToEdit.catchyDescription.trim()) } + var longDescription by remember { mutableStateOf(eventToEdit.description.trim()) } var coauthorsAndBoolean = associationViewModel.associations.collectAsState().value.map { @@ -139,12 +139,24 @@ fun EventEditScreen( OutlinedTextField( modifier = Modifier.fillMaxWidth().testTag(EventEditTestTags.EVENT_TITLE), value = name, + isError = name.isEmpty(), + supportingText = { + if (name.isEmpty()) { + Text(context.getString(R.string.event_creation_name_error)) + } + }, onValueChange = { name = it }, label = { Text(context.getString(R.string.event_creation_name_label)) }) OutlinedTextField( modifier = Modifier.fillMaxWidth().testTag(EventEditTestTags.SHORT_DESCRIPTION), value = shortDescription, + isError = shortDescription.isEmpty(), + supportingText = { + if (shortDescription.isEmpty()) { + Text(context.getString(R.string.event_creation_short_description_error)) + } + }, onValueChange = { shortDescription = it }, label = { Text(context.getString(R.string.event_creation_short_description_label)) }) @@ -178,6 +190,12 @@ fun EventEditScreen( OutlinedTextField( modifier = Modifier.fillMaxWidth().testTag(EventEditTestTags.DESCRIPTION), value = longDescription, + isError = longDescription.isEmpty(), + supportingText = { + if (longDescription.isEmpty()) { + Text(context.getString(R.string.event_creation_description_error)) + } + }, onValueChange = { longDescription = it }, label = { Text(context.getString(R.string.event_creation_description_label)) }) diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index f25249eaa..4a73650a3 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -210,6 +210,9 @@ Entrez une addresse Plus… + Entrez un nom d\'événement + Entrez une courte description de l\'événement + Entrez une description de l\'événement Modifier @@ -220,6 +223,9 @@ Sélectionner une date Sélectionner une heure + La date est manquante + L\'heure est manquante + Localisation erronée Continuez à taper pour voir plus de résultats diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4926a2889..5f70620c5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -214,6 +214,9 @@ Enter an address More… + Enter an event name + Enter an event short description + Enter an event description Edit @@ -224,6 +227,9 @@ Select date Select time + Date is missing + Time is missing + Wrong location input Continue typing to see more results