SES-2702 - making sure we hook the permission results everywhere

This commit is contained in:
ThomasSession 2024-09-11 10:56:38 +10:00
parent b452a17b42
commit 0fd801accb
3 changed files with 17 additions and 0 deletions

View File

@ -388,6 +388,11 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
super.onDestroy()
EventBus.getDefault().unregister(this)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults)
}
// endregion
// region Updating

View File

@ -13,6 +13,7 @@ import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.onboarding.manager.LoadAccountManager
import org.thoughtcrime.securesms.onboarding.messagenotifications.MessageNotificationsActivity
import org.thoughtcrime.securesms.permissions.Permissions
import org.thoughtcrime.securesms.ui.setComposeContent
import org.thoughtcrime.securesms.util.start
@ -45,4 +46,9 @@ class LoadAccountActivity : BaseActionBarActivity() {
LoadAccountScreen(state, viewModel.qrErrors, viewModel::onChange, viewModel::onContinue, viewModel::onScanQrCode)
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults)
}
}

View File

@ -120,6 +120,12 @@ fun QRScannerScreen(
stringResource(R.string.cameraGrantAccess),
modifier = Modifier.fillMaxWidth(),
onClick = {
// NOTE: We used to use the Accompanist's way to handle permissions in compose
// but it doesn't seem to offer a solution when a user manually changes a permission
// to 'Ask every time' form the app's settings.
// So we are using our custom implementation. ONE IMPORTANT THING with this approach
// is that we need to make sure every activity where this composable is used NEED to
// implement `onRequestPermissionsResult` (see LoadAccountActivity.kt for an example)
Permissions.with(context.findActivity())
.request(permission)
.withPermanentDenialDialog(