From b1eb76e49b0097c451a759f143bec94028e5e36a Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 26 Jun 2023 14:06:02 +0530 Subject: [PATCH] Improved the permission asking scenario for custom apps --- .../core/main/CoreReaderFragment.kt | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt index 409289a75..690623a28 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt @@ -342,10 +342,25 @@ abstract class CoreReaderFragment : // Successfully granted permission, so opening the note keeper showAddNoteDialog() } else { - Toast.makeText( - requireActivity().applicationContext, - getString(R.string.ext_storage_write_permission_denied_add_note), Toast.LENGTH_LONG - ).show() + if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + /* shouldShowRequestPermissionRationale() returns false when: + * 1) User has previously checked on "Don't ask me again", and/or + * 2) Permission has been disabled on device + */ + requireActivity().toast( + R.string.ext_storage_permission_rationale_add_note, + Toast.LENGTH_LONG + ) + } else { + requireActivity().toast( + R.string.ext_storage_write_permission_denied_add_note, + Toast.LENGTH_LONG + ) + alertDialogShower?.show( + KiwixDialog.ReadPermissionRequired, + requireActivity()::navigateToAppSettings + ) + } } } @@ -1306,22 +1321,7 @@ abstract class CoreReaderFragment : ) { isPermissionGranted = true } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - storagePermissionForNotesLauncher?.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) - /* shouldShowRequestPermissionRationale() returns false when: - * 1) User has previously checked on "Don't ask me again", and/or - * 2) Permission has been disabled on device - */ - requireActivity().toast( - R.string.ext_storage_permission_rationale_add_note, - Toast.LENGTH_LONG - ) - } else { - alertDialogShower?.show( - KiwixDialog.ReadPermissionRequired, - requireActivity()::navigateToAppSettings - ) - } + storagePermissionForNotesLauncher?.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) } } else { // For Android versions below Marshmallow 6.0 (API 23) isPermissionGranted = true // As already requested at install time