diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt index ab90a1f8d..343bac732 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt @@ -256,7 +256,7 @@ class KiwixReaderFragment : CoreReaderFragment() { override fun createWebView(attrs: AttributeSet): ToolbarScrollingKiwixWebView { return ToolbarScrollingKiwixWebView( - activity, this, attrs, activityMainRoot as ViewGroup, videoView, + requireContext(), this, attrs, activityMainRoot as ViewGroup, videoView, CoreWebViewClient(this, zimReaderContainer), toolbarContainer, bottomToolbar, requireActivity().bottom_nav_view, sharedPreferenceUtil diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/ToolbarScrollingKiwixWebView.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/ToolbarScrollingKiwixWebView.kt index b31ef708d..93e23d80a 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/ToolbarScrollingKiwixWebView.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/ToolbarScrollingKiwixWebView.kt @@ -28,27 +28,27 @@ import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil @SuppressLint("ViewConstructor") class ToolbarScrollingKiwixWebView( - context: Context?, - callback: WebViewCallback?, - attrs: AttributeSet?, - nonVideoView: ViewGroup?, - videoView: ViewGroup?, - webViewClient: CoreWebViewClient?, + context: Context, + callback: WebViewCallback, + attrs: AttributeSet, + nonVideoView: ViewGroup, + videoView: ViewGroup, + webViewClient: CoreWebViewClient, private val toolbarView: View, private val bottomBarView: View, override var sharedPreferenceUtil: SharedPreferenceUtil -) : KiwixWebView(context!!, callback!!, attrs!!, nonVideoView!!, videoView!!, webViewClient!!) { +) : KiwixWebView(context, callback, attrs, nonVideoView, videoView, webViewClient) { private val toolbarHeight = getContext().getToolbarHeight() private var parentNavigationBar: View? = null private var startY = 0f constructor( - context: Context?, - callback: WebViewCallback?, - attrs: AttributeSet?, - nonVideoView: ViewGroup?, - videoView: ViewGroup?, - webViewClient: CoreWebViewClient?, + context: Context, + callback: WebViewCallback, + attrs: AttributeSet, + nonVideoView: ViewGroup, + videoView: ViewGroup, + webViewClient: CoreWebViewClient, toolbarView: View, bottomBarView: View, parentNavigationBar: View?, @@ -60,6 +60,10 @@ class ToolbarScrollingKiwixWebView( this.parentNavigationBar = parentNavigationBar } + init { + fixInitalScrollingIssue() + } + /** * The webview needs to be scrolled with 0 to not be slightly hidden on startup. * See https://github.com/kiwix/kiwix-android/issues/2304 for issue description. @@ -69,9 +73,8 @@ class ToolbarScrollingKiwixWebView( } private fun moveToolbar(scrollDelta: Int): Boolean { - val newTranslation: Float val originalTranslation = toolbarView.translationY - newTranslation = if (scrollDelta > 0) { + val newTranslation = if (scrollDelta > 0) { // scroll down Math.max(-toolbarHeight.toFloat(), originalTranslation - scrollDelta) } else { @@ -81,9 +84,8 @@ class ToolbarScrollingKiwixWebView( toolbarView.translationY = newTranslation bottomBarView.translationY = newTranslation * -1 * (bottomBarView.height / toolbarHeight.toFloat()) - if (parentNavigationBar != null) { - parentNavigationBar!!.translationY = - newTranslation * -1 * (parentNavigationBar!!.height / toolbarHeight.toFloat()) + parentNavigationBar?.let { + it.translationY = newTranslation * -1 * (it.height / toolbarHeight.toFloat()) } this.translationY = newTranslation + toolbarHeight return toolbarHeight + newTranslation != 0f && newTranslation != 0f @@ -129,8 +131,4 @@ class ToolbarScrollingKiwixWebView( private fun ensureToolbarHidden() { moveToolbar(toolbarHeight) } - - init { - fixInitalScrollingIssue() - } }