From 017ad72360ed0d508a9d53071a80943b4797f434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Karpi=C5=84ski?= Date: Mon, 10 Jun 2024 20:22:25 +0200 Subject: [PATCH] Use `Permission` component from `dev.medzik.android.components` --- .../android/ui/components/Permission.kt | 39 ------------------- .../android/ui/screens/vault/OtpConfigure.kt | 2 +- 2 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 app/src/main/java/dev/medzik/librepass/android/ui/components/Permission.kt diff --git a/app/src/main/java/dev/medzik/librepass/android/ui/components/Permission.kt b/app/src/main/java/dev/medzik/librepass/android/ui/components/Permission.kt deleted file mode 100644 index c37846f5..00000000 --- a/app/src/main/java/dev/medzik/librepass/android/ui/components/Permission.kt +++ /dev/null @@ -1,39 +0,0 @@ -package dev.medzik.librepass.android.ui.components - -import android.content.pm.PackageManager -import androidx.activity.compose.rememberLauncherForActivityResult -import androidx.activity.result.contract.ActivityResultContracts -import androidx.compose.runtime.Composable -import androidx.compose.runtime.SideEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.setValue -import androidx.compose.ui.platform.LocalContext -import androidx.core.content.ContextCompat -import dev.medzik.android.components.rememberMutableBoolean - -@Composable -fun Permission( - permission: String, - onDenied: @Composable (requester: @Composable () -> Unit) -> Unit, - onGranted: @Composable () -> Unit = {} -) { - val ctx = LocalContext.current - - // check the initial state of permission, it may be already granted - var grantState by rememberMutableBoolean( - ContextCompat.checkSelfPermission( - ctx, - permission - ) == PackageManager.PERMISSION_GRANTED - ) - - if (grantState) { - onGranted() - } else { - val launcher = rememberLauncherForActivityResult(contract = ActivityResultContracts.RequestPermission()) { - grantState = it - } - - onDenied { SideEffect { launcher.launch(permission) } } - } -} diff --git a/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/OtpConfigure.kt b/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/OtpConfigure.kt index df7d433a..f8967962 100644 --- a/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/OtpConfigure.kt +++ b/app/src/main/java/dev/medzik/librepass/android/ui/screens/vault/OtpConfigure.kt @@ -24,11 +24,11 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController +import dev.medzik.android.components.Permission import dev.medzik.android.components.rememberMutable import dev.medzik.android.components.ui.ComboBoxDropdown import dev.medzik.librepass.android.R import dev.medzik.librepass.android.ui.LibrePassViewModel -import dev.medzik.librepass.android.ui.components.Permission import dev.medzik.librepass.android.ui.components.QrCodeScanner import dev.medzik.librepass.android.ui.components.TextInputFieldBase import dev.medzik.librepass.android.ui.components.TopBar