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.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalUriHandler
|
import androidx.compose.ui.platform.LocalUriHandler
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||||
import com.google.accompanist.permissions.isGranted
|
import com.google.accompanist.permissions.isGranted
|
||||||
import com.google.accompanist.permissions.rememberPermissionState
|
import com.google.accompanist.permissions.rememberPermissionState
|
||||||
|
@ -72,12 +73,14 @@ class MainActivity : ComponentActivity() {
|
||||||
if (code != "" && !(doNotAsk && isURL(code)))
|
if (code != "" && !(doNotAsk && isURL(code)))
|
||||||
ScannedAlert(
|
ScannedAlert(
|
||||||
onDismiss = { code = "" },
|
onDismiss = { code = "" },
|
||||||
code = code
|
code = code, doNotAsk = doNotAsk
|
||||||
) { doNotAsk = it }
|
) { doNotAsk = it }
|
||||||
} else PermissionAlert(
|
} else PermissionAlert(
|
||||||
textToShow = if (cameraPermissionState.status.shouldShowRationale) "The camera is important for this app. Please grant the permission."
|
textToShow = if (cameraPermissionState.status.shouldShowRationale) stringResource(
|
||||||
else "Camera permission is required for this feature to be available. Please grant the permission.",
|
id = R.string.camera_rationale
|
||||||
permissionName = "camera"
|
)
|
||||||
|
else stringResource(id = R.string.camera_required),
|
||||||
|
title = stringResource(id = R.string.camera_grant)
|
||||||
) {
|
) {
|
||||||
cameraPermissionState.launchPermissionRequest()
|
cameraPermissionState.launchPermissionRequest()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,20 +5,20 @@ import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import com.henryhiles.qscan.R
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PermissionAlert(textToShow: String, permissionName: String, onGrantRequest: () -> Unit) {
|
fun PermissionAlert(textToShow: String, title: String, onGrantRequest: () -> Unit) {
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(text = title)
|
||||||
text = "${permissionName.replaceFirstChar { it.uppercaseChar() }} permission required",
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
onDismissRequest = {},
|
onDismissRequest = {},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
TextButton(onClick = onGrantRequest) {
|
TextButton(onClick = onGrantRequest) {
|
||||||
Text(
|
Text(
|
||||||
text = "Grant Permission",
|
text = stringResource(id = R.string.action_permission_grant),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -31,20 +31,3 @@ 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.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalUriHandler
|
import androidx.compose.ui.platform.LocalUriHandler
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.henryhiles.qscan.LabelledCheckBox
|
import com.henryhiles.qscan.LabelledCheckBox
|
||||||
|
import com.henryhiles.qscan.R
|
||||||
import com.henryhiles.qscan.utils.Helpers.isURL
|
import com.henryhiles.qscan.utils.Helpers.isURL
|
||||||
|
|
||||||
@Composable
|
@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
|
val uriHandler = LocalUriHandler.current
|
||||||
var tempDoNotAsk by remember { mutableStateOf(false) }
|
var tempDoNotAsk by remember { mutableStateOf(doNotAsk) }
|
||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
text = "QR Code Scanned",
|
text = stringResource(id = R.string.code_scanned),
|
||||||
)
|
)
|
||||||
}, onDismissRequest = onDismiss, dismissButton = {
|
}, onDismissRequest = onDismiss, dismissButton = {
|
||||||
TextButton(onClick = onDismiss) {
|
TextButton(onClick = onDismiss) {
|
||||||
Text(
|
Text(
|
||||||
text = "Cancel",
|
text = stringResource(id = R.string.action_cancel),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -35,14 +42,16 @@ fun ScannedAlert(onDismiss: () -> Unit, code: String, onChangeDoNotAsk: (Boolean
|
||||||
Column {
|
Column {
|
||||||
SelectionContainer {
|
SelectionContainer {
|
||||||
Text(
|
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))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
LabelledCheckBox(
|
LabelledCheckBox(
|
||||||
checked = tempDoNotAsk,
|
checked = tempDoNotAsk,
|
||||||
onCheckedChange = { tempDoNotAsk = it },
|
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()
|
onDismiss()
|
||||||
}) {
|
}) {
|
||||||
Text(
|
Text(
|
||||||
text = "Open URL",
|
text = stringResource(id = R.string.action_open_url),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,3 +1,13 @@
|
||||||
<resources>
|
<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>
|
</resources>
|
Reference in a new issue