1
1
package org.nekomanga.presentation.screens
2
2
3
3
import android.content.pm.ApplicationInfo
4
+ import android.graphics.Bitmap
4
5
import android.webkit.WebResourceRequest
5
6
import android.webkit.WebView
6
7
import androidx.compose.foundation.layout.Box
@@ -13,7 +14,10 @@ import androidx.compose.material.icons.automirrored.filled.ArrowForward
13
14
import androidx.compose.material.icons.filled.Close
14
15
import androidx.compose.material3.LinearProgressIndicator
15
16
import androidx.compose.runtime.Composable
17
+ import androidx.compose.runtime.getValue
18
+ import androidx.compose.runtime.mutableStateOf
16
19
import androidx.compose.runtime.remember
20
+ import androidx.compose.runtime.setValue
17
21
import androidx.compose.ui.Modifier
18
22
import androidx.compose.ui.platform.LocalContext
19
23
import androidx.compose.ui.res.stringResource
@@ -44,11 +48,14 @@ fun WebViewScreen(
44
48
) {
45
49
val context = LocalContext .current
46
50
val state = rememberWebViewState(url = url)
51
+
52
+ var currentUrl by remember { mutableStateOf(url) }
53
+
47
54
val navigator = rememberWebViewNavigator()
48
55
49
56
NekoScaffold (
50
57
title = title,
51
- subtitle = url ,
58
+ subtitle = currentUrl ,
52
59
type = NekoScaffoldType .TitleAndSubtitle ,
53
60
onNavigationIconClicked = onClose,
54
61
navigationIcon = Icons .Filled .Close ,
@@ -85,11 +92,11 @@ fun WebViewScreen(
85
92
),
86
93
AppBar .OverflowAction (
87
94
title = UiText .StringResource (R .string.share),
88
- onClick = { state.lastLoadedUrl?. let ( onShare) },
95
+ onClick = { onShare(currentUrl ) },
89
96
),
90
97
AppBar .OverflowAction (
91
98
title = UiText .StringResource (R .string.open_in_browser),
92
- onClick = { state.lastLoadedUrl?. let ( onOpenInBrowser) },
99
+ onClick = { onOpenInBrowser(currentUrl ) },
93
100
),
94
101
) +
95
102
listOf (
@@ -100,7 +107,7 @@ fun WebViewScreen(
100
107
) {
101
108
AppBar .OverflowAction (
102
109
title = UiText .StringResource (R .string.open_in_app),
103
- onClick = { state.lastLoadedUrl?. let ( onOpenInApp) },
110
+ onClick = { onOpenInApp(currentUrl ) },
104
111
)
105
112
} else {
106
113
AppBar .Empty
@@ -120,6 +127,21 @@ fun WebViewScreen(
120
127
121
128
val webClient = remember {
122
129
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
+
123
145
override fun shouldOverrideUrlLoading (
124
146
view : WebView ? ,
125
147
request : WebResourceRequest ? ,
0 commit comments