-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Capture location] Prompt for location permissions when capture locat…
…ion task is opened (#2818) * dialog ui added * show dialog for the first time when enter * added permission check * string and view fix
- Loading branch information
1 parent
a9815b0
commit e2fcc7b
Showing
5 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...va/com/google/android/ground/ui/datacollection/tasks/location/LocationPermissionDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.android.ground.ui.datacollection.tasks.location | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.provider.Settings | ||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.google.android.ground.R | ||
import com.google.android.ground.ui.theme.AppTheme | ||
|
||
@Composable | ||
fun LocationPermissionDialog(onDismiss: () -> Unit, onCancel: () -> Unit) { | ||
val context = LocalContext.current | ||
AlertDialog( | ||
containerColor = MaterialTheme.colorScheme.surface, | ||
onDismissRequest = { onDismiss() }, | ||
title = { | ||
Text( | ||
stringResource(R.string.allow_location_title), | ||
color = MaterialTheme.colorScheme.onSurface, | ||
) | ||
}, | ||
text = { | ||
Text( | ||
stringResource(R.string.allow_location_description), | ||
color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
) | ||
}, | ||
dismissButton = { | ||
TextButton(onClick = { onCancel() }) { Text(text = stringResource(R.string.cancel)) } | ||
}, | ||
confirmButton = { | ||
TextButton( | ||
onClick = { | ||
// Open the app settings | ||
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) | ||
val uri = Uri.fromParts("package", context.packageName, null) | ||
intent.data = uri | ||
context.startActivity(intent) | ||
} | ||
) { | ||
Text(text = stringResource(R.string.allow_location_confirmation)) | ||
} | ||
}, | ||
) | ||
} | ||
|
||
@Composable | ||
@Preview | ||
fun PreviewUserDetailsDialog() { | ||
AppTheme { LocationPermissionDialog({}, {}) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters