Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
B
Browser White
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
Browser White
Commits
72b3dc78
Commit
72b3dc78
authored
Aug 16, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
012a9eb7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
26 deletions
+39
-26
WebViewFragment.kt
...java/com/base/browserwhite/ui/fragment/WebViewFragment.kt
+36
-24
fragment_web_view.xml
app/src/main/res/layout/fragment_web_view.xml
+3
-2
No files found.
app/src/main/java/com/base/browserwhite/ui/fragment/WebViewFragment.kt
View file @
72b3dc78
...
@@ -16,16 +16,19 @@ import android.webkit.WebSettings
...
@@ -16,16 +16,19 @@ import android.webkit.WebSettings
import
android.webkit.WebStorage
import
android.webkit.WebStorage
import
android.webkit.WebView
import
android.webkit.WebView
import
android.webkit.WebViewClient
import
android.webkit.WebViewClient
import
androidx.lifecycle.lifecycleScope
import
com.base.browserwhite.databinding.FragmentWebViewBinding
import
com.base.browserwhite.databinding.FragmentWebViewBinding
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.LogEx
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
import
kotlin.random.Random
class
WebViewFragment
(
val
url
:
String
)
:
BaseFragment
<
FragmentWebViewBinding
>()
{
class
WebViewFragment
(
val
url
:
String
)
:
BaseFragment
<
FragmentWebViewBinding
>()
{
private
val
TAG
=
"WebViewFragment"
private
val
TAG
=
"WebViewFragment"
private
var
job
:
Job
?
=
null
private
var
job
:
Job
?
=
null
private
var
searchAction
:
(
context
:
String
)
->
String
=
HomeFragment
.
Companion
::
getBaiduSearch
override
val
binding
:
FragmentWebViewBinding
by
lazy
{
override
val
binding
:
FragmentWebViewBinding
by
lazy
{
FragmentWebViewBinding
.
inflate
(
layoutInflater
)
FragmentWebViewBinding
.
inflate
(
layoutInflater
)
...
@@ -44,6 +47,14 @@ class WebViewFragment(val url: String) : BaseFragment<FragmentWebViewBinding>()
...
@@ -44,6 +47,14 @@ class WebViewFragment(val url: String) : BaseFragment<FragmentWebViewBinding>()
binding
.
tvReload
.
setOnClickListener
{
binding
.
tvReload
.
setOnClickListener
{
reloadWebView
()
reloadWebView
()
}
}
binding
.
refreshLayout
.
setOnRefreshListener
{
lifecycleScope
.
launch
{
binding
.
refreshLayout
.
isRefreshing
=
true
delay
(
Random
.
nextLong
(
1500
,
2500
))
binding
.
refreshLayout
.
isRefreshing
=
false
}
reloadWebView
()
}
}
}
private
fun
reloadWebView
()
{
private
fun
reloadWebView
()
{
...
@@ -161,29 +172,30 @@ class WebViewFragment(val url: String) : BaseFragment<FragmentWebViewBinding>()
...
@@ -161,29 +172,30 @@ class WebViewFragment(val url: String) : BaseFragment<FragmentWebViewBinding>()
override
fun
onReceivedError
(
view
:
WebView
?,
request
:
WebResourceRequest
?,
error
:
WebResourceError
?)
{
override
fun
onReceivedError
(
view
:
WebView
?,
request
:
WebResourceRequest
?,
error
:
WebResourceError
?)
{
LogEx
.
logDebug
(
TAG
,
"onReceivedError ${error?.errorCode} ${error?.description}"
)
LogEx
.
logDebug
(
TAG
,
"onReceivedError ${error?.errorCode} ${error?.description}"
)
super
.
onReceivedError
(
view
,
request
,
error
)
super
.
onReceivedError
(
view
,
request
,
error
)
if
(
error
?.
errorCode
==
-
1
)
{
return
//-1 net::ERR_BLOCKED_BY_ORB 跨域读取不影响显示
// if (error?.errorCode == -1) {
return
// //-1 net::ERR_BLOCKED_BY_ORB 跨域读取不影响显示
}
// return
if
(
error
?.
errorCode
==
-
6
)
{
// }
//-6 net::ERR_BLOCKED_BY_ORB 服务器拒绝连接,是服务的锅
// if (error?.errorCode == -6) {
return
// //-6 net::ERR_BLOCKED_BY_ORB 服务器拒绝连接,是服务的锅
}
// return
job
?.
cancel
()
// }
binding
.
webView
.
visibility
=
View
.
GONE
// job?.cancel()
binding
.
llError
.
visibility
=
View
.
VISIBLE
// binding.webView.visibility = View.GONE
if
(
error
!=
null
)
{
// binding.llError.visibility = View.VISIBLE
// 获取错误码
// if (error != null) {
val
errorCode
=
error
.
errorCode
// // 获取错误码
// 获取错误描述
// val errorCode = error.errorCode
val
description
=
error
.
description
// // 获取错误描述
// val description = error.description
// 创建错误信息文本
//
val
errorText
=
"Error ${errorCode}: $description"
// // 创建错误信息文本
// val errorText = "Error ${errorCode}: $description"
// 打印错误信息,或者根据需要进行其他处理
//
binding
.
tvErrorReason
.
text
=
errorText
// // 打印错误信息,或者根据需要进行其他处理
}
// binding.tvErrorReason.text = errorText
// }
}
}
}
}
...
...
app/src/main/res/layout/fragment_web_view.xml
View file @
72b3dc78
...
@@ -16,8 +16,9 @@
...
@@ -16,8 +16,9 @@
android:progressDrawable=
"@drawable/progress_bar_web"
android:progressDrawable=
"@drawable/progress_bar_web"
tools:progress=
"50"
/>
tools:progress=
"50"
/>
<
Frame
Layout
<
androidx.swiperefreshlayout.widget.SwipeRefresh
Layout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:id=
"@+id/refresh_layout"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
>
<WebView
<WebView
...
@@ -77,7 +78,7 @@
...
@@ -77,7 +78,7 @@
</LinearLayout>
</LinearLayout>
</
Frame
Layout>
</
androidx.swiperefreshlayout.widget.SwipeRefresh
Layout>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment