From 3b7ed9bc6d99c9822f3051f3696fb8359b4a8f8a Mon Sep 17 00:00:00 2001 From: Caleb Morris Date: Sun, 22 Oct 2023 16:58:16 -0700 Subject: [PATCH] Detached permission request from DiskUtil (#10051) Being an extension on the DiskUtil couples to a class at a different abstraction layer without really needing to. Created PermissionRequestHelper as a place to put similar requests if needed in the future. --- .../presentation/extensions/DiskUtil.kt | 18 ----------------- .../settings/screen/SettingsBackupScreen.kt | 5 ++--- .../permissions/PermissionRequestHelper.kt | 20 +++++++++++++++++++ .../kanade/tachiyomi/ui/browse/BrowseTab.kt | 5 ++--- 4 files changed, 24 insertions(+), 24 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/presentation/extensions/DiskUtil.kt create mode 100644 app/src/main/java/eu/kanade/presentation/permissions/PermissionRequestHelper.kt diff --git a/app/src/main/java/eu/kanade/presentation/extensions/DiskUtil.kt b/app/src/main/java/eu/kanade/presentation/extensions/DiskUtil.kt deleted file mode 100644 index f0581e0999..0000000000 --- a/app/src/main/java/eu/kanade/presentation/extensions/DiskUtil.kt +++ /dev/null @@ -1,18 +0,0 @@ -package eu.kanade.presentation.extensions - -import android.Manifest -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import com.google.accompanist.permissions.rememberPermissionState -import eu.kanade.tachiyomi.util.storage.DiskUtil - -/** - * Launches request for [Manifest.permission.WRITE_EXTERNAL_STORAGE] permission - */ -@Composable -fun DiskUtil.RequestStoragePermission() { - val permissionState = rememberPermissionState(permission = Manifest.permission.WRITE_EXTERNAL_STORAGE) - LaunchedEffect(Unit) { - permissionState.launchPermissionRequest() - } -} diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt index e35acffe07..cb9c9907c2 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt @@ -33,15 +33,14 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.core.net.toUri import com.hippo.unifile.UniFile -import eu.kanade.presentation.extensions.RequestStoragePermission import eu.kanade.presentation.more.settings.Preference +import eu.kanade.presentation.permissions.PermissionRequestHelper import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.backup.BackupConst import eu.kanade.tachiyomi.data.backup.BackupCreateJob import eu.kanade.tachiyomi.data.backup.BackupFileValidator import eu.kanade.tachiyomi.data.backup.BackupRestoreJob import eu.kanade.tachiyomi.data.backup.models.Backup -import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.toast @@ -66,7 +65,7 @@ object SettingsBackupScreen : SearchableSettings { override fun getPreferences(): List { val backupPreferences = Injekt.get() - DiskUtil.RequestStoragePermission() + PermissionRequestHelper.requestStoragePermission() return listOf( getCreateBackupPref(), diff --git a/app/src/main/java/eu/kanade/presentation/permissions/PermissionRequestHelper.kt b/app/src/main/java/eu/kanade/presentation/permissions/PermissionRequestHelper.kt new file mode 100644 index 0000000000..7ce28f9dac --- /dev/null +++ b/app/src/main/java/eu/kanade/presentation/permissions/PermissionRequestHelper.kt @@ -0,0 +1,20 @@ +package eu.kanade.presentation.permissions + +import android.Manifest +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import com.google.accompanist.permissions.rememberPermissionState + +/** + * Launches request for [Manifest.permission.WRITE_EXTERNAL_STORAGE] permission + */ +object PermissionRequestHelper { + + @Composable + fun requestStoragePermission() { + val permissionState = rememberPermissionState(permission = Manifest.permission.WRITE_EXTERNAL_STORAGE) + LaunchedEffect(Unit) { + permissionState.launchPermissionRequest() + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseTab.kt index d0753ce108..4466cb5672 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseTab.kt @@ -14,7 +14,7 @@ import cafe.adriel.voyager.navigator.Navigator import cafe.adriel.voyager.navigator.tab.LocalTabNavigator import cafe.adriel.voyager.navigator.tab.TabOptions import eu.kanade.presentation.components.TabbedScreen -import eu.kanade.presentation.extensions.RequestStoragePermission +import eu.kanade.presentation.permissions.PermissionRequestHelper import eu.kanade.presentation.util.Tab import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.browse.extension.ExtensionsScreenModel @@ -23,7 +23,6 @@ import eu.kanade.tachiyomi.ui.browse.migration.sources.migrateSourceTab import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchScreen import eu.kanade.tachiyomi.ui.browse.source.sourcesTab import eu.kanade.tachiyomi.ui.main.MainActivity -import eu.kanade.tachiyomi.util.storage.DiskUtil data class BrowseTab( private val toExtensions: Boolean = false, @@ -66,7 +65,7 @@ data class BrowseTab( ) // For local source - DiskUtil.RequestStoragePermission() + PermissionRequestHelper.requestStoragePermission() LaunchedEffect(Unit) { (context as? MainActivity)?.ready = true