From cc744b2b74cd59f8af5ae28c027dd097fd43ca9d Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 18 Dec 2023 19:43:05 +0530 Subject: [PATCH 1/2] Fixed: 3.9.0 Welcome screen does not run, and Kiwix does not prompt for permissions. * This commit addresses the scenario where, for any reason, shared preferences and the database are retained on the device, and the list of ZIM files is visible in the library. However, the `MANAGE_EXTERNAL_PERMISSION` is not found, and when a user attempts to open a file, the application lacks the necessary permission. To improve this scenario, we now prompt the user for permission if it is not available when opening ZIM files from the library. * Additionally, enhanced the behavior of the swipe refresh layout if the user clicks on the "NO" button in the permission dialog. --- .../nav/destination/library/LocalLibraryFragment.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 a8e049ad1..ddb336d9e 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 @@ -139,7 +139,14 @@ class LocalLibraryFragment : BaseFragment() { private val bookDelegate: BookOnDiskDelegate.BookDelegate by lazy { BookOnDiskDelegate.BookDelegate( sharedPreferenceUtil, - { offerAction(RequestNavigateTo(it)) }, + { + if (!requireActivity().isManageExternalStoragePermissionGranted(sharedPreferenceUtil)) { + @Suppress("NewApi") + showManageExternalStoragePermissionDialog() + } else { + offerAction(RequestNavigateTo(it)) + } + }, { offerAction(RequestMultiSelection(it)) }, { offerAction(RequestSelect(it)) } ) @@ -266,6 +273,10 @@ class LocalLibraryFragment : BaseFragment() { if (!requireActivity().isManageExternalStoragePermissionGranted(sharedPreferenceUtil)) { @Suppress("NewApi") showManageExternalStoragePermissionDialog() + // Set loading to false since the dialog is currently being displayed. + // If the user clicks on "No" in the permission dialog, + // the loading icon remains visible infinitely. + fragmentDestinationLibraryBinding?.zimSwiperefresh?.isRefreshing = false } else { requestFileSystemCheck() } From 0e61bdd7d859d472c8fe77f694f7aae15f2e2f2b Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Tue, 19 Dec 2023 12:31:55 +0530 Subject: [PATCH 2/2] Removed the lint suppression for "NewApi". --- .../library/LocalLibraryFragment.kt | 19 ++++++++----------- .../library/OnlineLibraryFragment.kt | 18 ++++++++---------- 2 files changed, 16 insertions(+), 21 deletions(-) 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 ddb336d9e..8e2246620 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 @@ -38,7 +38,6 @@ import android.view.ViewGroup import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts -import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.appcompat.widget.Toolbar @@ -141,7 +140,6 @@ class LocalLibraryFragment : BaseFragment() { sharedPreferenceUtil, { if (!requireActivity().isManageExternalStoragePermissionGranted(sharedPreferenceUtil)) { - @Suppress("NewApi") showManageExternalStoragePermissionDialog() } else { offerAction(RequestNavigateTo(it)) @@ -271,7 +269,6 @@ class LocalLibraryFragment : BaseFragment() { fragmentDestinationLibraryBinding?.zimSwiperefresh?.isRefreshing = false } else { if (!requireActivity().isManageExternalStoragePermissionGranted(sharedPreferenceUtil)) { - @Suppress("NewApi") showManageExternalStoragePermissionDialog() // Set loading to false since the dialog is currently being displayed. // If the user clicks on "No" in the permission dialog, @@ -284,14 +281,15 @@ class LocalLibraryFragment : BaseFragment() { } } - @RequiresApi(Build.VERSION_CODES.R) private fun showManageExternalStoragePermissionDialog() { - dialogShower.show( - KiwixDialog.ManageExternalFilesPermissionDialog, - { - this.activity?.let(FragmentActivity::navigateToSettings) - } - ) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + dialogShower.show( + KiwixDialog.ManageExternalFilesPermissionDialog, + { + this.activity?.let(FragmentActivity::navigateToSettings) + } + ) + } } private fun getBottomNavigationView() = @@ -314,7 +312,6 @@ class LocalLibraryFragment : BaseFragment() { fragmentDestinationLibraryBinding?.selectFile?.setOnClickListener { if (!requireActivity().isManageExternalStoragePermissionGranted(sharedPreferenceUtil)) { - @Suppress("NewApi") showManageExternalStoragePermissionDialog() } else { showFileChooser() diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt index 130406570..c28579cd1 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt @@ -37,7 +37,6 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts -import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.Toolbar @@ -531,7 +530,6 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { sharedPreferenceUtil ) ) { - @Suppress("NewApi") showManageExternalStoragePermissionDialog() } else { availableSpaceCalculator.hasAvailableSpaceFor( @@ -579,20 +577,20 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { private fun clickOnBookItem() { if (!requireActivity().isManageExternalStoragePermissionGranted(sharedPreferenceUtil)) { - @Suppress("NewApi") showManageExternalStoragePermissionDialog() } else { downloadBookItem?.let(::onBookItemClick) } } - @RequiresApi(Build.VERSION_CODES.R) private fun showManageExternalStoragePermissionDialog() { - dialogShower.show( - KiwixDialog.ManageExternalFilesPermissionDialog, - { - this.activity?.let(FragmentActivity::navigateToSettings) - } - ) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + dialogShower.show( + KiwixDialog.ManageExternalFilesPermissionDialog, + { + this.activity?.let(FragmentActivity::navigateToSettings) + } + ) + } } }