@@ -8,6 +8,7 @@ import androidx.annotation.DrawableRes
88import androidx.compose.foundation.ExperimentalFoundationApi
99import androidx.compose.foundation.clickable
1010import androidx.compose.foundation.layout.*
11+ import androidx.compose.foundation.text.ClickableText
1112import androidx.compose.foundation.text.KeyboardActions
1213import androidx.compose.foundation.text.KeyboardOptions
1314import androidx.compose.material.*
@@ -19,6 +20,7 @@ import androidx.compose.ui.focus.FocusRequester
1920import androidx.compose.ui.focus.focusRequester
2021import androidx.compose.ui.focus.onFocusChanged
2122import androidx.compose.ui.platform.LocalFocusManager
23+ import androidx.compose.ui.platform.testTag
2224import androidx.compose.ui.res.painterResource
2325import androidx.compose.ui.res.stringResource
2426import androidx.compose.ui.text.SpanStyle
@@ -32,27 +34,29 @@ import androidx.compose.ui.tooling.preview.Preview
3234import androidx.compose.ui.unit.dp
3335import com.mapcode.R
3436import com.mapcode.theme.MapcodeTheme
35- import kotlinx.coroutines.launch
3637
3738@Composable
3839fun InfoArea (
3940 modifier : Modifier ,
4041 viewModel : MapViewModel ,
41- scaffoldState : ScaffoldState ,
42+ showSnackbar : ( String ) -> Unit ,
4243 isVerticalLayout : Boolean
4344) {
4445 val uiState by viewModel.uiState.collectAsState()
45- val scope = rememberCoroutineScope()
4646 val copiedMessageStr = stringResource(R .string.copied_to_clipboard_snackbar_text)
4747 val onMapcodeClick = remember {
4848 {
4949 val copied = viewModel.copyMapcode()
5050 if (copied && Build .VERSION .SDK_INT <= Build .VERSION_CODES .S_V2 ) {
51- scope.launch {
52- // dismiss current snack bar so they aren't queued up
53- scaffoldState.snackbarHostState.currentSnackbarData?.dismiss()
54- scaffoldState.snackbarHostState.showSnackbar(copiedMessageStr)
55- }
51+ showSnackbar(copiedMessageStr)
52+ }
53+ }
54+ }
55+ val onLocationClick = remember {
56+ {
57+ viewModel.copyLocation()
58+ if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .S_V2 ) {
59+ showSnackbar(copiedMessageStr)
5660 }
5761 }
5862 }
@@ -66,8 +70,10 @@ fun InfoArea(
6670 onTerritoryClick = viewModel::onTerritoryClick,
6771 onChangeLatitude = viewModel::onLatitudeTextChanged,
6872 onSubmitLatitude = viewModel::onSubmitLatitude,
73+ onCopyLatitude = onLocationClick,
6974 onChangeLongitude = viewModel::onLongitudeTextChanged,
7075 onSubmitLongitude = viewModel::onSubmitLongitude,
76+ onCopyLongitude = onLocationClick,
7177 isVerticalLayout = isVerticalLayout
7278 )
7379}
@@ -80,8 +86,10 @@ private fun InfoArea(
8086 onSubmitAddress : () -> Unit = {},
8187 onChangeLatitude : (String ) -> Unit = {},
8288 onSubmitLatitude : () -> Unit = {},
89+ onCopyLatitude : () -> Unit = {},
8390 onChangeLongitude : (String ) -> Unit = {},
8491 onSubmitLongitude : () -> Unit = {},
92+ onCopyLongitude : () -> Unit = {},
8593 onTerritoryClick : () -> Unit = {},
8694 onMapcodeClick : () -> Unit = {},
8795 isVerticalLayout : Boolean
@@ -94,8 +102,10 @@ private fun InfoArea(
94102 onSubmitAddress,
95103 onChangeLatitude,
96104 onSubmitLatitude,
105+ onCopyLatitude,
97106 onChangeLongitude,
98107 onSubmitLongitude,
108+ onCopyLongitude,
99109 onTerritoryClick,
100110 onMapcodeClick
101111 )
@@ -107,8 +117,10 @@ private fun InfoArea(
107117 onSubmitAddress,
108118 onChangeLatitude,
109119 onSubmitLatitude,
120+ onCopyLatitude,
110121 onChangeLongitude,
111122 onSubmitLongitude,
123+ onCopyLongitude,
112124 onTerritoryClick,
113125 onMapcodeClick
114126 )
@@ -141,8 +153,10 @@ private fun VerticalInfoArea(
141153 onSubmitAddress : () -> Unit ,
142154 onChangeLatitude : (String ) -> Unit ,
143155 onSubmitLatitude : () -> Unit ,
156+ onCopyLatitude : () -> Unit ,
144157 onChangeLongitude : (String ) -> Unit ,
145158 onSubmitLongitude : () -> Unit ,
159+ onCopyLongitude : () -> Unit ,
146160 onTerritoryClick : () -> Unit ,
147161 onMapcodeClick : () -> Unit
148162) {
@@ -181,6 +195,7 @@ private fun VerticalInfoArea(
181195 showInvalidError = state.locationUi.showLatitudeInvalidError,
182196 onSubmit = onSubmitLatitude,
183197 onChange = onChangeLatitude,
198+ onCopy = onCopyLatitude
184199 )
185200 Spacer (Modifier .height(8 .dp))
186201 LongitudeTextBox (
@@ -190,6 +205,7 @@ private fun VerticalInfoArea(
190205 showInvalidError = state.locationUi.showLongitudeInvalidError,
191206 onSubmit = onSubmitLongitude,
192207 onChange = onChangeLongitude,
208+ onCopy = onCopyLongitude
193209 )
194210 }
195211}
@@ -202,8 +218,10 @@ private fun HorizontalInfoArea(
202218 onSubmitAddress : () -> Unit ,
203219 onChangeLatitude : (String ) -> Unit ,
204220 onSubmitLatitude : () -> Unit ,
221+ onCopyLatitude : () -> Unit ,
205222 onChangeLongitude : (String ) -> Unit ,
206223 onSubmitLongitude : () -> Unit ,
224+ onCopyLongitude : () -> Unit ,
207225 onTerritoryClick : () -> Unit ,
208226 onMapcodeClick : () -> Unit
209227) {
@@ -248,6 +266,7 @@ private fun HorizontalInfoArea(
248266 showInvalidError = state.locationUi.showLatitudeInvalidError,
249267 onSubmit = onSubmitLatitude,
250268 onChange = onChangeLatitude,
269+ onCopy = onCopyLatitude
251270 )
252271 LongitudeTextBox (
253272 modifier = Modifier
@@ -259,6 +278,7 @@ private fun HorizontalInfoArea(
259278 showInvalidError = state.locationUi.showLongitudeInvalidError,
260279 onSubmit = onSubmitLongitude,
261280 onChange = onChangeLongitude,
281+ onCopy = onCopyLongitude
262282 )
263283 }
264284 }
@@ -302,7 +322,8 @@ private fun LatitudeTextBox(
302322 placeHolder : String ,
303323 showInvalidError : Boolean ,
304324 onSubmit : () -> Unit ,
305- onChange : (String ) -> Unit
325+ onChange : (String ) -> Unit ,
326+ onCopy : () -> Unit
306327) {
307328 LatLngTextField (
308329 modifier = modifier,
@@ -312,7 +333,8 @@ private fun LatitudeTextBox(
312333 label = stringResource(R .string.latitude_text_field_label),
313334 clearButtonContentDescription = stringResource(R .string.clear_latitude_content_description),
314335 onSubmit = onSubmit,
315- onChange = onChange
336+ onChange = onChange,
337+ onCopy = onCopy
316338 )
317339}
318340
@@ -326,7 +348,8 @@ private fun LongitudeTextBox(
326348 placeHolder : String ,
327349 showInvalidError : Boolean ,
328350 onSubmit : () -> Unit ,
329- onChange : (String ) -> Unit
351+ onChange : (String ) -> Unit ,
352+ onCopy : () -> Unit
330353) {
331354 LatLngTextField (
332355 modifier = modifier,
@@ -336,7 +359,8 @@ private fun LongitudeTextBox(
336359 label = stringResource(R .string.longitude_text_field_label),
337360 clearButtonContentDescription = stringResource(R .string.clear_longitude_content_description),
338361 onSubmit = onSubmit,
339- onChange = onChange
362+ onChange = onChange,
363+ onCopy = onCopy
340364 )
341365}
342366
@@ -350,7 +374,8 @@ private fun LatLngTextField(
350374 label : String ,
351375 clearButtonContentDescription : String ,
352376 onSubmit : () -> Unit ,
353- onChange : (String ) -> Unit
377+ onChange : (String ) -> Unit ,
378+ onCopy : () -> Unit
354379) {
355380 Column (modifier) {
356381 val focusManager = LocalFocusManager .current
@@ -379,7 +404,14 @@ private fun LatLngTextField(
379404 .fillMaxWidth(),
380405 value = textValue,
381406 singleLine = true ,
382- label = { Text (label, maxLines = 1 ) },
407+ label = {
408+ ClickableText (
409+ modifier = Modifier .testTag(" latlngtextfield" ),
410+ text = buildAnnotatedString { append(label) },
411+ maxLines = 1 ,
412+ onClick = { onCopy() }
413+ )
414+ },
383415 onValueChange = { value ->
384416 textSelection = value.selection
385417 onChange(value.text)
0 commit comments