Skip to content

Commit

Permalink
Merge pull request #314 from SwEnt-Group13/fix/polish-event-fields
Browse files Browse the repository at this point in the history
Add highlighting to missing inputs in Event creation and Event edition
  • Loading branch information
Romainhir authored Dec 18, 2024
2 parents 2c248c9 + 59b8b77 commit 29607cb
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -129,6 +143,7 @@ fun NominatimLocationPicker(
},
onClick = {
locationSearchViewModel.setQuery(location.name)
selectedLocation = location
onLocationSelected(location)
showDropdown = false
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/android/unio/ui/event/EventCreation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions app/src/main/java/com/android/unio/ui/event/EventEdit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)) })

Expand Down Expand Up @@ -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)) })

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@
<string name="event_creation_location_input_label">Entrez une addresse</string>
<string name="event_creation_location_dropdown_points">…</string>
<string name="event_creation_location_dropdown_more">Plus…</string>
<string name="event_creation_name_error">Entrez un nom d\'événement</string>
<string name="event_creation_short_description_error">Entrez une courte description de l\'événement</string>
<string name="event_creation_description_error">Entrez une description de l\'événement</string>

<!-- Event Edit Strings -->
<string name="event_edit_title">Modifier </string>
Expand All @@ -220,6 +223,9 @@
<!-- Event Edit Component Strings -->
<string name="event_edit_date_picker_desc">Sélectionner une date</string>
<string name="event_edit_time_picker_desc">Sélectionner une heure</string>
<string name="event_edit_date_error">La date est manquante</string>
<string name="event_edit_time_error">L\'heure est manquante</string>
<string name="event_edit_location_error">Localisation erronée</string>
<string name="event_edit_toast_more_button">Continuez à taper pour voir plus de résultats</string>

<!-- Associations Overlay Strings -->
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@
<string name="event_creation_location_input_label">Enter an address</string>
<string name="event_creation_location_dropdown_points">…</string>
<string name="event_creation_location_dropdown_more">More…</string>
<string name="event_creation_name_error">Enter an event name</string>
<string name="event_creation_short_description_error">Enter an event short description</string>
<string name="event_creation_description_error">Enter an event description</string>

<!-- Event Edit Strings -->
<string name="event_edit_title">Edit </string>
Expand All @@ -224,6 +227,9 @@
<!-- Event Edit Component Strings -->
<string name="event_edit_date_picker_desc">Select date</string>
<string name="event_edit_time_picker_desc">Select time</string>
<string name="event_edit_date_error">Date is missing</string>
<string name="event_edit_time_error">Time is missing</string>
<string name="event_edit_location_error">Wrong location input</string>
<string name="event_edit_toast_more_button">Continue typing to see more results</string>

<!-- Associations Overlay Strings -->
Expand Down

0 comments on commit 29607cb

Please sign in to comment.