Commit 98918230 authored by wanglei's avatar wanglei

...

parent 5cc0312c
package com.base.browserwhite.fcm
import android.content.Context
import android.os.Handler
import android.os.HandlerThread
import android.util.Log
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.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.util.Calendar
import java.util.Locale
......@@ -35,7 +23,7 @@ object NotificationPushUtil {
* @param where [PUSH_WHERE_TIMBER]
*/
fun Context.sendNotificationWhere(setActionId: Int?, where: String) {
Log.d("glc","sendNotificationWhere")
Log.d("glc", "sendNotificationWhere where=$where")
val actionId: Int = setActionId ?: NotificationHelp.getNotificationId()
if (MyApplication.PAUSED_VALUE == 1) {
return
......
......@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.content.Context
import android.net.Uri
import android.net.http.SslError
import android.view.KeyEvent
import android.view.View
import android.webkit.CookieManager
import android.webkit.JsResult
......@@ -17,6 +16,7 @@ import android.webkit.WebSettings
import android.webkit.WebStorage
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import com.base.browserwhite.bean.BookmarkBean
import com.base.browserwhite.bean.DownloadBean
......@@ -31,7 +31,6 @@ import com.base.browserwhite.utils.DownloadUtils.getDownloadJsonBean
import com.base.browserwhite.utils.DownloadUtils.saveDownloadRecordFile
import com.base.browserwhite.utils.LogEx
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.google.gson.Gson
import com.liulishuo.filedownloader.FileDownloader
......@@ -43,7 +42,6 @@ import okhttp3.Callback
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.json.JSONArray
import java.io.IOException
import kotlin.random.Random
......@@ -52,7 +50,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
private val TAG = "WebViewFragment"
var url: String = ""
private val downloadList = arrayListOf<DownloadBean>()
var bookmarkBean: BookmarkBean = BookmarkBean()
override val binding: FragmentWebViewBinding by lazy {
......@@ -113,6 +111,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
binding.webView.visibility = View.VISIBLE
binding.progressBar.visibility = View.VISIBLE
binding.progressBar.progress = 0
downloadList.clear()
binding.webView.reload()
}
......@@ -125,8 +124,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
@SuppressLint("SetJavaScriptEnabled")
fun initWebSettings() {
// binding.webView.isFocusableInTouchMode = true
// binding.webView.isFocusable = true
val webSettings = binding.webView.settings
webSettings.allowFileAccess = true// 设置允许访问文件数据
......@@ -161,6 +158,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
//设置WebChromeClient
binding.webView.webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView, newProgress: Int) {
LogEx.logDebug(TAG, "onProgressChanged newProgress=$newProgress")
......@@ -168,13 +166,11 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
if (binding.progressBar.progress >= 100) {
binding.progressBar.visibility = View.GONE
}
if (newProgress == 100) {
parseVideoLink(view)
}
}
override fun onReceivedTitle(view: WebView?, title: String?) {
super.onReceivedTitle(view, title)
bookmarkBean.name = title ?: "about:black"
}
override fun onShowFileChooser(
......@@ -193,14 +189,16 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
): Boolean = true
}
binding.webView.webViewClient = object : WebViewClient() {
// override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
// LogEx.logDebug(TAG, "shouldOverrideUrlLoading")
// val url = request?.url.toString()
// binding.llError.visibility = View.GONE
// bookmarkBean.url = url
// view?.loadUrl(url)
// return true
// }
override fun onLoadResource(view: WebView?, url: String?) {
super.onLoadResource(view, url)
if (url?.endsWith(".mp4") == true) {
LogEx.logDebug(TAG, "onLoadResource url=$url")
addVideoLink(url)
}
}
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
return super.shouldOverrideUrlLoading(view, request)
}
......@@ -244,29 +242,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
LogEx.logDebug(TAG, "onReceivedError ${error?.errorCode} ${error?.description}")
super.onReceivedError(view, request, error)
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,70 +251,51 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
}
override fun onAttach(context: 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)
val recordFile = requireContext().getDownloadJson()
val olderList = getDownloadJsonBean(recordFile, Gson())
olderList.forEach {
it.status = FileDownloader.getImpl().getStatus(it.downloadId, it.path)
}
fun addVideoLink(addUri: String) {
val olderList = arrayListOf<DownloadBean>()
val recordFile = requireContext().getDownloadJson()
olderList.addAll(getDownloadJsonBean(recordFile, Gson()))
olderList.forEach {
it.status = FileDownloader.getImpl().getStatus(it.downloadId, it.path)
}
val set = hashSetOf<String>()
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) {
LogEx.logDebug(TAG, "old path=${olderBean.path} ${olderBean.downloadId}")
downloadList.add(olderBean.apply { uiType = 2 })
} else {
downloadList.add(DownloadBean(url = url).apply { uiType = 2 })
}
val olderBean = olderList.findLast { it.url == addUri }
if (olderBean != null) {
LogEx.logDebug(TAG, "old path=${olderBean.path} ${olderBean.downloadId}")
downloadList.add(olderBean.apply { uiType = 2 })
} else {
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) {
downloadList.filter { it.size <= 0 }.forEach {
fastGetSize(it)
}
lifecycleScope.launch(Dispatchers.IO) {
downloadList.forEach {
fastGetSize(it)
}
launch(Dispatchers.Main) {
downloadAdapter?.submitList(downloadList)
downloadAdapter?.notifyDataSetChanged()
}
launch(Dispatchers.Main) {
downloadAdapter?.submitList(downloadList)
downloadAdapter?.notifyDataSetChanged()
}
isParsing = false
})
}
}
......@@ -361,11 +317,6 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
}
fun javascriptBack() {
binding.webView.evaluateJavascript("window.history.back();", null)
}
private fun getSslErrorString(error: Int): String {
return when (error) {
SslError.SSL_DATE_INVALID -> "Date Invalid: The certificate's date is incorrect or the certificate has expired."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment