From 5e9962b5a18066cfa8bd8c902ac82bec85d9105e Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 17 Apr 2024 22:41:35 +0530 Subject: [PATCH] Fixed: PlayStore reported IndexOutOfBoundsException, when we are selecting the item from rightDrawer. * The error is not reproducible on my device and emulators too. But playStore reported this error so somehow this error is occurring. So to fix this issue we are now only performing the click action when the item is available in the DocumentSectionsList. This will avoid this type of error. --- .../core/main/CoreReaderFragment.kt | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 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 c472dc22de..b72e23e647 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 @@ -678,16 +678,27 @@ abstract class CoreReaderFragment : } override fun onSectionClick(view: View?, position: Int) { - loadUrlWithCurrentWebview( - "javascript:document.getElementById('" + - documentSections?.get(position)?.id?.replace("'", "\\'") + - "').scrollIntoView();" - ) + if (hasItemForPositionInDocumentSectionsList(position)) { // Bug Fix #3796 + loadUrlWithCurrentWebview( + "javascript:document.getElementById('" + + documentSections?.get(position)?.id?.replace("'", "\\'") + + "').scrollIntoView();" + ) + } drawerLayout?.closeDrawers() } }) } + private fun hasItemForPositionInDocumentSectionsList(position: Int): Boolean { + val documentListSize = documentSections?.size ?: return false + return when { + position < 0 -> false + position >= documentListSize -> false + else -> true + } + } + private fun showTabSwitcher() { (requireActivity() as CoreMainActivity).disableDrawer() actionBar?.apply {