Skip to content

Commit fe5fd0a

Browse files
committed
feat(event-edit): add initial location to LocationPicker and change screens accordingly
1 parent f9489f7 commit fe5fd0a

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

app/src/main/java/com/android/unio/ui/components/EventEditComponents.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ const val DROP_DOWN_MAX_ROWS = 3
7878
*
7979
* @param locationSearchViewModel NominatimLocationSearchViewModel : ViewModel for searching
8080
* locations.
81+
* @param initialLocation Location? : Initial location to pre-fill the text field.
8182
* @param textFieldTestTag String : Test tag for the text field.
8283
* @param dropdownTestTag String : Test tag for the dropdown menu.
8384
* @param onLocationSelected (Location) -> Unit : Lambda that is called when a location is selected.
8485
*/
8586
@Composable
8687
fun NominatimLocationPicker(
8788
locationSearchViewModel: NominatimLocationSearchViewModel,
89+
initialLocation: Location?,
8890
textFieldTestTag: String,
8991
dropdownTestTag: String,
9092
onLocationSelected: (Location) -> Unit
@@ -95,11 +97,14 @@ fun NominatimLocationPicker(
9597
val locationSuggestions by locationSearchViewModel.locationSuggestions.collectAsState()
9698
var showDropdown by remember { mutableStateOf(false) }
9799

100+
var shouldDisplayInitialLocation by remember { mutableStateOf(true) }
101+
98102
Box(modifier = Modifier.fillMaxWidth()) {
99103
OutlinedTextField(
100-
value = locationQuery,
104+
value = if (shouldDisplayInitialLocation) initialLocation?.name ?: "" else locationQuery,
101105
onValueChange = {
102106
locationSearchViewModel.setQuery(it)
107+
shouldDisplayInitialLocation = false
103108
showDropdown = true
104109
},
105110
label = { Text(context.getString(R.string.event_creation_location_label)) },

app/src/main/java/com/android/unio/ui/event/EventCreation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ fun EventCreationScreen(
191191

192192
NominatimLocationPicker(
193193
locationSearchViewModel,
194+
null,
194195
EventCreationTestTags.LOCATION,
195196
EventCreationTestTags.LOCATION_SUGGESTION_ITEM) {
196197
selectedLocation = it

app/src/main/java/com/android/unio/ui/event/EventEdit.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ fun EventEditScreen(
109109
val initialEndTime = getHHMMInMillisFromTimestamp(eventToEdit.endDate)
110110
val initialEndDate = eventToEdit.endDate.toDate().time - initialEndTime
111111

112-
var selectedLocation by remember { mutableStateOf<Location?>(null) }
112+
val initialLocation: Location? = eventToEdit.location
113+
var selectedLocation by remember { mutableStateOf<Location?>(eventToEdit.location) }
113114

114115
val eventBannerUri = remember { mutableStateOf<Uri>(eventToEdit.image.toUri()) }
115116

@@ -221,6 +222,7 @@ fun EventEditScreen(
221222

222223
NominatimLocationPicker(
223224
locationSearchViewModel,
225+
initialLocation,
224226
EventEditTestTags.LOCATION,
225227
EventEditTestTags.LOCATION_SUGGESTION_ITEM) {
226228
selectedLocation = it

0 commit comments

Comments
 (0)