File tree Expand file tree Collapse file tree 3 files changed +10
-2
lines changed
app/src/main/java/com/android/unio/ui Expand file tree Collapse file tree 3 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -78,13 +78,15 @@ const val DROP_DOWN_MAX_ROWS = 3
78
78
*
79
79
* @param locationSearchViewModel NominatimLocationSearchViewModel : ViewModel for searching
80
80
* locations.
81
+ * @param initialLocation Location? : Initial location to pre-fill the text field.
81
82
* @param textFieldTestTag String : Test tag for the text field.
82
83
* @param dropdownTestTag String : Test tag for the dropdown menu.
83
84
* @param onLocationSelected (Location) -> Unit : Lambda that is called when a location is selected.
84
85
*/
85
86
@Composable
86
87
fun NominatimLocationPicker (
87
88
locationSearchViewModel : NominatimLocationSearchViewModel ,
89
+ initialLocation : Location ? ,
88
90
textFieldTestTag : String ,
89
91
dropdownTestTag : String ,
90
92
onLocationSelected : (Location ) -> Unit
@@ -95,11 +97,14 @@ fun NominatimLocationPicker(
95
97
val locationSuggestions by locationSearchViewModel.locationSuggestions.collectAsState()
96
98
var showDropdown by remember { mutableStateOf(false ) }
97
99
100
+ var shouldDisplayInitialLocation by remember { mutableStateOf(true ) }
101
+
98
102
Box (modifier = Modifier .fillMaxWidth()) {
99
103
OutlinedTextField (
100
- value = locationQuery,
104
+ value = if (shouldDisplayInitialLocation) initialLocation?.name ? : " " else locationQuery,
101
105
onValueChange = {
102
106
locationSearchViewModel.setQuery(it)
107
+ shouldDisplayInitialLocation = false
103
108
showDropdown = true
104
109
},
105
110
label = { Text (context.getString(R .string.event_creation_location_label)) },
Original file line number Diff line number Diff line change @@ -191,6 +191,7 @@ fun EventCreationScreen(
191
191
192
192
NominatimLocationPicker (
193
193
locationSearchViewModel,
194
+ null ,
194
195
EventCreationTestTags .LOCATION ,
195
196
EventCreationTestTags .LOCATION_SUGGESTION_ITEM ) {
196
197
selectedLocation = it
Original file line number Diff line number Diff line change @@ -109,7 +109,8 @@ fun EventEditScreen(
109
109
val initialEndTime = getHHMMInMillisFromTimestamp(eventToEdit.endDate)
110
110
val initialEndDate = eventToEdit.endDate.toDate().time - initialEndTime
111
111
112
- var selectedLocation by remember { mutableStateOf<Location ?>(null ) }
112
+ val initialLocation: Location ? = eventToEdit.location
113
+ var selectedLocation by remember { mutableStateOf<Location ?>(eventToEdit.location) }
113
114
114
115
val eventBannerUri = remember { mutableStateOf<Uri >(eventToEdit.image.toUri()) }
115
116
@@ -221,6 +222,7 @@ fun EventEditScreen(
221
222
222
223
NominatimLocationPicker (
223
224
locationSearchViewModel,
225
+ initialLocation,
224
226
EventEditTestTags .LOCATION ,
225
227
EventEditTestTags .LOCATION_SUGGESTION_ITEM ) {
226
228
selectedLocation = it
You can’t perform that action at this time.
0 commit comments