From dda2200a4bde588aa2bd29f64bf1288e644cbf9a Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Tue, 16 Apr 2024 17:32:03 +0530 Subject: [PATCH 1/2] Fixed: Play Store reported a crash error when closing the tabs. * This error was occurring due to the user frequently clicking the close icon of the same tab, in this situation first click closes the tab, and the second immediate click again triggers the `closeTab` function but recyclerView does not have the valid view for this position because it is in removing process so this makes this view invalid and recyclerView returns the `-1` index for invalid views. So this was the reason for this issue, to address this issue we have added a check in our `closeTab` method if the incoming index is `-1` then it will not execute the further code. --- .../org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt | 4 ++++ 1 file changed, 4 insertions(+) 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 5183cacd41..a848795b69 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 @@ -1198,6 +1198,10 @@ abstract class CoreReaderFragment : if (currentTtsWebViewIndex == index) { onReadAloudStop() } + // Check if the index is valid; RecyclerView gives the index -1 for already removed views. + // Address those issues when the user frequently clicks on the close icon of the same tab. + // See https://github.com/kiwix/kiwix-android/issues/3790 for more details. + if (index == RecyclerView.NO_POSITION) return tempZimFileForUndo = zimReaderContainer?.zimFile tempWebViewForUndo = webViewList[index] webViewList.removeAt(index) From 40e86d02b64982a67a827cf9cf49f88da283aca2 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Tue, 16 Apr 2024 19:16:25 +0530 Subject: [PATCH 2/2] Enhanced the `Tab closed` snackBar behavior. Now, when the user clicks the `UNDO` button to restore a tab, we disable the snackBar's "UNDO" button to prevent subsequent clicks. This prevents the addition of multiple tabs if the `UNDO` button is clicked multiple times, as this type of restored tab leads to unexpected behavior see below video. --- .../org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 a848795b69..0cf7a3424e 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 @@ -1215,7 +1215,10 @@ abstract class CoreReaderFragment : snackBarRoot?.let { it.bringToFront() Snackbar.make(it, R.string.tab_closed, Snackbar.LENGTH_LONG) - .setAction(R.string.undo) { restoreDeletedTab(index) }.show() + .setAction(R.string.undo) { undoButton -> + undoButton.isEnabled = false + restoreDeletedTab(index) + }.show() } openHomeScreen() }