mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Fixed: Searched item was not opening in custom apps.
This commit is contained in:
parent
2fb1896cea
commit
67111ef848
@ -58,7 +58,6 @@ import org.kiwix.kiwixmobile.core.main.ToolbarScrollingKiwixWebView
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.WebViewHistoryItem
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource.Companion.fromDatabaseValue
|
||||
import org.kiwix.kiwixmobile.core.search.viewmodel.effects.SearchItemToOpen
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_FILE
|
||||
import org.kiwix.kiwixmobile.core.utils.TAG_KIWIX
|
||||
@ -70,7 +69,6 @@ private const val HIDE_TAB_SWITCHER_DELAY: Long = 300
|
||||
|
||||
class KiwixReaderFragment : CoreReaderFragment() {
|
||||
private var isFullScreenVideo: Boolean = false
|
||||
private var searchItemToOpen: SearchItemToOpen? = null
|
||||
|
||||
override fun inject(baseActivity: BaseActivity) {
|
||||
baseActivity.cachedComponent.inject(this)
|
||||
@ -113,16 +111,7 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
||||
} else {
|
||||
val restoreOrigin =
|
||||
if (args.searchItemTitle.isNotEmpty()) FromSearchScreen else FromExternalLaunch
|
||||
manageExternalLaunchAndRestoringViewState(restoreOrigin) {
|
||||
// This lambda function is invoked after restoring the tabs. It checks if there is a
|
||||
// search item to open. If `searchItemToOpen` is not null, it will call the superclass
|
||||
// method to open the specified search item. After opening, it sets `searchItemToOpen`
|
||||
// to null to prevent any unexpected behavior on subsequent calls.
|
||||
searchItemToOpen?.let {
|
||||
super.openSearchItem(it)
|
||||
}
|
||||
searchItemToOpen = null
|
||||
}
|
||||
manageExternalLaunchAndRestoringViewState(restoreOrigin)
|
||||
}
|
||||
}
|
||||
requireArguments().clear()
|
||||
@ -162,18 +151,6 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
||||
openZimFile(zimReaderSource)
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the specified search item to be opened later.
|
||||
*
|
||||
* This method saves the provided `SearchItemToOpen` object, which will be used to
|
||||
* open the searched item after the tabs have been restored.
|
||||
*
|
||||
* @param item The search item to be opened after restoring the tabs.
|
||||
*/
|
||||
override fun openSearchItem(item: SearchItemToOpen) {
|
||||
searchItemToOpen = item
|
||||
}
|
||||
|
||||
override fun loadDrawerViews() {
|
||||
drawerLayout = requireActivity().findViewById(R.id.navigation_container)
|
||||
tableDrawerRightContainer = requireActivity().findViewById(R.id.reader_drawer_nav_view)
|
||||
|
@ -287,6 +287,7 @@ abstract class CoreReaderFragment :
|
||||
private var isFirstTimeMainPageLoaded = true
|
||||
private var isFromManageExternalLaunch = false
|
||||
private var shouldSaveTabsOnPause = true
|
||||
private var searchItemToOpen: SearchItemToOpen? = null
|
||||
|
||||
@JvmField
|
||||
@Inject
|
||||
@ -2138,6 +2139,18 @@ abstract class CoreReaderFragment :
|
||||
openSearch("", isOpenedFromTabView = false, isVoice)
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the specified search item to be opened later.
|
||||
*
|
||||
* This method saves the provided `SearchItemToOpen` object, which will be used to
|
||||
* open the searched item after the tabs have been restored.
|
||||
*
|
||||
* @param item The search item to be opened after restoring the tabs.
|
||||
*/
|
||||
private fun storeSearchItem(item: SearchItemToOpen) {
|
||||
searchItemToOpen = item
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a search item based on its properties.
|
||||
*
|
||||
@ -2146,13 +2159,8 @@ abstract class CoreReaderFragment :
|
||||
* The method attempts to load the page URL directly. If the page URL is not available,
|
||||
* it attempts to convert the page title to a URL using the ZIM reader container. The
|
||||
* resulting URL is then loaded in the current web view.
|
||||
*
|
||||
* Note: This method is overridden in the `KiwixReaderFragment` class to store the
|
||||
* `SearchItemToOpen` object for later use. If modifications are made to this method,
|
||||
* please check the overridden version to understand how it interacts with the fragment's
|
||||
* navigation logic.
|
||||
*/
|
||||
open fun openSearchItem(item: SearchItemToOpen) {
|
||||
private fun openSearchItem(item: SearchItemToOpen) {
|
||||
if (item.shouldOpenInNewTab) {
|
||||
createNewTab()
|
||||
}
|
||||
@ -2708,8 +2716,7 @@ abstract class CoreReaderFragment :
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
protected fun manageExternalLaunchAndRestoringViewState(
|
||||
restoreOrigin: RestoreOrigin = FromExternalLaunch,
|
||||
onComplete: () -> Unit = {}
|
||||
restoreOrigin: RestoreOrigin = FromExternalLaunch
|
||||
) {
|
||||
val settings = requireActivity().getSharedPreferences(
|
||||
SharedPreferenceUtil.PREF_KIWIX_MOBILE,
|
||||
@ -2725,9 +2732,15 @@ abstract class CoreReaderFragment :
|
||||
restoreViewStateOnValidWebViewHistory(
|
||||
webViewHistoryItemList,
|
||||
currentTab,
|
||||
restoreOrigin,
|
||||
onComplete
|
||||
)
|
||||
restoreOrigin
|
||||
) {
|
||||
// This lambda function is invoked after restoring the tabs. It checks if there is a
|
||||
// search item to open. If `searchItemToOpen` is not null, it will call the openSearchItem
|
||||
// method to open the specified search item. After opening, it sets `searchItemToOpen`
|
||||
// to null to prevent any unexpected behavior on subsequent calls.
|
||||
searchItemToOpen?.let(::openSearchItem)
|
||||
searchItemToOpen = null
|
||||
}
|
||||
}, {
|
||||
restoreViewStateOnInvalidWebViewHistory()
|
||||
})
|
||||
@ -2800,7 +2813,7 @@ abstract class CoreReaderFragment :
|
||||
requireActivity().observeNavigationResult<SearchItemToOpen>(
|
||||
TAG_FILE_SEARCHED,
|
||||
viewLifecycleOwner,
|
||||
Observer(::openSearchItem)
|
||||
Observer(::storeSearchItem)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.custom.main
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.View
|
||||
@ -139,11 +140,13 @@ class CustomReaderFragment : CoreReaderFragment() {
|
||||
private fun loadPageFromNavigationArguments() {
|
||||
val args = CustomReaderFragmentArgs.fromBundle(requireArguments())
|
||||
if (args.pageUrl.isNotEmpty()) {
|
||||
Log.e("OPEN_PAGE", "loadPageFromNavigationArguments: ${args.pageUrl}")
|
||||
loadUrlWithCurrentWebview(args.pageUrl)
|
||||
// Setup bookmark for current book
|
||||
// See https://github.com/kiwix/kiwix-android/issues/3541
|
||||
zimReaderContainer?.zimFileReader?.let(::setUpBookmarks)
|
||||
} else {
|
||||
Log.e("OPEN_PAGE", "loadPageFromNavigationArguments: else part")
|
||||
openObbOrZim(true)
|
||||
}
|
||||
requireArguments().clear()
|
||||
|
Loading…
x
Reference in New Issue
Block a user