From bb4ef0329fd69bd42a8a46994720198ab4ed3f95 Mon Sep 17 00:00:00 2001 From: flaviuvsp Date: Fri, 2 Aug 2024 15:18:40 +0300 Subject: [PATCH] Add confirmation dialog --- .../compose/EditLocationScreen.kt | 27 ++++++++++++++++--- .../viewmodels/EditLocationViewModel.kt | 14 +++++++--- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditLocationScreen.kt b/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditLocationScreen.kt index 2efd69f4..796f4a6d 100644 --- a/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditLocationScreen.kt +++ b/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditLocationScreen.kt @@ -1,5 +1,6 @@ package org.permanent.permanent.ui.bulkEditMetadata.compose +import CustomDialog import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -64,6 +65,7 @@ fun EditLocationScreen( position = CameraPosition.fromLatLngZoom(viewModel.selectedLocation.value, 12f) } + val openAlertDialog = remember { mutableStateOf(false) } var isSearching by remember { mutableStateOf(false) } val locations by viewModel.locations.observeAsState(emptyList()) @@ -97,9 +99,11 @@ fun EditLocationScreen( GoogleMap( modifier = Modifier.fillMaxSize(), cameraPositionState = cameraPositionState ) { - Marker( - state = MarkerState(position = viewModel.selectedLocation.value) - ) + if (viewModel.selectedLocation.value != viewModel.defaultPosition) { + Marker( + state = MarkerState(position = viewModel.selectedLocation.value) + ) + } } } Column( @@ -198,7 +202,7 @@ fun EditLocationScreen( shape = RoundedCornerShape(0.dp), colors = ButtonDefaults.buttonColors(containerColor = primaryColor), onClick = { - viewModel.updateRecordLocation() + openAlertDialog.value = true }) { if (viewModel.isBusy.value) { CircularProgressIndicator( @@ -218,5 +222,20 @@ fun EditLocationScreen( } } } + when { + openAlertDialog.value -> { + CustomDialog( + title = stringResource(id = R.string.location_confirmation_title), + subtitle = stringResource(id = R.string.location_confirmation_substring), + okButtonText = stringResource(id = R.string.set_location), + cancelButtonText = stringResource(id = R.string.button_cancel), + onConfirm = { + openAlertDialog.value = false + viewModel.updateRecordLocation() + }) { + openAlertDialog.value = false + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/org/permanent/permanent/viewmodels/EditLocationViewModel.kt b/app/src/main/java/org/permanent/permanent/viewmodels/EditLocationViewModel.kt index d2aa993e..4f6d561f 100644 --- a/app/src/main/java/org/permanent/permanent/viewmodels/EditLocationViewModel.kt +++ b/app/src/main/java/org/permanent/permanent/viewmodels/EditLocationViewModel.kt @@ -41,7 +41,8 @@ class EditLocationViewModel(application: Application) : ObservableAndroidViewMod private val onLocationChanged = MutableLiveData() val locations: LiveData> get() = _locations - private val _selectedLocation = mutableStateOf(LatLng(1.35, 103.87)) + val defaultPosition = LatLng(38.8938592, -77.0969767) + private val _selectedLocation = mutableStateOf(defaultPosition) val selectedLocation: State get() = _selectedLocation var searchText: MutableState = mutableStateOf("") var isBusy: MutableState = mutableStateOf(false) @@ -50,9 +51,14 @@ class EditLocationViewModel(application: Application) : ObservableAndroidViewMod fun setRecords(records: ArrayList) { this.records.addAll(records) - records.firstOrNull()?.fileData?.let { - _selectedLocation.value = LatLng(it.latitude, it.longitude) - requestLocation(_selectedLocation.value) + records.forEach { record -> + record.fileData?.let { + if( it.latitude != -1.0) { + _selectedLocation.value = LatLng(it.latitude, it.longitude) + requestLocation(_selectedLocation.value) + return@forEach + } + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ba0474de..4d385405 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -730,5 +730,7 @@ Set Location Add Location Various locations + New location + Are you sure you want set a new location for selected items?