Skip to content

Commit

Permalink
Fixed: Search was not working when closing a tab and immediately open…
Browse files Browse the repository at this point in the history
…ing the search screen.

* The issue occurred because, after closing a tab and quickly navigating to the search screen, the snackbar callback was still running in the background. When switching to the search screen, the WebView list was empty because we clear it when the fragment's view is destroyed. As a result, the book was closed, and the SearchScreen could not find the ZIM file for searching.
* To fix this, we now dismiss the snackbar callback when the fragment's view is destroyed.
  • Loading branch information
MohitMaliDeveloper authored and kelson42 committed Jan 31, 2025
1 parent 553fc44 commit 8be4029
Showing 1 changed file with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ abstract class CoreReaderFragment :

override fun onDestroyView() {
super.onDestroyView()
restoreTabsSnackbarCallback = null
try {
coreReaderLifeCycleScope?.cancel()
readerLifeCycleScope?.cancel()
Expand Down Expand Up @@ -1394,17 +1395,7 @@ abstract class CoreReaderFragment :
.setAction(R.string.undo) { undoButton ->
undoButton.isEnabled = false
restoreDeletedTab(index)
}.addCallback(object : Snackbar.Callback() {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
super.onDismissed(transientBottomBar, event)
// If the undo button is not clicked and no tabs are left, exit the book and
// clean up resources.
if (event != DISMISS_EVENT_ACTION && webViewList.isEmpty()) {
closeZimBook()
}
}
})
.show()
}.addCallback(restoreTabsSnackbarCallback).show()

Check warning on line 1398 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1398

Added line #L1398 was not covered by tests
}
openHomeScreen()
}
Expand Down Expand Up @@ -1895,16 +1886,18 @@ abstract class CoreReaderFragment :
setIsCloseAllTabButtonClickable(true)
restoreDeletedTabs()
}
}.addCallback(object : Snackbar.Callback() {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
super.onDismissed(transientBottomBar, event)
// If the undo button is not clicked and no tabs are left, exit the book and
// clean up resources.
if (event != DISMISS_EVENT_ACTION && webViewList.isEmpty()) {
closeZimBook()
}
}
}).show()
}.addCallback(restoreTabsSnackbarCallback).show()
}
}

private var restoreTabsSnackbarCallback: Snackbar.Callback? = object : Snackbar.Callback() {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
super.onDismissed(transientBottomBar, event)
// If the undo button is not clicked and no tabs are left, exit the book and
// clean up resources.
if (event != DISMISS_EVENT_ACTION && webViewList.isEmpty() && isAdded) {
closeZimBook()

Check warning on line 1899 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1899

Added line #L1899 was not covered by tests
}
}
}

Expand Down

0 comments on commit 8be4029

Please sign in to comment.