diff --git a/app/src/main/kotlin/me/eternal/purrfectsnap/ui/manager/pages/location/BetterLocationRoot.kt b/app/src/main/kotlin/me/eternal/purrfectsnap/ui/manager/pages/location/BetterLocationRoot.kt index ccbab3ea..3f702d53 100644 --- a/app/src/main/kotlin/me/eternal/purrfectsnap/ui/manager/pages/location/BetterLocationRoot.kt +++ b/app/src/main/kotlin/me/eternal/purrfectsnap/ui/manager/pages/location/BetterLocationRoot.kt @@ -234,6 +234,8 @@ class BetterLocationRoot : Routes.Route() { val coordinatesProperty = remember { context.config.root.global.betterLocation.getPropertyPair("coordinates") } + val providerProperty = remember { context.config.root.global.betterLocation.getPropertyPair("location_search_provider") } + val apiKeyProperty = remember { context.config.root.global.betterLocation.getPropertyPair("google_maps_api_key") } val updateDispatcher = rememberAsyncUpdateDispatcher() val savedCoordinates = rememberAsyncMutableStateList( @@ -245,6 +247,8 @@ class BetterLocationRoot : Routes.Route() { var showMap by remember { mutableStateOf(false) } var addSavedCoordinateDialog by remember { mutableStateOf(false) } var showTeleportDialog by remember { mutableStateOf(false) } + var showProviderDialog by remember { mutableStateOf(false) } + var showApiKeyDialog by remember { mutableStateOf(false) } val marker = remember { mutableStateOf(null) } val mapView = remember { mutableStateOf(null) } @@ -271,6 +275,17 @@ class BetterLocationRoot : Routes.Route() { ) } + if (showProviderDialog) { + me.eternal.purrfectsnap.ui.util.Dialog(onDismissRequest = { showProviderDialog = false }) { + alertDialogs.UniqueSelectionDialog(providerProperty) + } + } + if (showApiKeyDialog) { + me.eternal.purrfectsnap.ui.util.Dialog(onDismissRequest = { showApiKeyDialog = false }) { + alertDialogs.KeyboardInputDialog(apiKeyProperty) { showApiKeyDialog = false } + } + } + Column( modifier = Modifier .fillMaxSize() @@ -401,6 +416,39 @@ class BetterLocationRoot : Routes.Route() { ) { context.config.root.global.betterLocation.suspendLocationUpdates.set(it) } + + @Composable + fun ConfigSelector(text: String, value: String, onClick: () -> Unit) { + Row( + modifier = Modifier + .fillMaxWidth() + .clickable(onClick = onClick) + .padding(horizontal = 16.dp, vertical = 12.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Text(text = text) + Spacer(modifier = Modifier.weight(1f)) + Text(text = value, color = PurrfectPalette.textSecondary, fontSize = 14.sp) + } + } + + @Composable + fun ConfigInput(text: String, value: String, onClick: () -> Unit) { + ConfigSelector(text, if (value.isNotEmpty()) "********" else translation["options.empty"], onClick) + } + + val currentProvider = context.config.root.global.betterLocation.locationSearchProvider.get() + ConfigSelector( + text = translation["properties.location_search_provider.name"], + value = context.translation["options.location_search_provider.$currentProvider"] + ) { showProviderDialog = true } + + if (currentProvider == "google_maps") { + ConfigInput( + text = translation["properties.google_maps_api_key.name"], + value = context.config.root.global.betterLocation.googleMapsApiKey.get() + ) { showApiKeyDialog = true } + } } item { GlassPanel( diff --git a/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/Global.kt b/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/Global.kt index 7888b3ff..5f89a740 100644 --- a/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/Global.kt +++ b/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/Global.kt @@ -28,7 +28,7 @@ class Global : ConfigContainer() { val spoofBatteryLevel = string("spoof_battery_level") { requireRestart(); inputCheck = { it.isEmpty() || it.toIntOrNull() in 0..100 } } val spoofHeadphones = boolean("spoof_headphones") { requireRestart() } val showBatteryLevel = boolean("show_battery_level") { requireRestart() } - val locationSearchProvider = unique("location_search_provider", "osm", "google_maps") + val locationSearchProvider = unique("location_search_provider", "osm", "google_maps") { addFlags(ConfigFlag.NO_DISABLE_KEY) } val googleMapsApiKey = string("google_maps_api_key") { addFlags(ConfigFlag.SENSITIVE) } }