Fixed: Opening bookmarks, notes, and history in the reader screen does not work.

* The issue occurred because the reader screen route was not being created properly, as both modules had different destination classes. We made the openPage method abstract so that each module can provide its own destination with arguments to correctly open pages.
* Improved WebView creation in Compose.
This commit is contained in:
MohitMaliFtechiz 2025-08-18 16:06:57 +05:30 committed by Kelson
parent 6bb8512391
commit 629a7f18dc
4 changed files with 66 additions and 21 deletions

View File

@ -46,8 +46,8 @@ import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavController
import androidx.navigation.NavOptions
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavOptions
import androidx.navigation.compose.rememberNavController
import eu.mhutti1.utils.storage.StorageDevice
import eu.mhutti1.utils.storage.StorageDeviceUtils
@ -76,6 +76,7 @@ import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_SUPPORT_ITEM_TESTING_TAG
import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_ZIM_HOST_ITEM_TESTING_TAG
import org.kiwix.kiwixmobile.core.main.NEW_TAB_SHORTCUT_ID
import org.kiwix.kiwixmobile.core.main.ZIM_HOST_DEEP_LINK_SCHEME
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.dialog.DialogHost
import org.kiwix.kiwixmobile.kiwixActivityComponent
@ -381,6 +382,30 @@ class KiwixMainActivity : CoreMainActivity() {
)
}
override fun openPage(
pageUrl: String,
zimReaderSource: ZimReaderSource?,
shouldOpenInNewTab: Boolean
) {
var zimFileUri = ""
if (zimReaderSource != null) {
zimFileUri = zimReaderSource.toDatabase()
}
val navOptions = NavOptions.Builder()
.setLaunchSingleTop(true)
.setPopUpTo(readerFragmentRoute, inclusive = true)
.build()
val readerRoute = KiwixDestination.Reader.createRoute(
zimFileUri = zimFileUri,
pageUrl = pageUrl,
shouldOpenInNewTab = shouldOpenInNewTab
)
navigate(
readerRoute,
navOptions
)
}
override fun hideBottomAppBar() {
shouldShowBottomAppBar.update { false }
}

View File

@ -384,27 +384,11 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
isVoice: Boolean = false
)
fun openPage(
abstract fun openPage(
pageUrl: String,
zimReaderSource: ZimReaderSource? = null,
shouldOpenInNewTab: Boolean = false
) {
var zimFileUri = ""
if (zimReaderSource != null) {
zimFileUri = zimReaderSource.toDatabase()
}
val navOptions = NavOptions.Builder()
.setLaunchSingleTop(true)
.setPopUpTo(readerFragmentRoute, inclusive = true)
.build()
val readerRouteWithArguments =
"$readerFragmentRoute?$PAGE_URL_KEY=$pageUrl&$ZIM_FILE_URI_KEY=$zimFileUri" +
"&$SHOULD_OPEN_IN_NEW_TAB=$shouldOpenInNewTab"
navigate(
readerRouteWithArguments,
navOptions
)
}
private fun openBookmarks() {
handleDrawerOnNavigation()

View File

@ -279,7 +279,6 @@ abstract class CoreReaderFragment :
onOpenLibraryButtonClicked = {},
pageLoadingItem = false to ZERO,
shouldShowDonationPopup = false,
// TODO set in onViewCreated.
fullScreenItem = false to null,
showBackToTopButton = false,
backToTopButtonClick = { backToTop() },
@ -441,11 +440,11 @@ abstract class CoreReaderFragment :
}
}
LaunchedEffect(Unit) {
addFullScreenItemIfNotAttached()
readerScreenState.update {
copy(
readerScreenTitle = context.getString(string.reader),
darkModeViewPainter = darkModeViewPainter,
fullScreenItem = fullScreenItem.first to getVideoView(),
tocButtonItem = getTocButtonStateAndAction(),
appName = (requireActivity() as CoreMainActivity).appName,
donateButtonClick = {
@ -1172,8 +1171,20 @@ abstract class CoreReaderFragment :
return null
}
/**
* Attached the full-screen item for videos in readerState if not already attached.
*/
private fun addFullScreenItemIfNotAttached() {
if (readerScreenState.value.fullScreenItem.second == null) {
readerScreenState.update {
copy(fullScreenItem = fullScreenItem.first to getVideoView())
}
}
}
@Throws(IllegalArgumentException::class)
protected open fun createWebView(attrs: AttributeSet?): KiwixWebView? {
addFullScreenItemIfNotAttached()
return KiwixWebView(
requireContext(),
this,

View File

@ -41,6 +41,7 @@ import org.kiwix.kiwixmobile.core.main.DrawerMenuItem
import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_ABOUT_APP_ITEM_TESTING_TAG
import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_SUPPORT_ITEM_TESTING_TAG
import org.kiwix.kiwixmobile.core.main.NEW_TAB_SHORTCUT_ID
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.utils.dialog.DialogHost
import org.kiwix.kiwixmobile.custom.BuildConfig
import org.kiwix.kiwixmobile.custom.R
@ -188,6 +189,30 @@ class CustomMainActivity : CoreMainActivity() {
)
}
override fun openPage(
pageUrl: String,
zimReaderSource: ZimReaderSource?,
shouldOpenInNewTab: Boolean
) {
var zimFileUri = ""
if (zimReaderSource != null) {
zimFileUri = zimReaderSource.toDatabase()
}
val navOptions = NavOptions.Builder()
.setLaunchSingleTop(true)
.setPopUpTo(readerFragmentRoute, inclusive = true)
.build()
val readerRoute = CustomDestination.Reader.createRoute(
zimFileUri = zimFileUri,
pageUrl = pageUrl,
shouldOpenInNewTab = shouldOpenInNewTab
)
navigate(
readerRoute,
navOptions
)
}
override fun hideBottomAppBar() {
// Do nothing since custom apps does not have the bottomAppBar.
}