Skip to content

Commit

Permalink
Merge pull request #287 from PermanentOrg/feature/VSP-944-Fix-Comment…
Browse files Browse the repository at this point in the history
…-On-PR

Add confirmation dialog
  • Loading branch information
flaviuvsp authored Aug 6, 2024
2 parents 06992ad + bb4ef03 commit 4aced56
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class EditLocationViewModel(application: Application) : ObservableAndroidViewMod

private val onLocationChanged = MutableLiveData<String>()
val locations: LiveData<List<AutocompletePrediction>> 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<LatLng> get() = _selectedLocation
var searchText: MutableState<String> = mutableStateOf("")
var isBusy: MutableState<Boolean> = mutableStateOf(false)
Expand All @@ -50,9 +51,14 @@ class EditLocationViewModel(application: Application) : ObservableAndroidViewMod

fun setRecords(records: ArrayList<Record>) {
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
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -730,5 +730,7 @@
<string name="set_location">Set Location</string>
<string name="add_location">Add Location</string>
<string name="various_locations">Various locations</string>
<string name="location_confirmation_title">New location</string>
<string name="location_confirmation_substring">Are you sure you want set a new location for selected items?</string>

</resources>

0 comments on commit 4aced56

Please sign in to comment.