@@ -21,11 +21,8 @@ import androidx.compose.foundation.text.KeyboardActions
2121import androidx.compose.foundation.text.KeyboardOptions
2222import androidx.compose.material.*
2323import androidx.compose.material.icons.Icons
24- import androidx.compose.material.icons.outlined.Bookmark
25- import androidx.compose.material.icons.outlined.BookmarkAdd
2624import androidx.compose.material.icons.outlined.Clear
2725import androidx.compose.runtime.*
28- import androidx.compose.ui.Alignment
2926import androidx.compose.ui.Modifier
3027import androidx.compose.ui.focus.FocusRequester
3128import androidx.compose.ui.focus.focusRequester
@@ -38,7 +35,6 @@ import androidx.compose.ui.text.input.KeyboardType
3835import androidx.compose.ui.tooling.preview.Preview
3936import androidx.compose.ui.unit.dp
4037import com.mapcode.R
41- import com.mapcode.theme.MapcodeColor
4238import com.mapcode.theme.MapcodeTheme
4339
4440@OptIn(ExperimentalMaterialApi ::class )
@@ -51,88 +47,72 @@ fun AddressArea(
5147 onSubmit : () -> Unit = {},
5248 helper : AddressHelper ,
5349 error : AddressError ,
54- onAddFavouriteClick : () -> Unit = {},
55- onDeleteFavouriteClick : () -> Unit = {},
56- isFavouriteLocation : Boolean
5750) {
5851 Column (modifier) {
5952
6053 var menuExpanded by remember { mutableStateOf(false ) }
6154 val focusRequester = FocusRequester ()
6255 val focusManager = LocalFocusManager .current
6356
64- Row {
65- ExposedDropdownMenuBox (
66- modifier = Modifier .weight(1f ),
67- expanded = menuExpanded,
68- onExpandedChange = { menuExpanded = it }) {
69- OutlinedTextField (
70- modifier = Modifier
71- .fillMaxWidth()
72- .focusRequester(focusRequester),
73- value = address,
74- onValueChange = {
75- onChange(it)
76- if (! menuExpanded) {
77- menuExpanded = true
78- }
79- },
80- singleLine = true ,
81- keyboardOptions = KeyboardOptions (
82- imeAction = ImeAction .Search ,
83- keyboardType = KeyboardType .Text
84- ),
85- keyboardActions = KeyboardActions (onSearch = {
86- menuExpanded = false
87- focusManager.clearFocus()
88- onSubmit()
89- }),
90- label = { Text (stringResource(R .string.address_bar_label), maxLines = 1 ) },
91- placeholder = { Text (address, maxLines = 1 ) },
92- trailingIcon = {
93- if (address.isNotEmpty()) {
94- IconButton (
95- onClick = {
96- focusRequester.requestFocus()
97- onChange(" " )
98- }) {
99- Icon (
100- Icons .Outlined .Clear ,
101- contentDescription = stringResource(R .string.clear_address_content_description)
102- )
103- }
57+ ExposedDropdownMenuBox (
58+ modifier = Modifier .fillMaxWidth(),
59+ expanded = menuExpanded,
60+ onExpandedChange = { menuExpanded = it }) {
61+ OutlinedTextField (
62+ modifier = Modifier
63+ .fillMaxWidth()
64+ .focusRequester(focusRequester),
65+ value = address,
66+ onValueChange = {
67+ onChange(it)
68+ if (! menuExpanded) {
69+ menuExpanded = true
70+ }
71+ },
72+ singleLine = true ,
73+ keyboardOptions = KeyboardOptions (
74+ imeAction = ImeAction .Search ,
75+ keyboardType = KeyboardType .Text
76+ ),
77+ keyboardActions = KeyboardActions (onSearch = {
78+ menuExpanded = false
79+ focusManager.clearFocus()
80+ onSubmit()
81+ }),
82+ label = { Text (stringResource(R .string.address_bar_label), maxLines = 1 ) },
83+ placeholder = { Text (address, maxLines = 1 ) },
84+ trailingIcon = {
85+ if (address.isNotEmpty()) {
86+ IconButton (
87+ onClick = {
88+ focusRequester.requestFocus()
89+ onChange(" " )
90+ }) {
91+ Icon (
92+ Icons .Outlined .Clear ,
93+ contentDescription = stringResource(R .string.clear_address_content_description)
94+ )
10495 }
10596 }
106- )
97+ }
98+ )
10799
108- if (matchingAddresses.isNotEmpty()) {
109- ExposedDropdownMenu (
110- modifier = Modifier .testTag(" address_dropdown" ),
111- expanded = menuExpanded, onDismissRequest = { menuExpanded = false }) {
112- matchingAddresses.forEach { address ->
113- DropdownMenuItem (onClick = {
114- menuExpanded = false
115- focusManager.clearFocus()
116- onChange(address)
117- onSubmit()
118- }) {
119- Text (address)
120- }
100+ if (matchingAddresses.isNotEmpty()) {
101+ ExposedDropdownMenu (
102+ modifier = Modifier .testTag(" address_dropdown" ),
103+ expanded = menuExpanded, onDismissRequest = { menuExpanded = false }) {
104+ matchingAddresses.forEach { address ->
105+ DropdownMenuItem (onClick = {
106+ menuExpanded = false
107+ focusManager.clearFocus()
108+ onChange(address)
109+ onSubmit()
110+ }) {
111+ Text (address)
121112 }
122113 }
123114 }
124115 }
125-
126- Spacer (Modifier .width(8 .dp))
127-
128- FavouriteButton (
129- modifier = Modifier
130- .align(Alignment .CenterVertically )
131- .padding(top = 8 .dp),
132- isFavouriteLocation = isFavouriteLocation,
133- addFavourite = onAddFavouriteClick,
134- deleteFavourite = onDeleteFavouriteClick
135- )
136116 }
137117
138118 val extraTextHeight = 20 .dp
@@ -165,7 +145,6 @@ private fun AddressAreaPreview() {
165145 helper = AddressHelper .None ,
166146 error = AddressError .None ,
167147 matchingAddresses = listOf (" Address 1" , " VERY VERY VERY VERY VERY LONG ADDRESS" ),
168- isFavouriteLocation = true
169148 )
170149 }
171150 }
@@ -231,40 +210,4 @@ private fun HelperText(modifier: Modifier = Modifier, message: String) {
231210 style = MaterialTheme .typography.body1,
232211 fontWeight = FontWeight .Bold
233212 )
234- }
235-
236- @Composable
237- private fun FavouriteButton (
238- modifier : Modifier = Modifier ,
239- isFavouriteLocation : Boolean ,
240- deleteFavourite : () -> Unit ,
241- addFavourite : () -> Unit
242- ) {
243- IconButton (
244- modifier = modifier,
245- onClick = {
246- if (isFavouriteLocation) {
247- deleteFavourite()
248- } else {
249- addFavourite()
250- }
251- }
252- ) {
253- if (isFavouriteLocation) {
254- Icon (
255- modifier = Modifier .size(32 .dp),
256- imageVector = Icons .Outlined .Bookmark ,
257- contentDescription = stringResource(R .string.delete_favourite_button_content_description),
258- tint = MapcodeColor .addFavouritesButton()
259- )
260- } else {
261- Icon (
262- modifier = Modifier .size(32 .dp),
263- imageVector = Icons .Outlined .BookmarkAdd ,
264- contentDescription = stringResource(R .string.add_favourite_button_content_description),
265- tint = MapcodeColor .addFavouritesButton()
266- )
267- }
268- }
269-
270213}
0 commit comments