From ff9c4ecb67ce11d4ec693525396151f4bc3d1331 Mon Sep 17 00:00:00 2001 From: David Perez Date: Mon, 15 Jan 2024 18:09:13 -0600 Subject: [PATCH] Add support for a localPermissionsManager (#628) --- .../util => manager/permissions}/PermissionsManager.kt | 2 +- .../permissions}/PermissionsManagerImpl.kt | 2 +- .../bitwarden/ui/platform/theme/BitwardenTheme.kt | 10 ++++++++++ .../vault/feature/addedit/VaultAddEditItemContent.kt | 2 +- .../ui/vault/feature/addedit/VaultAddEditScreen.kt | 8 +++----- .../feature/manualcodeentry/ManualCodeEntryScreen.kt | 8 +++----- .../permissions}/FakePermissionManager.kt | 2 +- .../ui/vault/feature/addedit/VaultAddEditScreenTest.kt | 2 +- .../manualcodeentry/ManualCodeEntryScreenTests.kt | 2 +- 9 files changed, 22 insertions(+), 16 deletions(-) rename app/src/main/java/com/x8bit/bitwarden/ui/platform/{base/util => manager/permissions}/PermissionsManager.kt (92%) rename app/src/main/java/com/x8bit/bitwarden/ui/platform/{base/util => manager/permissions}/PermissionsManagerImpl.kt (95%) rename app/src/test/java/com/x8bit/bitwarden/ui/platform/{base/util => manager/permissions}/FakePermissionManager.kt (95%) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/base/util/PermissionsManager.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/manager/permissions/PermissionsManager.kt similarity index 92% rename from app/src/main/java/com/x8bit/bitwarden/ui/platform/base/util/PermissionsManager.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/platform/manager/permissions/PermissionsManager.kt index 1a74ad97c..e53001343 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/base/util/PermissionsManager.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/manager/permissions/PermissionsManager.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.platform.base.util +package com.x8bit.bitwarden.ui.platform.manager.permissions import androidx.activity.compose.ManagedActivityResultLauncher import androidx.compose.runtime.Composable diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/base/util/PermissionsManagerImpl.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/manager/permissions/PermissionsManagerImpl.kt similarity index 95% rename from app/src/main/java/com/x8bit/bitwarden/ui/platform/base/util/PermissionsManagerImpl.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/platform/manager/permissions/PermissionsManagerImpl.kt index 08d9fe6ba..0be9f1a4c 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/base/util/PermissionsManagerImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/manager/permissions/PermissionsManagerImpl.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.platform.base.util +package com.x8bit.bitwarden.ui.platform.manager.permissions import android.app.Activity import android.content.pm.PackageManager diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/theme/BitwardenTheme.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/theme/BitwardenTheme.kt index a68448053..5da94b0e4 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/theme/BitwardenTheme.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/theme/BitwardenTheme.kt @@ -22,6 +22,8 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.core.view.WindowCompat import com.x8bit.bitwarden.R +import com.x8bit.bitwarden.ui.platform.manager.permissions.PermissionsManager +import com.x8bit.bitwarden.ui.platform.manager.permissions.PermissionsManagerImpl /** * The overall application theme. This can be configured to support a [darkTheme] and @@ -66,6 +68,7 @@ fun BitwardenTheme( CompositionLocalProvider( LocalNonMaterialColors provides nonMaterialColors, LocalNonMaterialTypography provides nonMaterialTypography, + LocalPermissionsManager provides PermissionsManagerImpl(context as Activity), ) { // Set overall theme based on color scheme and typography settings MaterialTheme( @@ -152,6 +155,13 @@ private fun lightColorScheme(context: Context): ColorScheme = private fun Int.toColor(context: Context): Color = Color(context.getColor(this)) +/** + * Provides access to non material theme typography throughout the app. + */ +val LocalPermissionsManager: ProvidableCompositionLocal = compositionLocalOf { + error("CompositionLocal LocalPermissionsManager not present") +} + /** * Provides access to non material theme typography throughout the app. */ diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditItemContent.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditItemContent.kt index 068cffd29..f87bf18c5 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditItemContent.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditItemContent.kt @@ -12,7 +12,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.x8bit.bitwarden.R -import com.x8bit.bitwarden.ui.platform.base.util.PermissionsManager +import com.x8bit.bitwarden.ui.platform.manager.permissions.PermissionsManager import com.x8bit.bitwarden.ui.platform.components.BitwardenListHeaderText import com.x8bit.bitwarden.ui.platform.components.BitwardenMultiSelectButton import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCardTypeHandlers diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreen.kt index 48887b204..076389f43 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreen.kt @@ -1,6 +1,5 @@ package com.x8bit.bitwarden.ui.vault.feature.addedit -import android.app.Activity import android.widget.Toast import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.imePadding @@ -20,8 +19,6 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.x8bit.bitwarden.R import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect -import com.x8bit.bitwarden.ui.platform.base.util.PermissionsManager -import com.x8bit.bitwarden.ui.platform.base.util.PermissionsManagerImpl import com.x8bit.bitwarden.ui.platform.base.util.asText import com.x8bit.bitwarden.ui.platform.components.BasicDialogState import com.x8bit.bitwarden.ui.platform.components.BitwardenBasicDialog @@ -32,6 +29,8 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenScaffold import com.x8bit.bitwarden.ui.platform.components.BitwardenTextButton import com.x8bit.bitwarden.ui.platform.components.BitwardenTopAppBar import com.x8bit.bitwarden.ui.platform.components.LoadingDialogState +import com.x8bit.bitwarden.ui.platform.manager.permissions.PermissionsManager +import com.x8bit.bitwarden.ui.platform.theme.LocalPermissionsManager import com.x8bit.bitwarden.ui.tools.feature.generator.model.GeneratorMode import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCardTypeHandlers import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers @@ -48,8 +47,7 @@ fun VaultAddEditScreen( onNavigateBack: () -> Unit, onNavigateToQrCodeScanScreen: () -> Unit, viewModel: VaultAddEditViewModel = hiltViewModel(), - permissionsManager: PermissionsManager = - PermissionsManagerImpl(LocalContext.current as Activity), + permissionsManager: PermissionsManager = LocalPermissionsManager.current, onNavigateToManualCodeEntryScreen: () -> Unit, onNavigateToGeneratorModal: (GeneratorMode.Modal) -> Unit, ) { diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryScreen.kt index 9a4983be9..0cc831775 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryScreen.kt @@ -1,7 +1,6 @@ package com.x8bit.bitwarden.ui.vault.feature.manualcodeentry import android.Manifest -import android.app.Activity import android.content.Intent import android.net.Uri import android.provider.Settings @@ -34,14 +33,14 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.x8bit.bitwarden.R import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect import com.x8bit.bitwarden.ui.platform.base.util.IntentHandler -import com.x8bit.bitwarden.ui.platform.base.util.PermissionsManager -import com.x8bit.bitwarden.ui.platform.base.util.PermissionsManagerImpl import com.x8bit.bitwarden.ui.platform.base.util.toAnnotatedString import com.x8bit.bitwarden.ui.platform.components.BitwardenFilledTonalButton import com.x8bit.bitwarden.ui.platform.components.BitwardenScaffold import com.x8bit.bitwarden.ui.platform.components.BitwardenTextField import com.x8bit.bitwarden.ui.platform.components.BitwardenTopAppBar import com.x8bit.bitwarden.ui.platform.components.BitwardenTwoButtonDialog +import com.x8bit.bitwarden.ui.platform.manager.permissions.PermissionsManager +import com.x8bit.bitwarden.ui.platform.theme.LocalPermissionsManager /** * The screen to manually add a totp code. @@ -54,8 +53,7 @@ fun ManualCodeEntryScreen( onNavigateToQrCodeScreen: () -> Unit, viewModel: ManualCodeEntryViewModel = hiltViewModel(), intentHandler: IntentHandler = IntentHandler(LocalContext.current), - permissionsManager: PermissionsManager = - PermissionsManagerImpl(LocalContext.current as Activity), + permissionsManager: PermissionsManager = LocalPermissionsManager.current, ) { var shouldShowPermissionDialog by rememberSaveable { mutableStateOf(false) } val state by viewModel.stateFlow.collectAsStateWithLifecycle() diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/platform/base/util/FakePermissionManager.kt b/app/src/test/java/com/x8bit/bitwarden/ui/platform/manager/permissions/FakePermissionManager.kt similarity index 95% rename from app/src/test/java/com/x8bit/bitwarden/ui/platform/base/util/FakePermissionManager.kt rename to app/src/test/java/com/x8bit/bitwarden/ui/platform/manager/permissions/FakePermissionManager.kt index 12031675b..e9bf92a85 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/platform/base/util/FakePermissionManager.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/platform/manager/permissions/FakePermissionManager.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.platform.base.util +package com.x8bit.bitwarden.ui.platform.manager.permissions import androidx.activity.compose.ManagedActivityResultLauncher import androidx.compose.runtime.Composable diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreenTest.kt index 3c988bcc5..904993d06 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreenTest.kt @@ -29,8 +29,8 @@ import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.performTouchInput import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest -import com.x8bit.bitwarden.ui.platform.base.util.FakePermissionManager import com.x8bit.bitwarden.ui.platform.base.util.asText +import com.x8bit.bitwarden.ui.platform.manager.permissions.FakePermissionManager import com.x8bit.bitwarden.ui.tools.feature.generator.model.GeneratorMode import com.x8bit.bitwarden.ui.util.isProgressBar import com.x8bit.bitwarden.ui.util.onAllNodesWithContentDescriptionAfterScroll diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryScreenTests.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryScreenTests.kt index acfdccdf2..4ee120066 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryScreenTests.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryScreenTests.kt @@ -17,8 +17,8 @@ import androidx.compose.ui.test.performTextInput import androidx.test.core.app.ApplicationProvider import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest -import com.x8bit.bitwarden.ui.platform.base.util.FakePermissionManager import com.x8bit.bitwarden.ui.platform.base.util.IntentHandler +import com.x8bit.bitwarden.ui.platform.manager.permissions.FakePermissionManager import io.mockk.every import io.mockk.mockk import io.mockk.slot