Commit 3fa3215f authored by wanglei's avatar wanglei

...

parent 0005e330
......@@ -98,6 +98,7 @@ dependencies {
implementation("de.hdodenhof:circleimageview:3.1.0")
implementation("com.github.pokercc:ExpandableRecyclerView:0.9.3")
implementation("io.github.cymchad:BaseRecyclerViewAdapterHelper4:4.1.4")
implementation("com.mikhaellopez:circularprogressbar:3.1.0")
//相机
val cameraxVersion = "1.2.2"
......
......@@ -132,6 +132,10 @@
android:name=".service.StayNotificationService"
android:foregroundServiceType="dataSync" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
......
package com.base.browserwhite.ui.activity.webbrowser
import android.annotation.SuppressLint
import android.app.DownloadManager
import android.net.Uri
import android.net.http.SslError
import android.view.View
......@@ -21,22 +22,27 @@ import com.base.browserwhite.databinding.FragmentWebViewBinding
import com.base.browserwhite.ui.adapter.DownloadAdapter
import com.base.browserwhite.ui.fragment.BaseFragment
import com.base.browserwhite.ui.views.DialogViews.showDownloadVideoDialog
import com.base.browserwhite.utils.DownloadHelper.getDownloadJson
import com.base.browserwhite.utils.DownloadHelper.getOlderList
import com.base.browserwhite.utils.LogEx
import com.base.browserwhite.utils.VideoDownloader
import com.base.browserwhite.utils.VideoDownloader.queryDownloadProgress
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.json.JSONArray
import java.io.File
import java.lang.reflect.Type
import kotlin.random.Random
class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
private val TAG = "WebViewFragment"
private var progressJob: Job? = null
var url: String = ""
private val downloadList = arrayListOf<DownloadBean>()
......@@ -81,31 +87,58 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
bean.path = pair.second.absolutePath
},
dismissAction = {
progressJob?.cancel()
isUpdating = false
saveDownloadRecordFile(downloadList)
},
)
progressJob?.cancel()
progressJob = upDataProgress(adapter)
isUpdating = true
upDataProgress(adapter)
}
}
private fun saveDownloadRecordFile(downloadList: ArrayList<DownloadBean>) = lifecycleScope.launch(Dispatchers.IO) {
val recordFile = requireContext().getDownloadJson()
val gson = Gson()
val list = downloadList.filter {
it.state == DownloadManager.STATUS_RUNNING ||
it.state == DownloadManager.STATUS_PAUSED ||
it.state == DownloadManager.STATUS_SUCCESSFUL
}
val olderList = getOlderList(recordFile, gson).filter { !list.contains(it) }
val arrayList = arrayListOf<DownloadBean>()
arrayList.addAll(olderList)
arrayList.addAll(list)
val json = gson.toJson(list)
recordFile.writeText(json)
}
private var isUpdating = false
@SuppressLint("NotifyDataSetChanged")
private fun upDataProgress(adapter: DownloadAdapter) = lifecycleScope.launch(Dispatchers.IO) {
private fun upDataProgress(adapter: DownloadAdapter) = Thread {
while (isActive) {
downloadList.forEach { bean: DownloadBean ->
while (isUpdating) {
downloadList.filter { it.state == DownloadManager.STATUS_RUNNING }.forEach { bean: DownloadBean ->
queryDownloadProgress(requireContext(), bean.downloadId,
uiAction = { progress ->
LogEx.logDebug(TAG, "item ${bean.downloadId} progress=$progress ")
bean.progress = progress
},
noRunningAction = { status ->
bean.state = status
})
}
binding.root.post {
adapter.notifyDataSetChanged()
delay(1000)
}
Thread.sleep(250)
}
}.start()
private fun reloadWebView() {
binding.llError.visibility = View.GONE
......@@ -161,7 +194,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
//设置WebChromeClient
binding.webView.webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView, newProgress: Int) {
LogEx.logDebug(TAG, "onProgressChanged newProgress=$newProgress")
// LogEx.logDebug(TAG, "onProgressChanged newProgress=$newProgress")
binding.progressBar.progress = newProgress + 15
if (binding.progressBar.progress >= 100) {
......@@ -279,12 +312,18 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
binding.flDownload.visibility = View.VISIBLE
binding.tvDownloadNumber.text = jsonArray.length().toString()
}
val recordFile = requireContext().getDownloadJson()
val olderList = getOlderList(recordFile, Gson())
for (i in 0 until jsonArray.length()) {
val videoUrl = jsonArray.optString(i)
LogEx.logDebug(TAG, videoUrl)
val olderBean = olderList.findLast { it.uri == videoUrl }
if (olderBean != null) {
downloadList.add(olderBean)
} else {
downloadList.add(DownloadBean(uri = videoUrl).apply { uiType = 2 })
}
}
isParsing = false
})
......
package com.base.browserwhite.ui.adapter
import android.app.DownloadManager
import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.browserwhite.R
import com.base.browserwhite.bean.DownloadBean
......@@ -36,10 +38,34 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
} else if (item.uiType == 2) {
val binding = ItemDownloadCardBinding.bind(holder.itemView)
Glide.with(context).load(item.uri).centerCrop().into(binding.iv)
binding.tvName.text = item.uri.split("/").last()
binding.tvName.text = if (item.name.isNotEmpty()) item.name else item.uri.split("/").last()
binding.ivDownload.isVisible = item.downloadId == -1L
binding.flDownload.isVisible = item.downloadId != -1L
binding.ivFinish.isVisible = false
when (item.state) {
DownloadManager.STATUS_PAUSED -> {
binding.ivXiazaiZantin.setImageResource(R.mipmap.zanting_download)
binding.circularProgressBar.progress = item.progress.toFloat()
}
DownloadManager.STATUS_RUNNING -> {
binding.ivXiazaiZantin.setImageResource(R.mipmap.xiazhaiz_download)
binding.circularProgressBar.progress = item.progress.toFloat()
}
DownloadManager.STATUS_SUCCESSFUL -> {
binding.flDownload.isVisible = false
binding.ivFinish.isVisible = true
}
}
binding.ivDownload.setOnClickListener {
downloadAction?.invoke(item)
}
}
}
......
......@@ -195,6 +195,12 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
}
binding.colorProgress.finishAnimation = {
initMediaData()
}
}
private fun initMediaData() = Thread {
val list = requireContext().getMediaFile().filter {
val file = File(it.path)
if (BuildConfig.DEBUG) {
......@@ -203,13 +209,13 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
System.currentTimeMillis() - file.lastModified() <= 15L * 24 * 60 * 60 * 1000
}
}
binding.root.post {
if (list.isEmpty()) {
binding.tvTitleRecent.visibility = View.GONE
}
adapter.setData(list)
}
}
}.start()
}
\ No newline at end of file
package com.base.browserwhite.ui.views
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.AnimatorSet
import android.animation.ValueAnimator
import android.content.Context
import android.graphics.Canvas
......
......@@ -3,6 +3,7 @@ package com.base.browserwhite.ui.views
import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.Dialog
import android.app.DownloadManager
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
......@@ -253,6 +254,7 @@ object DialogViews {
adapter.downloadAction = { item: DownloadBean ->
dialog.dismiss()
showDownloadConfirmDialog(item) {
item.state = DownloadManager.STATUS_RUNNING
download.invoke(item)
}
}
......
package com.base.browserwhite.utils
import android.annotation.SuppressLint
import android.app.DownloadManager
import android.content.Context
import com.base.browserwhite.bean.DownloadBean
import com.base.browserwhite.ui.adapter.DownloadAdapter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.io.File
import java.lang.reflect.Type
object DownloadHelper {
fun Context.getDownloadJson(): File {
val file = File(this.filesDir, "downloadRecord")
val recordFile = File(file, "download.json")
if (!file.exists()) {
file.mkdirs()
}
if (!recordFile.exists()) {
recordFile.createNewFile()
}
return recordFile
}
fun getOlderList(recordFile: File, gson: Gson): List<DownloadBean> {
val olderText = recordFile.readText()
val type: Type = object : TypeToken<List<DownloadBean>>() {}.type
return gson.fromJson(olderText, type) ?: listOf()
}
}
\ No newline at end of file
package com.base.browserwhite.utils
import android.view.View
internal fun View.scale(factor: Float) {
scaleX = factor
scaleY = factor
}
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<!-- <stroke-->
<!-- android:width="1px"-->
<!-- android:color="#FF3835" />-->
<solid android:color="#E8E8F1" />
<corners android:radius="10dp" />
</shape>
</item>
<item android:id="@android:id/progress">
<scale android:scaleWidth="100%">
<shape>
<corners android:radius="10dp" />
<solid android:color="#0571ED" />
</shape>
</scale>
</item>
</layer-list>
\ No newline at end of file
......@@ -80,20 +80,31 @@
android:visibility="gone"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_finish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/t_wancheng_download"
android:visibility="gone"
tools:ignore="ContentDescription" />
<FrameLayout
android:visibility="gone"
android:id="@+id/fl_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="35dp"
android:layout_height="35dp"
android:indeterminate="false"
android:max="100"
android:progressDrawable="@drawable/progress_bar_clean"
tools:progress="50" />
<com.mikhaellopez.circularprogressbar.CircularProgressBar
android:id="@+id/circularProgressBar"
android:layout_width="30dp"
android:layout_height="30dp"
app:cpb_background_progressbar_color="#E8E8F1"
app:cpb_background_progressbar_width="3dp"
app:cpb_progress_direction="to_left"
app:cpb_progress_max="100"
app:cpb_progressbar_color="#0570EC"
app:cpb_progressbar_width="3dp"
app:cpb_round_border="true" />
<ImageView
android:id="@+id/iv_xiazai_zantin"
......
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