mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Fixed: FindInPage functionality not working in Kiwix and custom apps.
This commit is contained in:
parent
67111ef848
commit
83337ac5f1
@ -288,6 +288,7 @@ abstract class CoreReaderFragment :
|
|||||||
private var isFromManageExternalLaunch = false
|
private var isFromManageExternalLaunch = false
|
||||||
private var shouldSaveTabsOnPause = true
|
private var shouldSaveTabsOnPause = true
|
||||||
private var searchItemToOpen: SearchItemToOpen? = null
|
private var searchItemToOpen: SearchItemToOpen? = null
|
||||||
|
private var findInPageTitle: String? = null
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@Inject
|
@Inject
|
||||||
@ -2358,6 +2359,23 @@ abstract class CoreReaderFragment :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the given title for a "find in page" search operation.
|
||||||
|
* This title is used later when triggering the "find in page" functionality.
|
||||||
|
*
|
||||||
|
* @param title The title or keyword to search for within the current WebView content.
|
||||||
|
*/
|
||||||
|
private fun storeFindInPageTitle(title: String) {
|
||||||
|
findInPageTitle = title
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initiates the "find in page" UI for searching within the current WebView content.
|
||||||
|
* If the `compatCallback` is active, it sets up the WebView to search for the
|
||||||
|
* specified title and displays the search input UI.
|
||||||
|
*
|
||||||
|
* @param title The search term or keyword to locate within the page. If null, no action is taken.
|
||||||
|
*/
|
||||||
private fun findInPage(title: String?) {
|
private fun findInPage(title: String?) {
|
||||||
// if the search is localized trigger find in page UI.
|
// if the search is localized trigger find in page UI.
|
||||||
compatCallback?.apply {
|
compatCallback?.apply {
|
||||||
@ -2734,12 +2752,15 @@ abstract class CoreReaderFragment :
|
|||||||
currentTab,
|
currentTab,
|
||||||
restoreOrigin
|
restoreOrigin
|
||||||
) {
|
) {
|
||||||
// This lambda function is invoked after restoring the tabs. It checks if there is a
|
// This lambda is executed after the tabs have been restored. It checks if there is a
|
||||||
// search item to open. If `searchItemToOpen` is not null, it will call the openSearchItem
|
// search item to open. If `searchItemToOpen` is not null, it calls `openSearchItem`
|
||||||
// method to open the specified search item. After opening, it sets `searchItemToOpen`
|
// to open the specified item, then sets `searchItemToOpen` to null to prevent
|
||||||
// to null to prevent any unexpected behavior on subsequent calls.
|
// any unexpected behavior on future calls. Similarly, if `findInPageTitle` is set,
|
||||||
|
// it invokes `findInPage` and resets `findInPageTitle` to null.
|
||||||
searchItemToOpen?.let(::openSearchItem)
|
searchItemToOpen?.let(::openSearchItem)
|
||||||
searchItemToOpen = null
|
searchItemToOpen = null
|
||||||
|
findInPageTitle?.let(::findInPage)
|
||||||
|
findInPageTitle = null
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
restoreViewStateOnInvalidWebViewHistory()
|
restoreViewStateOnInvalidWebViewHistory()
|
||||||
@ -2808,7 +2829,7 @@ abstract class CoreReaderFragment :
|
|||||||
requireActivity().observeNavigationResult<String>(
|
requireActivity().observeNavigationResult<String>(
|
||||||
FIND_IN_PAGE_SEARCH_STRING,
|
FIND_IN_PAGE_SEARCH_STRING,
|
||||||
viewLifecycleOwner,
|
viewLifecycleOwner,
|
||||||
Observer(::findInPage)
|
Observer(::storeFindInPageTitle)
|
||||||
)
|
)
|
||||||
requireActivity().observeNavigationResult<SearchItemToOpen>(
|
requireActivity().observeNavigationResult<SearchItemToOpen>(
|
||||||
TAG_FILE_SEARCHED,
|
TAG_FILE_SEARCHED,
|
||||||
|
@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.custom.main
|
|||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -140,13 +139,11 @@ class CustomReaderFragment : CoreReaderFragment() {
|
|||||||
private fun loadPageFromNavigationArguments() {
|
private fun loadPageFromNavigationArguments() {
|
||||||
val args = CustomReaderFragmentArgs.fromBundle(requireArguments())
|
val args = CustomReaderFragmentArgs.fromBundle(requireArguments())
|
||||||
if (args.pageUrl.isNotEmpty()) {
|
if (args.pageUrl.isNotEmpty()) {
|
||||||
Log.e("OPEN_PAGE", "loadPageFromNavigationArguments: ${args.pageUrl}")
|
|
||||||
loadUrlWithCurrentWebview(args.pageUrl)
|
loadUrlWithCurrentWebview(args.pageUrl)
|
||||||
// Setup bookmark for current book
|
// Setup bookmark for current book
|
||||||
// See https://github.com/kiwix/kiwix-android/issues/3541
|
// See https://github.com/kiwix/kiwix-android/issues/3541
|
||||||
zimReaderContainer?.zimFileReader?.let(::setUpBookmarks)
|
zimReaderContainer?.zimFileReader?.let(::setUpBookmarks)
|
||||||
} else {
|
} else {
|
||||||
Log.e("OPEN_PAGE", "loadPageFromNavigationArguments: else part")
|
|
||||||
openObbOrZim(true)
|
openObbOrZim(true)
|
||||||
}
|
}
|
||||||
requireArguments().clear()
|
requireArguments().clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user