Commit edb705a6 authored by wanglei's avatar wanglei

...

parent 45007791
......@@ -85,10 +85,9 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
val binding = ItemDownloadBinding.bind(holder.itemView)
if (payloads.isNullOrEmpty()) {
val file = File(item.path)
Glide.with(context).load(item.url).centerCrop().into(binding.iv)
binding.tvName.text = file.name
binding.tvSize.text = file.length().toFormatSize()
binding.tvName.text = item.name
binding.tvSize.text = item.size.toFormatSize()
when (item.status) {
FileDownloadStatus.completed -> {
binding.flMore.visibility = View.VISIBLE
......@@ -99,12 +98,14 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
binding.flMore.visibility = View.GONE
binding.flDownload.visibility = View.VISIBLE
binding.circularProgressBar.progress = item.progress.toFloat()
binding.ivXiazaiZantin.setImageResource(R.mipmap.zanting_download)
}
FileDownloadStatus.progress -> {
binding.flMore.visibility = View.GONE
binding.flDownload.visibility = View.VISIBLE
binding.circularProgressBar.progress = item.progress.toFloat()
binding.ivXiazaiZantin.setImageResource(R.mipmap.xiazhaiz_download)
replaceListener(item, position)
}
}
......@@ -125,12 +126,14 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
binding.flMore.visibility = View.GONE
binding.flDownload.visibility = View.VISIBLE
binding.circularProgressBar.progress = item.progress.toFloat()
binding.ivXiazaiZantin.setImageResource(R.mipmap.zanting_download)
}
FileDownloadStatus.progress -> {
binding.flMore.visibility = View.GONE
binding.flDownload.visibility = View.VISIBLE
binding.circularProgressBar.progress = item.progress.toFloat()
binding.ivXiazaiZantin.setImageResource(R.mipmap.xiazhaiz_download)
replaceListener(item, position)
}
}
......@@ -292,6 +295,7 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
}
override fun completed(task: BaseDownloadTask?) {
LogEx.logDebug(TAG, "completed tag=$tag item=${item.downloadId} ${item.path}")
item.progress = 100
item.status = FileDownloader.getImpl().getStatus(item.url, item.path)
item.time = System.currentTimeMillis()
......@@ -303,6 +307,7 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
val percent = soFarBytes * 100 / totalBytes
item.progress = abs(percent)
item.status = FileDownloadStatus.paused
item.time = System.currentTimeMillis()
notifyItemChanged(position, "aaa")
}
......
......@@ -18,16 +18,17 @@ import com.base.browserwhite.utils.DownloadHelper.getDownloadJsonBean
import com.base.browserwhite.utils.DownloadHelper.saveDownloadRecordFile
import com.base.browserwhite.utils.IntentEx.shareAction
import com.base.browserwhite.utils.KotlinExt.toFormatTime
import com.base.browserwhite.utils.LogEx
import com.base.browserwhite.utils.PermissionHelp.checkStorePermission
import com.base.browserwhite.utils.PermissionHelp.requestStorePermission
import com.google.gson.Gson
import com.liulishuo.filedownloader.FileDownloader
import com.liulishuo.filedownloader.model.FileDownloadStatus
import java.io.File
class WebDownloadManagerActivity : BaseActivity<ActivityWebDownloadManagerBinding>() {
private lateinit var adapter: DownloadAdapter
private val TAG = "WebDownloadManagerActivity"
override val binding: ActivityWebDownloadManagerBinding by lazy {
ActivityWebDownloadManagerBinding.inflate(layoutInflater)
......@@ -44,19 +45,16 @@ class WebDownloadManagerActivity : BaseActivity<ActivityWebDownloadManagerBindin
showMediaMoreDialog(archView,
deleteAction = {
showDeleteTipDialog {
adapter.items.forEach {
LogEx.logDebug(TAG, "${it.isTime} ${it.time.toFormatTime()} ${it.path}")
}
runCatching {
File(item.path).delete()
saveDeleteJson(item)
}
adapter.remove(item)
val list = adapter.items.filter { !it.isTime && it.time == item.time }
if (list.isEmpty()) {
adapter.items.filter { it.isTime && it.time == item.time }.forEach { timeBean ->
adapter.remove(timeBean)
}
binding.llEmpty.isVisible = adapter.items.isEmpty()
}
removeTimeDean(item)
}
},
shareAction = {
......@@ -77,6 +75,17 @@ class WebDownloadManagerActivity : BaseActivity<ActivityWebDownloadManagerBindin
}
}
private fun removeTimeDean(item: DownloadBean) {
val list = adapter.items.filter { !it.isTime && it.time.toFormatTime() == item.time.toFormatTime() }
if (list.isEmpty()) {
adapter.items.filter { it.isTime && it.time.toFormatTime() == item.time.toFormatTime() }.forEach { timeBean ->
adapter.remove(timeBean)
}
binding.llEmpty.isVisible = adapter.items.isEmpty()
}
}
private fun saveDeleteJson(item: DownloadBean) {
val recordFile = getDownloadJson()
val list = getDownloadJsonBean(recordFile).toMutableList()
......@@ -127,10 +136,10 @@ class WebDownloadManagerActivity : BaseActivity<ActivityWebDownloadManagerBindin
override fun onPause() {
super.onPause()
this.saveDownloadRecordFile(adapter.items)
}
override fun onDestroy() {
super.onDestroy()
this.saveDownloadRecordFile(adapter.items)
}
}
\ No newline at end of file
......@@ -26,6 +26,7 @@ import com.base.browserwhite.utils.DownloadHelper.getDownloadJsonBean
import com.base.browserwhite.utils.DownloadHelper.saveDownloadRecordFile
import com.base.browserwhite.utils.LogEx
import com.google.gson.Gson
import com.liulishuo.filedownloader.FileDownloader
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
......@@ -151,7 +152,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) {
......@@ -268,6 +269,9 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
val recordFile = requireContext().getDownloadJson()
val olderList = 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()) {
......@@ -294,6 +298,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
}
launch(Dispatchers.Main) {
downloadAdapter?.submitList(downloadList)
downloadAdapter?.notifyDataSetChanged()
}
}
isParsing = false
......
......@@ -8,6 +8,7 @@ import com.base.browserwhite.bean.DownloadBean
import com.base.browserwhite.bean.downloadBeanGson
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.liulishuo.filedownloader.FileDownloader
import com.liulishuo.filedownloader.model.FileDownloadStatus
import java.io.File
import java.lang.reflect.Type
......@@ -77,15 +78,14 @@ object DownloadHelper {
//已开始的任务
val startedList = downloadList.filter {
it.status == FileDownloadStatus.progress ||
it.status == FileDownloadStatus.paused
(it.status == FileDownloadStatus.progress || it.status == FileDownloadStatus.paused) && !it.isTime
}
startedList.forEach { it.time = System.currentTimeMillis() }
val startPath = startedList.map { it.path }
//完成的任务
val finishList = downloadList.filter { it.status == FileDownloadStatus.completed }
val finishList = downloadList.filter { it.status == FileDownloadStatus.completed && !it.isTime }
val finishPath = finishList.map { it.path }
......@@ -93,6 +93,9 @@ object DownloadHelper {
val olderList = getDownloadJsonBean(recordFile, downloadBeanGson).toMutableList()
olderList.removeIf { startPath.contains(it.path) }
olderList.removeIf { finishPath.contains(it.path) }
olderList.forEach {
it.status = FileDownloader.getImpl().getStatus(it.downloadId, it.path)
}
val arrayList = arrayListOf<DownloadBean>()
arrayList.addAll(olderList)
......
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