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
98918230
Commit
98918230
authored
Sep 05, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
5cc0312c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
113 deletions
+52
-113
NotificationPushUtil.kt
...in/java/com/base/browserwhite/fcm/NotificationPushUtil.kt
+1
-13
WebViewFragment.kt
...se/browserwhite/ui/activity/webbrowser/WebViewFragment.kt
+51
-100
No files found.
app/src/main/java/com/base/browserwhite/fcm/NotificationPushUtil.kt
View file @
98918230
package
com.base.browserwhite.fcm
package
com.base.browserwhite.fcm
import
android.content.Context
import
android.content.Context
import
android.os.Handler
import
android.os.HandlerThread
import
android.util.Log
import
android.util.Log
import
com.base.browserwhite.MyApplication
import
com.base.browserwhite.MyApplication
import
com.base.browserwhite.bean.ConstObject
import
com.base.browserwhite.bean.ConstObject.ID_APP_PROCESS
import
com.base.browserwhite.bean.ConstObject.ID_CLEAN_JUNK_MEMORY
import
com.base.browserwhite.bean.ConstObject.ID_JUNK_CLEANER
import
com.base.browserwhite.bean.ConstObject.ID_NEWS
import
com.base.browserwhite.bean.ConstObject.ID_WEATHER
import
com.base.browserwhite.help.EventUtils
import
com.base.browserwhite.help.EventUtils
import
com.base.browserwhite.utils.AppPreferences
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.TimeUtils.formatTimeH
import
com.base.browserwhite.utils.TimeUtils.isTimeBetweenEightAndTenPM
import
java.text.SimpleDateFormat
import
java.text.SimpleDateFormat
import
java.util.Calendar
import
java.util.Calendar
import
java.util.Locale
import
java.util.Locale
...
@@ -35,7 +23,7 @@ object NotificationPushUtil {
...
@@ -35,7 +23,7 @@ object NotificationPushUtil {
* @param where [PUSH_WHERE_TIMBER]
* @param where [PUSH_WHERE_TIMBER]
*/
*/
fun
Context
.
sendNotificationWhere
(
setActionId
:
Int
?,
where
:
String
)
{
fun
Context
.
sendNotificationWhere
(
setActionId
:
Int
?,
where
:
String
)
{
Log
.
d
(
"glc"
,
"sendNotificationW
here"
)
Log
.
d
(
"glc"
,
"sendNotificationWhere where=$w
here"
)
val
actionId
:
Int
=
setActionId
?:
NotificationHelp
.
getNotificationId
()
val
actionId
:
Int
=
setActionId
?:
NotificationHelp
.
getNotificationId
()
if
(
MyApplication
.
PAUSED_VALUE
==
1
)
{
if
(
MyApplication
.
PAUSED_VALUE
==
1
)
{
return
return
...
...
app/src/main/java/com/base/browserwhite/ui/activity/webbrowser/WebViewFragment.kt
View file @
98918230
...
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
...
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import
android.content.Context
import
android.content.Context
import
android.net.Uri
import
android.net.Uri
import
android.net.http.SslError
import
android.net.http.SslError
import
android.view.KeyEvent
import
android.view.View
import
android.view.View
import
android.webkit.CookieManager
import
android.webkit.CookieManager
import
android.webkit.JsResult
import
android.webkit.JsResult
...
@@ -17,6 +16,7 @@ import android.webkit.WebSettings
...
@@ -17,6 +16,7 @@ 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.core.view.isVisible
import
androidx.lifecycle.lifecycleScope
import
androidx.lifecycle.lifecycleScope
import
com.base.browserwhite.bean.BookmarkBean
import
com.base.browserwhite.bean.BookmarkBean
import
com.base.browserwhite.bean.DownloadBean
import
com.base.browserwhite.bean.DownloadBean
...
@@ -31,7 +31,6 @@ import com.base.browserwhite.utils.DownloadUtils.getDownloadJsonBean
...
@@ -31,7 +31,6 @@ import com.base.browserwhite.utils.DownloadUtils.getDownloadJsonBean
import
com.base.browserwhite.utils.DownloadUtils.saveDownloadRecordFile
import
com.base.browserwhite.utils.DownloadUtils.saveDownloadRecordFile
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.SpBeanUtils
import
com.base.browserwhite.utils.SpBeanUtils
import
com.base.browserwhite.utils.SpBeanUtils.BOOKMARK_SP_KEY
import
com.base.browserwhite.utils.SpBeanUtils.HISTORY_SP_KEY
import
com.base.browserwhite.utils.SpBeanUtils.HISTORY_SP_KEY
import
com.google.gson.Gson
import
com.google.gson.Gson
import
com.liulishuo.filedownloader.FileDownloader
import
com.liulishuo.filedownloader.FileDownloader
...
@@ -43,7 +42,6 @@ import okhttp3.Callback
...
@@ -43,7 +42,6 @@ import okhttp3.Callback
import
okhttp3.OkHttpClient
import
okhttp3.OkHttpClient
import
okhttp3.Request
import
okhttp3.Request
import
okhttp3.Response
import
okhttp3.Response
import
org.json.JSONArray
import
java.io.IOException
import
java.io.IOException
import
kotlin.random.Random
import
kotlin.random.Random
...
@@ -52,7 +50,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -52,7 +50,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
private
val
TAG
=
"WebViewFragment"
private
val
TAG
=
"WebViewFragment"
var
url
:
String
=
""
var
url
:
String
=
""
private
val
downloadList
=
arrayListOf
<
DownloadBean
>()
var
bookmarkBean
:
BookmarkBean
=
BookmarkBean
()
var
bookmarkBean
:
BookmarkBean
=
BookmarkBean
()
override
val
binding
:
FragmentWebViewBinding
by
lazy
{
override
val
binding
:
FragmentWebViewBinding
by
lazy
{
...
@@ -113,6 +111,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -113,6 +111,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
binding
.
webView
.
visibility
=
View
.
VISIBLE
binding
.
webView
.
visibility
=
View
.
VISIBLE
binding
.
progressBar
.
visibility
=
View
.
VISIBLE
binding
.
progressBar
.
visibility
=
View
.
VISIBLE
binding
.
progressBar
.
progress
=
0
binding
.
progressBar
.
progress
=
0
downloadList
.
clear
()
binding
.
webView
.
reload
()
binding
.
webView
.
reload
()
}
}
...
@@ -125,8 +124,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -125,8 +124,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
@SuppressLint
(
"SetJavaScriptEnabled"
)
@SuppressLint
(
"SetJavaScriptEnabled"
)
fun
initWebSettings
()
{
fun
initWebSettings
()
{
// binding.webView.isFocusableInTouchMode = true
// binding.webView.isFocusable = true
val
webSettings
=
binding
.
webView
.
settings
val
webSettings
=
binding
.
webView
.
settings
webSettings
.
allowFileAccess
=
true
// 设置允许访问文件数据
webSettings
.
allowFileAccess
=
true
// 设置允许访问文件数据
...
@@ -161,6 +158,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -161,6 +158,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
//设置WebChromeClient
//设置WebChromeClient
binding
.
webView
.
webChromeClient
=
object
:
WebChromeClient
()
{
binding
.
webView
.
webChromeClient
=
object
:
WebChromeClient
()
{
override
fun
onProgressChanged
(
view
:
WebView
,
newProgress
:
Int
)
{
override
fun
onProgressChanged
(
view
:
WebView
,
newProgress
:
Int
)
{
LogEx
.
logDebug
(
TAG
,
"onProgressChanged newProgress=$newProgress"
)
LogEx
.
logDebug
(
TAG
,
"onProgressChanged newProgress=$newProgress"
)
...
@@ -168,13 +166,11 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -168,13 +166,11 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
if
(
binding
.
progressBar
.
progress
>=
100
)
{
if
(
binding
.
progressBar
.
progress
>=
100
)
{
binding
.
progressBar
.
visibility
=
View
.
GONE
binding
.
progressBar
.
visibility
=
View
.
GONE
}
}
if
(
newProgress
==
100
)
{
parseVideoLink
(
view
)
}
}
}
override
fun
onReceivedTitle
(
view
:
WebView
?,
title
:
String
?)
{
override
fun
onReceivedTitle
(
view
:
WebView
?,
title
:
String
?)
{
super
.
onReceivedTitle
(
view
,
title
)
super
.
onReceivedTitle
(
view
,
title
)
bookmarkBean
.
name
=
title
?:
"about:black"
}
}
override
fun
onShowFileChooser
(
override
fun
onShowFileChooser
(
...
@@ -193,14 +189,16 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -193,14 +189,16 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
):
Boolean
=
true
):
Boolean
=
true
}
}
binding
.
webView
.
webViewClient
=
object
:
WebViewClient
()
{
binding
.
webView
.
webViewClient
=
object
:
WebViewClient
()
{
// override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
// LogEx.logDebug(TAG, "shouldOverrideUrlLoading")
// val url = request?.url.toString()
override
fun
onLoadResource
(
view
:
WebView
?,
url
:
String
?)
{
// binding.llError.visibility = View.GONE
super
.
onLoadResource
(
view
,
url
)
// bookmarkBean.url = url
if
(
url
?.
endsWith
(
".mp4"
)
==
true
)
{
// view?.loadUrl(url)
LogEx
.
logDebug
(
TAG
,
"onLoadResource url=$url"
)
// return true
addVideoLink
(
url
)
// }
}
}
override
fun
shouldOverrideUrlLoading
(
view
:
WebView
?,
request
:
WebResourceRequest
?):
Boolean
{
override
fun
shouldOverrideUrlLoading
(
view
:
WebView
?,
request
:
WebResourceRequest
?):
Boolean
{
return
super
.
shouldOverrideUrlLoading
(
view
,
request
)
return
super
.
shouldOverrideUrlLoading
(
view
,
request
)
}
}
...
@@ -244,29 +242,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -244,29 +242,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
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
)
return
return
// if (error?.errorCode == -1) {
// //-1 net::ERR_BLOCKED_BY_ORB 跨域读取不影响显示
// return
// }
// if (error?.errorCode == -6) {
// //-6 net::ERR_BLOCKED_BY_ORB 服务器拒绝连接,是服务的锅
// return
// }
// job?.cancel()
// binding.webView.visibility = View.GONE
// binding.llError.visibility = View.VISIBLE
// if (error != null) {
// // 获取错误码
// val errorCode = error.errorCode
// // 获取错误描述
// val description = error.description
//
// // 创建错误信息文本
// val errorText = "Error ${errorCode}: $description"
//
// // 打印错误信息,或者根据需要进行其他处理
// binding.tvErrorReason.text = errorText
// }
}
}
}
}
...
@@ -276,61 +251,44 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -276,61 +251,44 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
}
}
override
fun
onAttach
(
context
:
Context
)
{
override
fun
onAttach
(
context
:
Context
)
{
super
.
onAttach
(
context
)
super
.
onAttach
(
context
)
}
}
private
var
isParsing
:
Boolean
=
false
private
val
downloadList
=
arrayListOf
<
DownloadBean
>()
@SuppressLint
(
"NotifyDataSetChanged"
)
fun
parseVideoLink
(
view
:
WebView
)
{
if
(
isParsing
)
return
if
(
activity
==
null
)
return
isParsing
=
true
downloadList
.
clear
()
view
.
evaluateJavascript
(
"(function() {"
+
"var videos = document.querySelectorAll('video');"
+
"var videoSources = [];"
+
"for (var i = 0; i < videos.length; i++) {"
+
"var video = videos[i];"
+
"var src = video.src;"
+
"videoSources.push(src);"
+
"}"
+
"return videoSources;"
+
"}).call(this);"
,
ValueCallback
<
String
?>
{
value
->
// 这里处理获取到的视频链接数组
LogEx
.
logDebug
(
TAG
,
"value=$value"
)
// 将字符串转换为JSON数组,然后处理
val
jsonArray
=
JSONArray
(
value
)
@SuppressLint
(
"NotifyDataSetChanged"
)
fun
addVideoLink
(
addUri
:
String
)
{
val
olderList
=
arrayListOf
<
DownloadBean
>()
val
recordFile
=
requireContext
().
getDownloadJson
()
val
recordFile
=
requireContext
().
getDownloadJson
()
val
olderList
=
getDownloadJsonBean
(
recordFile
,
Gson
(
))
olderList
.
addAll
(
getDownloadJsonBean
(
recordFile
,
Gson
()
))
olderList
.
forEach
{
olderList
.
forEach
{
it
.
status
=
FileDownloader
.
getImpl
().
getStatus
(
it
.
downloadId
,
it
.
path
)
it
.
status
=
FileDownloader
.
getImpl
().
getStatus
(
it
.
downloadId
,
it
.
path
)
}
}
val
set
=
hashSetOf
<
String
>()
val
olderBean
=
olderList
.
findLast
{
it
.
url
==
addUri
}
for
(
i
in
0
until
jsonArray
.
length
())
{
val
videoUrl
=
jsonArray
.
optString
(
i
)
if
(
videoUrl
.
startsWith
(
"http"
)
||
videoUrl
.
startsWith
(
"https"
))
{
set
.
add
(
videoUrl
)
}
}
if
(
set
.
size
!=
0
)
{
binding
.
flDownload
.
visibility
=
View
.
VISIBLE
binding
.
tvDownloadNumber
.
text
=
set
.
size
.
toString
()
}
set
.
forEach
{
url
->
LogEx
.
logDebug
(
TAG
,
url
)
val
olderBean
=
olderList
.
findLast
{
it
.
url
==
url
}
if
(
olderBean
!=
null
)
{
if
(
olderBean
!=
null
)
{
LogEx
.
logDebug
(
TAG
,
"old path=${olderBean.path} ${olderBean.downloadId}"
)
LogEx
.
logDebug
(
TAG
,
"old path=${olderBean.path} ${olderBean.downloadId}"
)
downloadList
.
add
(
olderBean
.
apply
{
uiType
=
2
})
downloadList
.
add
(
olderBean
.
apply
{
uiType
=
2
})
}
else
{
}
else
{
downloadList
.
add
(
DownloadBean
(
url
=
url
).
apply
{
uiType
=
2
})
downloadList
.
add
(
DownloadBean
(
url
=
addUri
).
apply
{
name
=
addUri
.
split
(
"/"
).
last
()
uiType
=
2
})
}
}
binding
.
tvDownloadNumber
.
text
=
downloadList
.
size
.
toString
()
binding
.
flDownload
.
isVisible
=
downloadList
.
isNotEmpty
()
downloadList
.
forEach
{
LogEx
.
logDebug
(
TAG
,
"${it.url} ${it.size} ${it.downloadId} ${it.path}"
)
}
}
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
downloadList
.
forEach
{
downloadList
.
filter
{
it
.
size
<=
0
}
.
forEach
{
fastGetSize
(
it
)
fastGetSize
(
it
)
}
}
launch
(
Dispatchers
.
Main
)
{
launch
(
Dispatchers
.
Main
)
{
...
@@ -338,8 +296,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -338,8 +296,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
downloadAdapter
?.
notifyDataSetChanged
()
downloadAdapter
?.
notifyDataSetChanged
()
}
}
}
}
isParsing
=
false
})
}
}
...
@@ -361,11 +317,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -361,11 +317,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
}
}
fun
javascriptBack
()
{
binding
.
webView
.
evaluateJavascript
(
"window.history.back();"
,
null
)
}
private
fun
getSslErrorString
(
error
:
Int
):
String
{
private
fun
getSslErrorString
(
error
:
Int
):
String
{
return
when
(
error
)
{
return
when
(
error
)
{
SslError
.
SSL_DATE_INVALID
->
"Date Invalid: The certificate's date is incorrect or the certificate has expired."
SslError
.
SSL_DATE_INVALID
->
"Date Invalid: The certificate's date is incorrect or the certificate has expired."
...
...
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