Updated QR screen to show dialog when permission is permanently denied

Missing the real string for it!
This commit is contained in:
ThomasSession 2024-09-05 14:55:53 +10:00 committed by fanchao
parent 2c3e73b2a7
commit a7843af306

View File

@ -30,8 +30,11 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
@ -62,6 +65,10 @@ import kotlinx.coroutines.launch
import network.loki.messenger.R import network.loki.messenger.R
import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.ui.AlertDialog
import org.thoughtcrime.securesms.ui.DialogButtonModel
import org.thoughtcrime.securesms.ui.GetString
import org.thoughtcrime.securesms.ui.theme.LocalColors
import org.thoughtcrime.securesms.ui.theme.LocalDimensions import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.ui.theme.LocalType import org.thoughtcrime.securesms.ui.theme.LocalType
@ -86,29 +93,10 @@ fun QRScannerScreen(
val cameraPermissionState = rememberPermissionState(Manifest.permission.CAMERA) val cameraPermissionState = rememberPermissionState(Manifest.permission.CAMERA)
var showCameraPermissionDialog by remember { mutableStateOf(false) }
if (cameraPermissionState.status.isGranted) { if (cameraPermissionState.status.isGranted) {
ScanQrCode(errors, onScan) ScanQrCode(errors, onScan)
} else if (cameraPermissionState.status.shouldShowRationale) {
Column(
modifier = Modifier
.align(Alignment.Center)
.padding(horizontal = 60.dp)
) {
Text(
stringResource(R.string.cameraGrantAccessDenied).let { txt ->
val c = LocalContext.current
Phrase.from(txt).put(APP_NAME_KEY, c.getString(R.string.app_name)).format().toString()
},
style = LocalType.current.base,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.size(LocalDimensions.current.spacing))
OutlineButton(
stringResource(R.string.sessionSettings),
modifier = Modifier.align(Alignment.CenterHorizontally),
onClick = onClickSettings
)
}
} else { } else {
Column( Column(
modifier = Modifier modifier = Modifier
@ -129,11 +117,38 @@ fun QRScannerScreen(
PrimaryOutlineButton( PrimaryOutlineButton(
stringResource(R.string.cameraGrantAccess), stringResource(R.string.cameraGrantAccess),
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
onClick = { cameraPermissionState.run { launchPermissionRequest() } } onClick = {
// if the permission has been denied permanently, ask the user to go to the settings
if (cameraPermissionState.status.shouldShowRationale){
showCameraPermissionDialog = true
}
// otherwise ask for permission
else {
cameraPermissionState.run { launchPermissionRequest() }
}
}
) )
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
} }
} }
// camera permission denied permanently dialog
if(showCameraPermissionDialog){
AlertDialog(
onDismissRequest = { showCameraPermissionDialog = false },
title = stringResource(R.string.permissionsRequired),
text = stringResource(R.string.cameraGrantAccessDenied), //todo UPDATE TO PROPER STRING !!!!!!!!!!!!!!!!!!!!!!!
buttons = listOf(
DialogButtonModel(
text = GetString(stringResource(id = R.string.sessionSettings)),
onClick = onClickSettings
),
DialogButtonModel(
GetString(stringResource(R.string.cancel))
)
)
)
}
} }
} }