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
18f6be20
Commit
18f6be20
authored
Aug 26, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
3519b620
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
78 additions
and
88 deletions
+78
-88
build.gradle.kts
app/build.gradle.kts
+0
-1
MyApplication.kt
app/src/main/java/com/base/browserwhite/MyApplication.kt
+0
-4
DownloadBean.kt
app/src/main/java/com/base/browserwhite/bean/DownloadBean.kt
+1
-1
WebDownloadManagerActivity.kt
...rwhite/ui/activity/download/WebDownloadManagerActivity.kt
+7
-19
WebViewFragment.kt
...se/browserwhite/ui/activity/webbrowser/WebViewFragment.kt
+13
-7
DownloadAdapter.kt
.../java/com/base/browserwhite/ui/adapter/DownloadAdapter.kt
+53
-54
DownloadDialog.kt
...ain/java/com/base/browserwhite/ui/views/DownloadDialog.kt
+2
-0
DownloadHelper.kt
...c/main/java/com/base/browserwhite/utils/DownloadHelper.kt
+2
-2
No files found.
app/build.gradle.kts
View file @
18f6be20
...
@@ -120,7 +120,6 @@ dependencies {
...
@@ -120,7 +120,6 @@ dependencies {
implementation
(
"com.squareup.okhttp3:okhttp"
)
implementation
(
"com.squareup.okhttp3:okhttp"
)
implementation
(
"com.squareup.okhttp3:logging-interceptor"
)
implementation
(
"com.squareup.okhttp3:logging-interceptor"
)
//支持暂停恢复下载
//支持暂停恢复下载
implementation
(
"com.github.amitshekhariitbhu:PRDownloader:1.0.1"
)
implementation
(
"com.liulishuo.filedownloader:library:1.7.7"
)
implementation
(
"com.liulishuo.filedownloader:library:1.7.7"
)
...
...
app/src/main/java/com/base/browserwhite/MyApplication.kt
View file @
18f6be20
...
@@ -4,12 +4,8 @@ import android.app.Activity
...
@@ -4,12 +4,8 @@ import android.app.Activity
import
android.app.Application
import
android.app.Application
import
android.os.Bundle
import
android.os.Bundle
import
com.base.browserwhite.utils.ActivityManagerUtils
import
com.base.browserwhite.utils.ActivityManagerUtils
import
com.downloader.PRDownloader
import
com.downloader.PRDownloaderConfig
import
com.facebook.FacebookSdk
import
com.facebook.FacebookSdk
import
com.google.ar.core.Config
import
com.liulishuo.filedownloader.FileDownloader
import
com.liulishuo.filedownloader.FileDownloader
import
com.liulishuo.filedownloader.connection.FileDownloadConnection
class
MyApplication
:
Application
()
{
class
MyApplication
:
Application
()
{
...
...
app/src/main/java/com/base/browserwhite/bean/DownloadBean.kt
View file @
18f6be20
...
@@ -15,7 +15,7 @@ data class DownloadBean(
...
@@ -15,7 +15,7 @@ data class DownloadBean(
var
downloadId
:
Int
=
-
1
,
var
downloadId
:
Int
=
-
1
,
var
path
:
String
=
""
,
var
path
:
String
=
""
,
val
url
:
String
=
""
,
val
url
:
String
=
""
,
var
time
:
String
=
""
,
var
time
:
Long
=
0
,
)
{
)
{
var
status
=
FileDownloadStatus
.
pending
var
status
=
FileDownloadStatus
.
pending
var
name
:
String
=
""
var
name
:
String
=
""
...
...
app/src/main/java/com/base/browserwhite/ui/activity/download/WebDownloadManagerActivity.kt
View file @
18f6be20
...
@@ -14,11 +14,10 @@ import com.base.browserwhite.ui.adapter.DownloadAdapter
...
@@ -14,11 +14,10 @@ import com.base.browserwhite.ui.adapter.DownloadAdapter
import
com.base.browserwhite.ui.views.DialogViews.showGerPermission
import
com.base.browserwhite.ui.views.DialogViews.showGerPermission
import
com.base.browserwhite.utils.BarUtils
import
com.base.browserwhite.utils.BarUtils
import
com.base.browserwhite.utils.DownloadHelper.getDownloadJson
import
com.base.browserwhite.utils.DownloadHelper.getDownloadJson
import
com.base.browserwhite.utils.DownloadHelper.get
NotFinishList
import
com.base.browserwhite.utils.DownloadHelper.get
DownloadJsonBean
import
com.base.browserwhite.utils.KotlinExt.toFormatTime
import
com.base.browserwhite.utils.KotlinExt.toFormatTime
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.downloader.Status
import
java.io.File
import
java.io.File
class
WebDownloadManagerActivity
:
BaseActivity
<
ActivityWebDownloadManagerBinding
>()
{
class
WebDownloadManagerActivity
:
BaseActivity
<
ActivityWebDownloadManagerBinding
>()
{
...
@@ -70,34 +69,23 @@ class WebDownloadManagerActivity : BaseActivity<ActivityWebDownloadManagerBindin
...
@@ -70,34 +69,23 @@ class WebDownloadManagerActivity : BaseActivity<ActivityWebDownloadManagerBindin
binding
.
llEmpty
.
isVisible
=
true
binding
.
llEmpty
.
isVisible
=
true
}
else
{
}
else
{
val
fileList
=
arrayListOf
<
File
>()
val
fileList
=
arrayListOf
<
File
>()
val
timeList
=
arrayListOf
<
String
>()
val
beanList
=
arrayListOf
<
DownloadBean
>()
val
beanList
=
arrayListOf
<
DownloadBean
>()
fileList
.
addAll
(
dir
.
listFiles
()
?:
arrayOf
())
fileList
.
addAll
(
dir
.
listFiles
()
?:
arrayOf
())
fileList
.
sortBy
{
it
.
lastModified
()
}
fileList
.
sortBy
{
it
.
lastModified
()
}
fileList
.
forEach
{
val
timeList
=
arrayListOf
<
String
>()
val
time
=
it
.
lastModified
().
toFormatTime
()
getDownloadJsonBean
(
getDownloadJson
()).
forEach
{
old
->
val
time
=
old
.
time
.
toFormatTime
()
if
(!
timeList
.
contains
(
time
))
{
if
(!
timeList
.
contains
(
time
))
{
timeList
.
add
(
time
)
timeList
.
add
(
time
)
beanList
.
add
(
DownloadBean
(
time
=
time
).
apply
{
isTime
=
true
})
}
else
{
beanList
.
add
(
DownloadBean
(
path
=
it
.
absolutePath
))
}
}
getNotFinishList
(
getDownloadJson
()).
forEach
{
old
->
if
(!
timeList
.
contains
(
old
.
time
))
{
timeList
.
add
(
old
.
time
)
beanList
.
add
(
DownloadBean
(
time
=
old
.
time
).
apply
{
isTime
=
true
})
beanList
.
add
(
DownloadBean
(
time
=
old
.
time
).
apply
{
isTime
=
true
})
}
}
else
{
val
index
=
beanList
.
indexOfFirst
{
bean
->
bean
.
time
==
old
.
time
}
beanList
.
add
(
old
)
runCatching
{
beanList
.
add
(
index
+
1
,
old
)
}
}
}
}
adapter
.
submitList
(
beanList
)
adapter
.
submitList
(
beanList
)
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/browserwhite/ui/activity/webbrowser/WebViewFragment.kt
View file @
18f6be20
...
@@ -17,18 +17,16 @@ import android.webkit.WebView
...
@@ -17,18 +17,16 @@ import android.webkit.WebView
import
android.webkit.WebViewClient
import
android.webkit.WebViewClient
import
androidx.lifecycle.lifecycleScope
import
androidx.lifecycle.lifecycleScope
import
com.base.browserwhite.bean.DownloadBean
import
com.base.browserwhite.bean.DownloadBean
import
com.base.browserwhite.bean.DownloadBeanSerializer
import
com.base.browserwhite.bean.downloadBeanGson
import
com.base.browserwhite.bean.downloadBeanGson
import
com.base.browserwhite.databinding.FragmentWebViewBinding
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.DownloadDialog.showDownloadVideoDialog
import
com.base.browserwhite.ui.views.DownloadDialog.showDownloadVideoDialog
import
com.base.browserwhite.utils.DownloadHelper.getDownloadJson
import
com.base.browserwhite.utils.DownloadHelper.getDownloadJson
import
com.base.browserwhite.utils.DownloadHelper.getNotFinishList
import
com.base.browserwhite.utils.DownloadHelper.getDownloadJsonBean
import
com.base.browserwhite.utils.KotlinExt.toFormatTime
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.LogEx
import
com.google.gson.Gson
import
com.google.gson.Gson
import
com.
google.gson.GsonBuilder
import
com.
liulishuo.filedownloader.model.FileDownloadStatus
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
...
@@ -105,9 +103,9 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -105,9 +103,9 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
val
recordFile
=
requireContext
().
getDownloadJson
()
val
recordFile
=
requireContext
().
getDownloadJson
()
val
list
=
downloadList
val
list
=
downloadList
list
.
f
orEach
{
it
.
time
=
System
.
currentTimeMillis
().
toFormatTime
()
}
list
.
f
ilter
{
it
.
status
!=
FileDownloadStatus
.
completed
}.
forEach
{
it
.
time
=
System
.
currentTimeMillis
()
}
val
olderList
=
get
NotFinishList
(
recordFile
,
downloadBeanGson
).
filter
{
!
list
.
contains
(
it
)
}
val
olderList
=
get
DownloadJsonBean
(
recordFile
,
downloadBeanGson
).
filter
{
!
list
.
contains
(
it
)
}
val
arrayList
=
arrayListOf
<
DownloadBean
>()
val
arrayList
=
arrayListOf
<
DownloadBean
>()
arrayList
.
addAll
(
olderList
)
arrayList
.
addAll
(
olderList
)
...
@@ -287,7 +285,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -287,7 +285,7 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
val
jsonArray
=
JSONArray
(
value
)
val
jsonArray
=
JSONArray
(
value
)
val
recordFile
=
requireContext
().
getDownloadJson
()
val
recordFile
=
requireContext
().
getDownloadJson
()
val
olderList
=
get
NotFinishList
(
recordFile
,
Gson
())
val
olderList
=
get
DownloadJsonBean
(
recordFile
,
Gson
())
val
set
=
hashSetOf
<
String
>()
val
set
=
hashSetOf
<
String
>()
for
(
i
in
0
until
jsonArray
.
length
())
{
for
(
i
in
0
until
jsonArray
.
length
())
{
...
@@ -312,6 +310,9 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -312,6 +310,9 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
downloadList
.
forEach
{
downloadList
.
forEach
{
fastGetSize
(
it
)
fastGetSize
(
it
)
}
}
launch
(
Dispatchers
.
Main
)
{
downloadAdapter
?.
submitList
(
downloadList
)
}
}
}
isParsing
=
false
isParsing
=
false
})
})
...
@@ -388,4 +389,9 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -388,4 +389,9 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
}
}
}
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
saveDownloadRecordFile
(
downloadList
)
}
}
}
\ No newline at end of file
app/src/main/java/com/base/browserwhite/ui/adapter/DownloadAdapter.kt
View file @
18f6be20
...
@@ -14,6 +14,7 @@ import com.base.browserwhite.databinding.ItemDownloadTimeBinding
...
@@ -14,6 +14,7 @@ import com.base.browserwhite.databinding.ItemDownloadTimeBinding
import
com.base.browserwhite.ui.views.DownloadDialog.showDownloadConfirmDialog
import
com.base.browserwhite.ui.views.DownloadDialog.showDownloadConfirmDialog
import
com.base.browserwhite.utils.DownloadHelper.getDownloadPath
import
com.base.browserwhite.utils.DownloadHelper.getDownloadPath
import
com.base.browserwhite.utils.KotlinExt.toFormatSize
import
com.base.browserwhite.utils.KotlinExt.toFormatSize
import
com.base.browserwhite.utils.KotlinExt.toFormatTime
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.XmlEx.inflate
import
com.base.browserwhite.utils.XmlEx.inflate
import
com.bumptech.glide.Glide
import
com.bumptech.glide.Glide
...
@@ -22,13 +23,8 @@ import com.liulishuo.filedownloader.BaseDownloadTask
...
@@ -22,13 +23,8 @@ import com.liulishuo.filedownloader.BaseDownloadTask
import
com.liulishuo.filedownloader.FileDownloadListener
import
com.liulishuo.filedownloader.FileDownloadListener
import
com.liulishuo.filedownloader.FileDownloader
import
com.liulishuo.filedownloader.FileDownloader
import
com.liulishuo.filedownloader.model.FileDownloadStatus
import
com.liulishuo.filedownloader.model.FileDownloadStatus
import
okhttp3.Call
import
okhttp3.Callback
import
okhttp3.OkHttpClient
import
okhttp3.Request
import
okhttp3.Response
import
java.io.File
import
java.io.File
import
java.io.IOException
import
kotlin.math.abs
class
DownloadAdapter
:
BaseQuickAdapter
<
DownloadBean
,
DownloadAdapter
.
DownloadViewHolder
>()
{
class
DownloadAdapter
:
BaseQuickAdapter
<
DownloadBean
,
DownloadAdapter
.
DownloadViewHolder
>()
{
...
@@ -44,7 +40,7 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
...
@@ -44,7 +40,7 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
val
context
=
holder
.
itemView
.
context
val
context
=
holder
.
itemView
.
context
if
(
item
.
isTime
)
{
if
(
item
.
isTime
)
{
val
binding
=
ItemDownloadTimeBinding
.
bind
(
holder
.
itemView
)
val
binding
=
ItemDownloadTimeBinding
.
bind
(
holder
.
itemView
)
binding
.
tvTime
.
text
=
item
.
time
binding
.
tvTime
.
text
=
item
.
time
.
toFormatTime
()
}
else
if
(
item
.
uiType
==
1
)
{
}
else
if
(
item
.
uiType
==
1
)
{
val
binding
=
ItemDownloadBinding
.
bind
(
holder
.
itemView
)
val
binding
=
ItemDownloadBinding
.
bind
(
holder
.
itemView
)
val
file
=
File
(
item
.
path
)
val
file
=
File
(
item
.
path
)
...
@@ -59,7 +55,7 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
...
@@ -59,7 +55,7 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
binding
.
tvSize
.
text
=
item
.
size
.
toFormatSize
()
binding
.
tvSize
.
text
=
item
.
size
.
toFormatSize
()
var
status
=
item
.
status
var
status
=
item
.
status
LogEx
.
logDebug
(
TAG
,
"status=${item.status} path=${item.path} progress=${item.progress}"
)
//
LogEx.logDebug(TAG, "status=${item.status} path=${item.path} progress=${item.progress}")
if
(
item
.
progress
==
100
)
{
if
(
item
.
progress
==
100
)
{
status
=
FileDownloadStatus
.
completed
status
=
FileDownloadStatus
.
completed
}
}
...
@@ -77,10 +73,8 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
...
@@ -77,10 +73,8 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
FileDownloadStatus
.
progress
->
{
FileDownloadStatus
.
progress
->
{
binding
.
ivXiazaiZantin
.
setImageResource
(
R
.
mipmap
.
xiazhaiz_download
)
binding
.
ivXiazaiZantin
.
setImageResource
(
R
.
mipmap
.
xiazhaiz_download
)
binding
.
circularProgressBar
.
progress
=
item
.
progress
.
toFloat
()
binding
.
circularProgressBar
.
progress
=
item
.
progress
.
toFloat
()
if
(
item
.
fileDownloadListener
==
null
)
{
replaceListener
(
item
)
replaceListener
(
item
)
}
}
}
FileDownloadStatus
.
completed
->
{
FileDownloadStatus
.
completed
->
{
binding
.
flDownload
.
isVisible
=
false
binding
.
flDownload
.
isVisible
=
false
...
@@ -99,9 +93,25 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
...
@@ -99,9 +93,25 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
}
}
}
}
binding
.
flDownload
.
setOnClickListener
{
binding
.
flDownload
.
setOnClickListener
{
pauseResumeDownload
(
item
)
}
}
}
private
fun
pauseResumeDownload
(
item
:
DownloadBean
)
{
if
(
item
.
status
==
FileDownloadStatus
.
progress
)
{
FileDownloader
.
getImpl
().
pause
(
item
.
downloadId
)
LogEx
.
logDebug
(
TAG
,
"pause downloadId=${item.downloadId}"
)
return
}
}
if
(
item
.
status
==
FileDownloadStatus
.
paused
)
{
downloadItem
(
context
,
item
)
LogEx
.
logDebug
(
TAG
,
"start"
)
return
}
}
LogEx
.
logDebug
(
TAG
,
"有问题"
)
}
}
override
fun
getItemViewType
(
position
:
Int
,
list
:
List
<
DownloadBean
>):
Int
{
override
fun
getItemViewType
(
position
:
Int
,
list
:
List
<
DownloadBean
>):
Int
{
...
@@ -125,71 +135,54 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
...
@@ -125,71 +135,54 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
item
.
path
=
context
.
getDownloadPath
(
item
.
url
,
item
.
name
)
item
.
path
=
context
.
getDownloadPath
(
item
.
url
,
item
.
name
)
item
.
fileDownloadListener
=
createNewLister
(
item
,
"downloadItem"
)
val
downloadTask
=
FileDownloader
.
getImpl
().
create
(
item
.
url
)
val
downloadTask
=
FileDownloader
.
getImpl
().
create
(
item
.
url
)
.
setPath
(
item
.
path
)
.
setPath
(
item
.
path
)
.
setCallbackProgressMinInterval
(
500
)
.
setCallbackProgressMinInterval
(
500
)
.
setListener
(
object
:
FileDownloadListener
()
{
.
setListener
(
item
.
fileDownloadListener
)
override
fun
pending
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
downloadTask
.
start
()
item
.
downloadId
=
downloadTask
.
id
}
override
fun
progress
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
LogEx
.
logDebug
(
TAG
,
"downloadItem progress"
)
val
percent
=
soFarBytes
*
100
/
totalBytes
item
.
progress
=
percent
item
.
status
=
FileDownloader
.
getImpl
().
getStatus
(
item
.
url
,
item
.
path
)
notifyDataSetChanged
()
}
override
fun
connected
(
task
:
BaseDownloadTask
?,
etag
:
String
?,
isContinue
:
Boolean
,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
LogEx
.
logDebug
(
TAG
,
"downloadItem connected"
)
super
.
connected
(
task
,
etag
,
isContinue
,
soFarBytes
,
totalBytes
)
if
(
isContinue
)
{
// 如果是继续之前的下载
}
}
override
fun
completed
(
task
:
BaseDownloadTask
?)
{
LogEx
.
logDebug
(
TAG
,
"downloadItem completed"
)
item
.
progress
=
100
item
.
status
=
FileDownloader
.
getImpl
().
getStatus
(
item
.
url
,
item
.
path
)
notifyDataSetChanged
()
}
override
fun
paused
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
}
}
override
fun
error
(
task
:
BaseDownloadTask
?,
e
:
Throwable
?)
{
private
fun
replaceListener
(
item
:
DownloadBean
)
{
if
(
item
.
fileDownloadListener
==
null
)
{
item
.
fileDownloadListener
=
createNewLister
(
item
,
"replaceListener"
)
FileDownloader
.
getImpl
().
replaceListener
(
item
.
downloadId
,
item
.
fileDownloadListener
)
}
}
override
fun
warn
(
task
:
BaseDownloadTask
?)
{
}
}
})
downloadTask
.
start
()
}
private
fun
createNewLister
(
item
:
DownloadBean
,
tag
:
String
=
""
):
FileDownloadListener
{
return
object
:
FileDownloadListener
()
{
private
fun
replaceListener
(
item
:
DownloadBean
)
{
item
.
fileDownloadListener
=
object
:
FileDownloadListener
()
{
override
fun
pending
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
override
fun
pending
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
}
}
@SuppressLint
(
"NotifyDataSetChanged"
)
@SuppressLint
(
"NotifyDataSetChanged"
)
override
fun
progress
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
override
fun
progress
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
LogEx
.
logDebug
(
TAG
,
"replaceListener progress"
)
val
percent
=
soFarBytes
*
100
/
totalBytes
val
percent
=
soFarBytes
*
100
/
totalBytes
LogEx
.
logDebug
(
TAG
,
"progress tag=$tag item=${item.downloadId} percent=$percent"
)
if
(
percent
<
0
)
return
item
.
progress
=
percent
item
.
progress
=
percent
item
.
status
=
FileDownloader
.
getImpl
().
getStatus
(
item
.
url
,
item
.
path
)
notifyDataSetChanged
()
notifyDataSetChanged
()
}
}
@SuppressLint
(
"NotifyDataSetChanged"
)
@SuppressLint
(
"NotifyDataSetChanged"
)
override
fun
completed
(
task
:
BaseDownloadTask
?)
{
override
fun
completed
(
task
:
BaseDownloadTask
?)
{
item
.
progress
=
100
item
.
progress
=
100
item
.
status
=
FileDownloader
.
getImpl
().
getStatus
(
item
.
url
,
item
.
path
)
item
.
time
=
System
.
currentTimeMillis
()
notifyDataSetChanged
()
notifyDataSetChanged
()
}
}
@SuppressLint
(
"NotifyDataSetChanged"
)
override
fun
paused
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
override
fun
paused
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
LogEx
.
logDebug
(
TAG
,
"paused tag=$tag item=${item.downloadId}"
)
val
percent
=
soFarBytes
*
100
/
totalBytes
item
.
progress
=
abs
(
percent
)
item
.
status
=
FileDownloadStatus
.
paused
notifyDataSetChanged
()
}
}
override
fun
error
(
task
:
BaseDownloadTask
?,
e
:
Throwable
?)
{
override
fun
error
(
task
:
BaseDownloadTask
?,
e
:
Throwable
?)
{
...
@@ -197,9 +190,15 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
...
@@ -197,9 +190,15 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
override
fun
warn
(
task
:
BaseDownloadTask
?)
{
override
fun
warn
(
task
:
BaseDownloadTask
?)
{
}
}
override
fun
connected
(
task
:
BaseDownloadTask
?,
etag
:
String
?,
isContinue
:
Boolean
,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
super
.
connected
(
task
,
etag
,
isContinue
,
soFarBytes
,
totalBytes
)
LogEx
.
logDebug
(
TAG
,
"connected tag=$tag item=${item.downloadId} isContinue=$isContinue"
)
if
(
isContinue
)
{
}
}
}
}
FileDownloader
.
getImpl
().
replaceListener
(
item
.
downloadId
,
item
.
fileDownloadListener
)
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/browserwhite/ui/views/DownloadDialog.kt
View file @
18f6be20
...
@@ -18,6 +18,7 @@ import com.base.browserwhite.databinding.DialogDownloadFinishBinding
...
@@ -18,6 +18,7 @@ import com.base.browserwhite.databinding.DialogDownloadFinishBinding
import
com.base.browserwhite.databinding.DialogDownloadVideoBinding
import
com.base.browserwhite.databinding.DialogDownloadVideoBinding
import
com.base.browserwhite.ui.activity.download.WebDownloadManagerActivity
import
com.base.browserwhite.ui.activity.download.WebDownloadManagerActivity
import
com.base.browserwhite.ui.adapter.DownloadAdapter
import
com.base.browserwhite.ui.adapter.DownloadAdapter
import
com.base.browserwhite.utils.KotlinExt.toFormatSize
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.LogEx
import
com.bumptech.glide.Glide
import
com.bumptech.glide.Glide
import
com.google.android.material.bottomsheet.BottomSheetBehavior
import
com.google.android.material.bottomsheet.BottomSheetBehavior
...
@@ -82,6 +83,7 @@ object DownloadDialog {
...
@@ -82,6 +83,7 @@ object DownloadDialog {
Glide
.
with
(
this
).
load
(
item
.
url
).
centerCrop
().
into
(
binding
.
iv
)
Glide
.
with
(
this
).
load
(
item
.
url
).
centerCrop
().
into
(
binding
.
iv
)
binding
.
editName
.
setText
(
item
.
url
.
split
(
"/"
).
last
())
binding
.
editName
.
setText
(
item
.
url
.
split
(
"/"
).
last
())
binding
.
tvSize
.
text
=
item
.
size
.
toFormatSize
()
binding
.
ivEdit
.
setOnClickListener
{
binding
.
ivEdit
.
setOnClickListener
{
binding
.
editName
.
isEnabled
=
true
binding
.
editName
.
isEnabled
=
true
binding
.
editName
.
setBackgroundResource
(
android
.
R
.
drawable
.
edit_text
)
binding
.
editName
.
setBackgroundResource
(
android
.
R
.
drawable
.
edit_text
)
...
...
app/src/main/java/com/base/browserwhite/utils/DownloadHelper.kt
View file @
18f6be20
...
@@ -24,10 +24,10 @@ object DownloadHelper {
...
@@ -24,10 +24,10 @@ object DownloadHelper {
return
recordFile
return
recordFile
}
}
fun
get
NotFinishList
(
recordFile
:
File
,
gson
:
Gson
=
downloadBeanGson
):
List
<
DownloadBean
>
{
fun
get
DownloadJsonBean
(
recordFile
:
File
,
gson
:
Gson
=
downloadBeanGson
):
List
<
DownloadBean
>
{
val
olderText
=
recordFile
.
readText
()
val
olderText
=
recordFile
.
readText
()
val
type
:
Type
=
object
:
TypeToken
<
List
<
DownloadBean
>>()
{}.
type
val
type
:
Type
=
object
:
TypeToken
<
List
<
DownloadBean
>>()
{}.
type
return
gson
.
fromJson
(
olderText
,
type
)
?:
listOf
()
return
gson
.
fromJson
<
List
<
DownloadBean
>?>(
olderText
,
type
)
?.
filter
{
File
(
it
.
path
).
exists
()
}
?:
listOf
()
}
}
fun
Context
.
getDownloadPath
(
fun
Context
.
getDownloadPath
(
...
...
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