From 2ac761729d9e25e302c4578f5605059813be8253 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 10 Jul 2021 15:11:39 -0400 Subject: [PATCH] Laxing on the all files permission for a11 The permission will now show only once, aside from trying to download manga or trying to read local manga close #910 --- .../tachiyomi/data/preference/PreferenceKeys.kt | 2 ++ .../tachiyomi/data/preference/PreferencesHelper.kt | 2 ++ .../tachiyomi/ui/manga/MangaDetailsController.kt | 2 +- .../tachiyomi/ui/recents/RecentsController.kt | 2 +- .../ui/setting/SettingsBackupController.kt | 2 +- .../kanade/tachiyomi/ui/source/BrowseController.kt | 2 +- .../ui/source/browse/BrowseSourceController.kt | 2 ++ .../tachiyomi/util/view/ControllerExtensions.kt | 13 ++++++++++--- 8 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index efed769540..5bc4e498a5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -16,6 +16,8 @@ object PreferenceKeys { const val backToStart = "back_to_start" + const val deniedA11FilePermission = "denied_a11_file_permission" + const val rotation = "pref_rotation_type_key" const val enableTransitions = "pref_enable_transitions_key" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 8bd8705884..3a6476d27a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -106,6 +106,8 @@ class PreferencesHelper(val context: Context) { fun startingTab() = flowPrefs.getInt(Keys.startingTab, 0) fun backReturnsToStart() = flowPrefs.getBoolean(Keys.backToStart, true) + fun hasDeniedA11FilePermission() = flowPrefs.getBoolean(Keys.deniedA11FilePermission, false) + fun clear() = prefs.edit().clear().apply() fun oldTheme() = prefs.getInt(Keys.theme, 5) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index 1dafae78e0..8d99ca895a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -214,7 +214,7 @@ class MangaDetailsController : presenter.onCreate() binding.swipeRefresh.isRefreshing = presenter.isLoading binding.swipeRefresh.setOnRefreshListener { presenter.refreshAll() } - requestFilePermissionsSafe(301) + requestFilePermissionsSafe(301, presenter.preferences, presenter.manga.isLocal()) } /** Check if device is tablet, and use a second recycler to hold the details header if so */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index ac72b7e660..b92c82cf0a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -367,7 +367,7 @@ class RecentsController(bundle: Bundle? = null) : binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.expand() } setPadding(binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable == true) - requestFilePermissionsSafe(301) + requestFilePermissionsSafe(301, presenter.preferences) } fun updateTitleAndMenu() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index 929bb20d66..8bfd850492 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -42,7 +42,7 @@ class SettingsBackupController : SettingsController() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - requestFilePermissionsSafe(500) + requestFilePermissionsSafe(500, preferences) } override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt index bdfacbb502..ee34033787 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt @@ -160,7 +160,7 @@ class BrowseController : updateTitleAndMenu() } - requestFilePermissionsSafe(301) + requestFilePermissionsSafe(301, preferences) binding.bottomSheet.root.onCreate(this) binding.shadow.alpha = diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt index 3b24a2bc9b..b6a94347a1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt @@ -38,6 +38,7 @@ import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.view.applyBottomAnimatedInsets import eu.kanade.tachiyomi.util.view.inflate +import eu.kanade.tachiyomi.util.view.requestFilePermissionsSafe import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener import eu.kanade.tachiyomi.util.view.snack @@ -131,6 +132,7 @@ open class BrowseSourceController(bundle: Bundle) : binding.fab.isVisible = presenter.sourceFilters.isNotEmpty() binding.fab.setOnClickListener { showFilters() } binding.progress.isVisible = true + requestFilePermissionsSafe(301, preferences, presenter.source is LocalSource) } override fun onDestroyView(view: View) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt index cea447b626..913f8a3cc5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt @@ -492,7 +492,11 @@ fun Controller.requestPermissionsSafe(permissions: Array, requestCode: I } } -fun Controller.requestFilePermissionsSafe(requestCode: Int) { +fun Controller.requestFilePermissionsSafe( + requestCode: Int, + preferences: PreferencesHelper, + showA11PermissionAnyway: Boolean = false +) { val activity = activity ?: return val permissions = mutableListOf(Manifest.permission.WRITE_EXTERNAL_STORAGE) permissions.forEach { permission -> @@ -504,9 +508,12 @@ fun Controller.requestFilePermissionsSafe(requestCode: Int) { requestPermissions(arrayOf(permission), requestCode) } } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && - !Environment.isExternalStorageManager() + if ( + Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && + !Environment.isExternalStorageManager() && + (!preferences.hasDeniedA11FilePermission().get() || showA11PermissionAnyway) ) { + preferences.hasDeniedA11FilePermission().set(true) MaterialDialog(activity) .title(R.string.all_files_permission_required) .message(R.string.external_storage_permission_notice)