mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-16 19:05:27 -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.page.history.adapter.WebViewHistoryItem
|
||||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
|
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
|
||||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource.Companion.fromDatabaseValue
|
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.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_FILE
|
import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_FILE
|
||||||
import org.kiwix.kiwixmobile.core.utils.TAG_KIWIX
|
import org.kiwix.kiwixmobile.core.utils.TAG_KIWIX
|
||||||
@ -70,7 +69,6 @@ private const val HIDE_TAB_SWITCHER_DELAY: Long = 300
|
|||||||
|
|
||||||
class KiwixReaderFragment : CoreReaderFragment() {
|
class KiwixReaderFragment : CoreReaderFragment() {
|
||||||
private var isFullScreenVideo: Boolean = false
|
private var isFullScreenVideo: Boolean = false
|
||||||
private var searchItemToOpen: SearchItemToOpen? = null
|
|
||||||
|
|
||||||
override fun inject(baseActivity: BaseActivity) {
|
override fun inject(baseActivity: BaseActivity) {
|
||||||
baseActivity.cachedComponent.inject(this)
|
baseActivity.cachedComponent.inject(this)
|
||||||
@ -113,16 +111,7 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
} else {
|
} else {
|
||||||
val restoreOrigin =
|
val restoreOrigin =
|
||||||
if (args.searchItemTitle.isNotEmpty()) FromSearchScreen else FromExternalLaunch
|
if (args.searchItemTitle.isNotEmpty()) FromSearchScreen else FromExternalLaunch
|
||||||
manageExternalLaunchAndRestoringViewState(restoreOrigin) {
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
requireArguments().clear()
|
requireArguments().clear()
|
||||||
@ -162,18 +151,6 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
openZimFile(zimReaderSource)
|
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() {
|
override fun loadDrawerViews() {
|
||||||
drawerLayout = requireActivity().findViewById(R.id.navigation_container)
|
drawerLayout = requireActivity().findViewById(R.id.navigation_container)
|
||||||
tableDrawerRightContainer = requireActivity().findViewById(R.id.reader_drawer_nav_view)
|
tableDrawerRightContainer = requireActivity().findViewById(R.id.reader_drawer_nav_view)
|
||||||
|
@ -287,6 +287,7 @@ abstract class CoreReaderFragment :
|
|||||||
private var isFirstTimeMainPageLoaded = true
|
private var isFirstTimeMainPageLoaded = true
|
||||||
private var isFromManageExternalLaunch = false
|
private var isFromManageExternalLaunch = false
|
||||||
private var shouldSaveTabsOnPause = true
|
private var shouldSaveTabsOnPause = true
|
||||||
|
private var searchItemToOpen: SearchItemToOpen? = null
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@Inject
|
@Inject
|
||||||
@ -2138,6 +2139,18 @@ abstract class CoreReaderFragment :
|
|||||||
openSearch("", isOpenedFromTabView = false, isVoice)
|
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.
|
* 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,
|
* 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
|
* 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.
|
* 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) {
|
if (item.shouldOpenInNewTab) {
|
||||||
createNewTab()
|
createNewTab()
|
||||||
}
|
}
|
||||||
@ -2708,8 +2716,7 @@ abstract class CoreReaderFragment :
|
|||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
protected fun manageExternalLaunchAndRestoringViewState(
|
protected fun manageExternalLaunchAndRestoringViewState(
|
||||||
restoreOrigin: RestoreOrigin = FromExternalLaunch,
|
restoreOrigin: RestoreOrigin = FromExternalLaunch
|
||||||
onComplete: () -> Unit = {}
|
|
||||||
) {
|
) {
|
||||||
val settings = requireActivity().getSharedPreferences(
|
val settings = requireActivity().getSharedPreferences(
|
||||||
SharedPreferenceUtil.PREF_KIWIX_MOBILE,
|
SharedPreferenceUtil.PREF_KIWIX_MOBILE,
|
||||||
@ -2725,9 +2732,15 @@ abstract class CoreReaderFragment :
|
|||||||
restoreViewStateOnValidWebViewHistory(
|
restoreViewStateOnValidWebViewHistory(
|
||||||
webViewHistoryItemList,
|
webViewHistoryItemList,
|
||||||
currentTab,
|
currentTab,
|
||||||
restoreOrigin,
|
restoreOrigin
|
||||||
onComplete
|
) {
|
||||||
)
|
// 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()
|
restoreViewStateOnInvalidWebViewHistory()
|
||||||
})
|
})
|
||||||
@ -2800,7 +2813,7 @@ abstract class CoreReaderFragment :
|
|||||||
requireActivity().observeNavigationResult<SearchItemToOpen>(
|
requireActivity().observeNavigationResult<SearchItemToOpen>(
|
||||||
TAG_FILE_SEARCHED,
|
TAG_FILE_SEARCHED,
|
||||||
viewLifecycleOwner,
|
viewLifecycleOwner,
|
||||||
Observer(::openSearchItem)
|
Observer(::storeSearchItem)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ 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
|
||||||
@ -139,11 +140,13 @@ 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