Fixing Camera permissions

This commit is contained in:
ThomasSession 2024-09-09 14:29:29 +10:00
parent 85161ffe33
commit 83b08cc438
5 changed files with 19 additions and 10 deletions

View File

@ -310,7 +310,6 @@ dependencies {
implementation "nl.komponents.kovenant:kovenant:$kovenantVersion" implementation "nl.komponents.kovenant:kovenant:$kovenantVersion"
implementation "nl.komponents.kovenant:kovenant-android:$kovenantVersion" implementation "nl.komponents.kovenant:kovenant-android:$kovenantVersion"
implementation "com.jakewharton.rxbinding3:rxbinding:3.1.0" implementation "com.jakewharton.rxbinding3:rxbinding:3.1.0"
implementation "com.github.tbruyelle:rxpermissions:0.10.2"
implementation "com.github.ybq:Android-SpinKit:1.4.0" implementation "com.github.ybq:Android-SpinKit:1.4.0"
implementation "com.opencsv:opencsv:4.6" implementation "com.opencsv:opencsv:4.6"
testImplementation "junit:junit:$junitVersion" testImplementation "junit:junit:$junitVersion"
@ -366,7 +365,7 @@ dependencies {
debugImplementation "androidx.compose.ui:ui-test-manifest:$composeVersion" debugImplementation "androidx.compose.ui:ui-test-manifest:$composeVersion"
implementation "com.google.accompanist:accompanist-themeadapter-appcompat:0.33.1-alpha" implementation "com.google.accompanist:accompanist-themeadapter-appcompat:0.33.1-alpha"
implementation "com.google.accompanist:accompanist-permissions:0.33.1-alpha" implementation "com.google.accompanist:accompanist-permissions:0.36.0"
implementation "com.google.accompanist:accompanist-drawablepainter:0.33.1-alpha" implementation "com.google.accompanist:accompanist-drawablepainter:0.33.1-alpha"
implementation "androidx.camera:camera-camera2:1.3.2" implementation "androidx.camera:camera-camera2:1.3.2"

View File

@ -89,9 +89,9 @@ class WebRtcCallActivity : PassphraseRequiredActionBarActivity() {
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent) super.onNewIntent(intent)
if (intent?.action == ACTION_ANSWER) { if (intent.action == ACTION_ANSWER) {
val answerIntent = WebRtcCallService.acceptCallIntent(this) val answerIntent = WebRtcCallService.acceptCallIntent(this)
answerIntent.flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT answerIntent.flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
ContextCompat.startForegroundService(this, answerIntent) ContextCompat.startForegroundService(this, answerIntent)

View File

@ -317,10 +317,6 @@ public class AttachmentManager {
.put(APP_NAME_KEY, context.getString(R.string.app_name)) .put(APP_NAME_KEY, context.getString(R.string.app_name))
.format().toString(); .format().toString();
String requireCameraPermissionTxt = Phrase.from(context, R.string.cameraGrantAccessDescription)
.put(APP_NAME_KEY, context.getString(R.string.app_name))
.format().toString();
Permissions.with(activity) Permissions.with(activity)
.request(Manifest.permission.CAMERA) .request(Manifest.permission.CAMERA)
.withPermanentDenialDialog(cameraPermissionDeniedTxt) .withPermanentDenialDialog(cameraPermissionDeniedTxt)

View File

@ -5,6 +5,10 @@ import android.content.Context
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.PermissionState
import com.google.accompanist.permissions.isGranted
import com.google.accompanist.permissions.shouldShowRationale
import com.squareup.phrase.Phrase import com.squareup.phrase.Phrase
import org.thoughtcrime.securesms.ui.theme.SessionMaterialTheme import org.thoughtcrime.securesms.ui.theme.SessionMaterialTheme
@ -39,3 +43,8 @@ fun ComposeView.setThemedContent(content: @Composable () -> Unit) = setContent {
content() content()
} }
} }
@ExperimentalPermissionsApi
fun PermissionState.isPermanentlyDenied(): Boolean {
return !status.shouldShowRationale && !status.isGranted
}

View File

@ -68,6 +68,8 @@ import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.ui.AlertDialog import org.thoughtcrime.securesms.ui.AlertDialog
import org.thoughtcrime.securesms.ui.DialogButtonModel import org.thoughtcrime.securesms.ui.DialogButtonModel
import org.thoughtcrime.securesms.ui.GetString import org.thoughtcrime.securesms.ui.GetString
import org.thoughtcrime.securesms.ui.getSubbedString
import org.thoughtcrime.securesms.ui.isPermanentlyDenied
import org.thoughtcrime.securesms.ui.theme.LocalColors 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
@ -119,7 +121,7 @@ fun QRScannerScreen(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
onClick = { onClick = {
// if the permission has been denied permanently, ask the user to go to the settings // if the permission has been denied permanently, ask the user to go to the settings
if (cameraPermissionState.status.shouldShowRationale){ if (cameraPermissionState.isPermanentlyDenied()){
showCameraPermissionDialog = true showCameraPermissionDialog = true
} }
// otherwise ask for permission // otherwise ask for permission
@ -134,10 +136,13 @@ fun QRScannerScreen(
// camera permission denied permanently dialog // camera permission denied permanently dialog
if(showCameraPermissionDialog){ if(showCameraPermissionDialog){
val context = LocalContext.current
AlertDialog( AlertDialog(
onDismissRequest = { showCameraPermissionDialog = false }, onDismissRequest = { showCameraPermissionDialog = false },
title = stringResource(R.string.permissionsRequired), title = stringResource(R.string.permissionsRequired),
text = stringResource(R.string.permissionsCameraDenied), text = context.getSubbedString(R.string.permissionsCameraDenied,
APP_NAME_KEY to context.getString(R.string.app_name)),
buttons = listOf( buttons = listOf(
DialogButtonModel( DialogButtonModel(
text = GetString(stringResource(id = R.string.sessionSettings)), text = GetString(stringResource(id = R.string.sessionSettings)),