From 528ca4d18ed692d6ec1ea0d53b79dc1e83a6a533 Mon Sep 17 00:00:00 2001 From: MohitMali Date: Tue, 31 Oct 2023 15:45:36 +0530 Subject: [PATCH] Fixed, can not open ZIM files from phone storage via the file picker in Android 13. * Improved the permission request scenario for 'MANAGE_EXTERNAL_STORAGE' in Android 13. In the non-play store variant, we were not prompting users to grant this permission, and they were unaware that it was necessary to access the ZIM files in their storage. To resolve this issue, we now request this permission. --- app/detekt_baseline.xml | 2 +- .../library/LocalLibraryFragment.kt | 50 ++++++++++--------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/app/detekt_baseline.xml b/app/detekt_baseline.xml index 22d856fb2d..db84623e8a 100644 --- a/app/detekt_baseline.xml +++ b/app/detekt_baseline.xml @@ -12,7 +12,7 @@ MagicNumber:ZimManageViewModel.kt$ZimManageViewModel$5 MagicNumber:ZimManageViewModel.kt$ZimManageViewModel$500 MagicNumber:LocalFileTransferFragment.kt$LocalFileTransferFragment$500 - NestedBlockDepth:LocalLibraryFragment.kt$LocalLibraryFragment$private fun checkPermissions() + NestedBlockDepth:LocalLibraryFragment.kt$LocalLibraryFragment$private fun checkManageExternalStoragePermission() NestedBlockDepth:PeerGroupHandshake.kt$PeerGroupHandshake$private fun readHandshakeAndExchangeMetaData(): InetAddress? NestedBlockDepth:ReceiverHandShake.kt$ReceiverHandShake$override fun exchangeFileTransferMetadata(inputStream: InputStream, outputStream: OutputStream) PackageNaming:AvailableSpaceCalculator.kt$package diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt index d0ca9e4162..3782bc6ae3 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt @@ -430,33 +430,37 @@ class LocalLibraryFragment : BaseFragment() { ) ) } else { - requestFileSystemCheck() + checkManageExternalStoragePermission() } } else { - if (sharedPreferenceUtil.isPlayStoreBuild) { - requestFileSystemCheck() - } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - if (Environment.isExternalStorageManager()) { - // We already have permission!! - requestFileSystemCheck() - } else { - if (sharedPreferenceUtil.manageExternalFilesPermissionDialog) { - // We should only ask for first time, If the users wants to revoke settings - // then they can directly toggle this feature from settings screen - sharedPreferenceUtil.manageExternalFilesPermissionDialog = false - // Show Dialog and Go to settings to give permission - dialogShower.show( - KiwixDialog.ManageExternalFilesPermissionDialog, - { - this.activity?.let(FragmentActivity::navigateToSettings) - } - ) - } - } - } else { + checkManageExternalStoragePermission() + } + } + + private fun checkManageExternalStoragePermission() { + if (sharedPreferenceUtil.isPlayStoreBuild) { + requestFileSystemCheck() + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (Environment.isExternalStorageManager()) { + // We already have permission!! requestFileSystemCheck() + } else { + if (sharedPreferenceUtil.manageExternalFilesPermissionDialog) { + // We should only ask for first time, If the users wants to revoke settings + // then they can directly toggle this feature from settings screen + sharedPreferenceUtil.manageExternalFilesPermissionDialog = false + // Show Dialog and Go to settings to give permission + dialogShower.show( + KiwixDialog.ManageExternalFilesPermissionDialog, + { + this.activity?.let(FragmentActivity::navigateToSettings) + } + ) + } } + } else { + requestFileSystemCheck() } } }