add strings to strings.xml
This commit is contained in:
parent
0e355a3e49
commit
0c2b2268dd
4 changed files with 40 additions and 35 deletions
|
@ -14,6 +14,7 @@ import androidx.compose.runtime.*
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.google.accompanist.permissions.isGranted
|
||||
import com.google.accompanist.permissions.rememberPermissionState
|
||||
|
@ -72,12 +73,14 @@ class MainActivity : ComponentActivity() {
|
|||
if (code != "" && !(doNotAsk && isURL(code)))
|
||||
ScannedAlert(
|
||||
onDismiss = { code = "" },
|
||||
code = code
|
||||
code = code, doNotAsk = doNotAsk
|
||||
) { doNotAsk = it }
|
||||
} else PermissionAlert(
|
||||
textToShow = if (cameraPermissionState.status.shouldShowRationale) "The camera is important for this app. Please grant the permission."
|
||||
else "Camera permission is required for this feature to be available. Please grant the permission.",
|
||||
permissionName = "camera"
|
||||
textToShow = if (cameraPermissionState.status.shouldShowRationale) stringResource(
|
||||
id = R.string.camera_rationale
|
||||
)
|
||||
else stringResource(id = R.string.camera_required),
|
||||
title = stringResource(id = R.string.camera_grant)
|
||||
) {
|
||||
cameraPermissionState.launchPermissionRequest()
|
||||
}
|
||||
|
|
|
@ -5,20 +5,20 @@ import androidx.compose.material3.AlertDialog
|
|||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.henryhiles.qscan.R
|
||||
|
||||
@Composable
|
||||
fun PermissionAlert(textToShow: String, permissionName: String, onGrantRequest: () -> Unit) {
|
||||
fun PermissionAlert(textToShow: String, title: String, onGrantRequest: () -> Unit) {
|
||||
AlertDialog(
|
||||
title = {
|
||||
Text(
|
||||
text = "${permissionName.replaceFirstChar { it.uppercaseChar() }} permission required",
|
||||
)
|
||||
Text(text = title)
|
||||
},
|
||||
onDismissRequest = {},
|
||||
confirmButton = {
|
||||
TextButton(onClick = onGrantRequest) {
|
||||
Text(
|
||||
text = "Grant Permission",
|
||||
text = stringResource(id = R.string.action_permission_grant),
|
||||
)
|
||||
}
|
||||
},
|
||||
|
@ -30,21 +30,4 @@ fun PermissionAlert(textToShow: String, permissionName: String, onGrantRequest:
|
|||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
//Surface(
|
||||
//shape = MaterialTheme.shapes.large
|
||||
//) {
|
||||
// Column(modifier = Modifier.padding(16.dp)) {
|
||||
|
||||
|
||||
//
|
||||
// Row(
|
||||
// modifier = Modifier.fillMaxWidth(),
|
||||
// horizontalArrangement = Arrangement.End
|
||||
// ) {
|
||||
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
|
@ -10,24 +10,31 @@ import androidx.compose.material3.TextButton
|
|||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.henryhiles.qscan.LabelledCheckBox
|
||||
import com.henryhiles.qscan.R
|
||||
import com.henryhiles.qscan.utils.Helpers.isURL
|
||||
|
||||
@Composable
|
||||
fun ScannedAlert(onDismiss: () -> Unit, code: String, onChangeDoNotAsk: (Boolean) -> Unit) {
|
||||
fun ScannedAlert(
|
||||
onDismiss: () -> Unit,
|
||||
code: String,
|
||||
doNotAsk: Boolean,
|
||||
onChangeDoNotAsk: (Boolean) -> Unit
|
||||
) {
|
||||
val uriHandler = LocalUriHandler.current
|
||||
var tempDoNotAsk by remember { mutableStateOf(false) }
|
||||
var tempDoNotAsk by remember { mutableStateOf(doNotAsk) }
|
||||
|
||||
AlertDialog(
|
||||
title = {
|
||||
Text(
|
||||
text = "QR Code Scanned",
|
||||
text = stringResource(id = R.string.code_scanned),
|
||||
)
|
||||
}, onDismissRequest = onDismiss, dismissButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(
|
||||
text = "Cancel",
|
||||
text = stringResource(id = R.string.action_cancel),
|
||||
)
|
||||
}
|
||||
},
|
||||
|
@ -35,14 +42,16 @@ fun ScannedAlert(onDismiss: () -> Unit, code: String, onChangeDoNotAsk: (Boolean
|
|||
Column {
|
||||
SelectionContainer {
|
||||
Text(
|
||||
text = if (isURL(code)) "This QR code will take you to $code, are you sure you want to go there?" else "The content of that QR Code is \"$code\"",
|
||||
text = stringResource(id = if (isURL(code)) R.string.code_description_url else R.string.code_description_text).format(
|
||||
code
|
||||
),
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LabelledCheckBox(
|
||||
checked = tempDoNotAsk,
|
||||
onCheckedChange = { tempDoNotAsk = it },
|
||||
label = "Don't ask again"
|
||||
label = stringResource(id = R.string.setting_do_not_ask)
|
||||
)
|
||||
}
|
||||
},
|
||||
|
@ -54,7 +63,7 @@ fun ScannedAlert(onDismiss: () -> Unit, code: String, onChangeDoNotAsk: (Boolean
|
|||
onDismiss()
|
||||
}) {
|
||||
Text(
|
||||
text = "Open URL",
|
||||
text = stringResource(id = R.string.action_open_url),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
<resources>
|
||||
<string name="app_name">QScan</string>
|
||||
<string name="app_name" translatable="false">QScan</string>
|
||||
<string name="camera_grant">Camera permission required</string>
|
||||
<string name="camera_rationale">"The camera is important for this app. Please grant the permission."</string>
|
||||
<string name="camera_required">"Camera permission is required for this feature to be available. Please grant the permission."</string>
|
||||
<string name="action_cancel">Cancel</string>
|
||||
<string name="action_permission_grant">Grant permission</string>
|
||||
<string name="action_open_url">Open URL</string>
|
||||
<string name="setting_do_not_ask">Don\'t ask again</string>
|
||||
<string name="code_scanned">QR Code Scanned</string>
|
||||
<string name="code_description_url">This QR code will take you to %1$s, are you sure you want to go there?"</string>
|
||||
<string name="code_description_text">The content of that QR Code is "%1$s".</string>
|
||||
</resources>
|
Reference in a new issue