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
This commit is contained in:
Jays2Kings 2021-07-10 15:11:39 -04:00
parent 70fc7c3b3b
commit 2ac761729d
8 changed files with 20 additions and 7 deletions

View File

@ -16,6 +16,8 @@ object PreferenceKeys {
const val backToStart = "back_to_start" const val backToStart = "back_to_start"
const val deniedA11FilePermission = "denied_a11_file_permission"
const val rotation = "pref_rotation_type_key" const val rotation = "pref_rotation_type_key"
const val enableTransitions = "pref_enable_transitions_key" const val enableTransitions = "pref_enable_transitions_key"

View File

@ -106,6 +106,8 @@ class PreferencesHelper(val context: Context) {
fun startingTab() = flowPrefs.getInt(Keys.startingTab, 0) fun startingTab() = flowPrefs.getInt(Keys.startingTab, 0)
fun backReturnsToStart() = flowPrefs.getBoolean(Keys.backToStart, true) fun backReturnsToStart() = flowPrefs.getBoolean(Keys.backToStart, true)
fun hasDeniedA11FilePermission() = flowPrefs.getBoolean(Keys.deniedA11FilePermission, false)
fun clear() = prefs.edit().clear().apply() fun clear() = prefs.edit().clear().apply()
fun oldTheme() = prefs.getInt(Keys.theme, 5) fun oldTheme() = prefs.getInt(Keys.theme, 5)

View File

@ -214,7 +214,7 @@ class MangaDetailsController :
presenter.onCreate() presenter.onCreate()
binding.swipeRefresh.isRefreshing = presenter.isLoading binding.swipeRefresh.isRefreshing = presenter.isLoading
binding.swipeRefresh.setOnRefreshListener { presenter.refreshAll() } 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 */ /** Check if device is tablet, and use a second recycler to hold the details header if so */

View File

@ -367,7 +367,7 @@ class RecentsController(bundle: Bundle? = null) :
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.expand() binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.expand()
} }
setPadding(binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable == true) setPadding(binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable == true)
requestFilePermissionsSafe(301) requestFilePermissionsSafe(301, presenter.preferences)
} }
fun updateTitleAndMenu() { fun updateTitleAndMenu() {

View File

@ -42,7 +42,7 @@ class SettingsBackupController : SettingsController() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
requestFilePermissionsSafe(500) requestFilePermissionsSafe(500, preferences)
} }
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {

View File

@ -160,7 +160,7 @@ class BrowseController :
updateTitleAndMenu() updateTitleAndMenu()
} }
requestFilePermissionsSafe(301) requestFilePermissionsSafe(301, preferences)
binding.bottomSheet.root.onCreate(this) binding.bottomSheet.root.onCreate(this)
binding.shadow.alpha = binding.shadow.alpha =

View File

@ -38,6 +38,7 @@ import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.view.applyBottomAnimatedInsets import eu.kanade.tachiyomi.util.view.applyBottomAnimatedInsets
import eu.kanade.tachiyomi.util.view.inflate 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.scrollViewWith
import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener
import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.snack
@ -131,6 +132,7 @@ open class BrowseSourceController(bundle: Bundle) :
binding.fab.isVisible = presenter.sourceFilters.isNotEmpty() binding.fab.isVisible = presenter.sourceFilters.isNotEmpty()
binding.fab.setOnClickListener { showFilters() } binding.fab.setOnClickListener { showFilters() }
binding.progress.isVisible = true binding.progress.isVisible = true
requestFilePermissionsSafe(301, preferences, presenter.source is LocalSource)
} }
override fun onDestroyView(view: View) { override fun onDestroyView(view: View) {

View File

@ -492,7 +492,11 @@ fun Controller.requestPermissionsSafe(permissions: Array<String>, requestCode: I
} }
} }
fun Controller.requestFilePermissionsSafe(requestCode: Int) { fun Controller.requestFilePermissionsSafe(
requestCode: Int,
preferences: PreferencesHelper,
showA11PermissionAnyway: Boolean = false
) {
val activity = activity ?: return val activity = activity ?: return
val permissions = mutableListOf(Manifest.permission.WRITE_EXTERNAL_STORAGE) val permissions = mutableListOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)
permissions.forEach { permission -> permissions.forEach { permission ->
@ -504,9 +508,12 @@ fun Controller.requestFilePermissionsSafe(requestCode: Int) {
requestPermissions(arrayOf(permission), requestCode) requestPermissions(arrayOf(permission), requestCode)
} }
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && if (
!Environment.isExternalStorageManager() Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
!Environment.isExternalStorageManager() &&
(!preferences.hasDeniedA11FilePermission().get() || showA11PermissionAnyway)
) { ) {
preferences.hasDeniedA11FilePermission().set(true)
MaterialDialog(activity) MaterialDialog(activity)
.title(R.string.all_files_permission_required) .title(R.string.all_files_permission_required)
.message(R.string.external_storage_permission_notice) .message(R.string.external_storage_permission_notice)