@@ -21,11 +21,8 @@ import androidx.compose.foundation.text.KeyboardActions
21
21
import androidx.compose.foundation.text.KeyboardOptions
22
22
import androidx.compose.material.*
23
23
import androidx.compose.material.icons.Icons
24
- import androidx.compose.material.icons.outlined.Bookmark
25
- import androidx.compose.material.icons.outlined.BookmarkAdd
26
24
import androidx.compose.material.icons.outlined.Clear
27
25
import androidx.compose.runtime.*
28
- import androidx.compose.ui.Alignment
29
26
import androidx.compose.ui.Modifier
30
27
import androidx.compose.ui.focus.FocusRequester
31
28
import androidx.compose.ui.focus.focusRequester
@@ -38,7 +35,6 @@ import androidx.compose.ui.text.input.KeyboardType
38
35
import androidx.compose.ui.tooling.preview.Preview
39
36
import androidx.compose.ui.unit.dp
40
37
import com.mapcode.R
41
- import com.mapcode.theme.MapcodeColor
42
38
import com.mapcode.theme.MapcodeTheme
43
39
44
40
@OptIn(ExperimentalMaterialApi ::class )
@@ -51,88 +47,72 @@ fun AddressArea(
51
47
onSubmit : () -> Unit = {},
52
48
helper : AddressHelper ,
53
49
error : AddressError ,
54
- onAddFavouriteClick : () -> Unit = {},
55
- onDeleteFavouriteClick : () -> Unit = {},
56
- isFavouriteLocation : Boolean
57
50
) {
58
51
Column (modifier) {
59
52
60
53
var menuExpanded by remember { mutableStateOf(false ) }
61
54
val focusRequester = FocusRequester ()
62
55
val focusManager = LocalFocusManager .current
63
56
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
+ )
104
95
}
105
96
}
106
- )
97
+ }
98
+ )
107
99
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)
121
112
}
122
113
}
123
114
}
124
115
}
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
- )
136
116
}
137
117
138
118
val extraTextHeight = 20 .dp
@@ -165,7 +145,6 @@ private fun AddressAreaPreview() {
165
145
helper = AddressHelper .None ,
166
146
error = AddressError .None ,
167
147
matchingAddresses = listOf (" Address 1" , " VERY VERY VERY VERY VERY LONG ADDRESS" ),
168
- isFavouriteLocation = true
169
148
)
170
149
}
171
150
}
@@ -231,40 +210,4 @@ private fun HelperText(modifier: Modifier = Modifier, message: String) {
231
210
style = MaterialTheme .typography.body1,
232
211
fontWeight = FontWeight .Bold
233
212
)
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
-
270
213
}
0 commit comments