Skip to content

Commit 0420ca2

Browse files
committed
Fix webview subtitle not matching the actual page
1 parent ce92a28 commit 0420ca2

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

app/src/main/java/org/nekomanga/presentation/screens/WebViewScreen.kt

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.nekomanga.presentation.screens
22

33
import android.content.pm.ApplicationInfo
4+
import android.graphics.Bitmap
45
import android.webkit.WebResourceRequest
56
import android.webkit.WebView
67
import androidx.compose.foundation.layout.Box
@@ -13,7 +14,10 @@ import androidx.compose.material.icons.automirrored.filled.ArrowForward
1314
import androidx.compose.material.icons.filled.Close
1415
import androidx.compose.material3.LinearProgressIndicator
1516
import androidx.compose.runtime.Composable
17+
import androidx.compose.runtime.getValue
18+
import androidx.compose.runtime.mutableStateOf
1619
import androidx.compose.runtime.remember
20+
import androidx.compose.runtime.setValue
1721
import androidx.compose.ui.Modifier
1822
import androidx.compose.ui.platform.LocalContext
1923
import androidx.compose.ui.res.stringResource
@@ -44,11 +48,14 @@ fun WebViewScreen(
4448
) {
4549
val context = LocalContext.current
4650
val state = rememberWebViewState(url = url)
51+
52+
var currentUrl by remember { mutableStateOf(url) }
53+
4754
val navigator = rememberWebViewNavigator()
4855

4956
NekoScaffold(
5057
title = title,
51-
subtitle = url,
58+
subtitle = currentUrl,
5259
type = NekoScaffoldType.TitleAndSubtitle,
5360
onNavigationIconClicked = onClose,
5461
navigationIcon = Icons.Filled.Close,
@@ -85,11 +92,11 @@ fun WebViewScreen(
8592
),
8693
AppBar.OverflowAction(
8794
title = UiText.StringResource(R.string.share),
88-
onClick = { state.lastLoadedUrl?.let(onShare) },
95+
onClick = { onShare(currentUrl) },
8996
),
9097
AppBar.OverflowAction(
9198
title = UiText.StringResource(R.string.open_in_browser),
92-
onClick = { state.lastLoadedUrl?.let(onOpenInBrowser) },
99+
onClick = { onOpenInBrowser(currentUrl) },
93100
),
94101
) +
95102
listOf(
@@ -100,7 +107,7 @@ fun WebViewScreen(
100107
) {
101108
AppBar.OverflowAction(
102109
title = UiText.StringResource(R.string.open_in_app),
103-
onClick = { state.lastLoadedUrl?.let(onOpenInApp) },
110+
onClick = { onOpenInApp(currentUrl) },
104111
)
105112
} else {
106113
AppBar.Empty
@@ -120,6 +127,21 @@ fun WebViewScreen(
120127

121128
val webClient = remember {
122129
object : AccompanistWebViewClient() {
130+
131+
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
132+
super.onPageStarted(view, url, favicon)
133+
url?.let { currentUrl = it }
134+
}
135+
136+
override fun doUpdateVisitedHistory(
137+
view: WebView,
138+
url: String?,
139+
isReload: Boolean,
140+
) {
141+
super.doUpdateVisitedHistory(view, url, isReload)
142+
url?.let { currentUrl = it }
143+
}
144+
123145
override fun shouldOverrideUrlLoading(
124146
view: WebView?,
125147
request: WebResourceRequest?,

0 commit comments

Comments
 (0)