Commit 3fa3215f authored by wanglei's avatar wanglei

...

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