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