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
3f2e9fa5
Commit
3f2e9fa5
authored
Sep 06, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
1fb04e75
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
23 deletions
+46
-23
DownloadAdapter.kt
...base/browserwhite/ui/activity/download/DownloadAdapter.kt
+7
-2
DownloadDialog.kt
.../base/browserwhite/ui/activity/download/DownloadDialog.kt
+5
-14
WebBrowserActivity.kt
...browserwhite/ui/activity/webbrowser/WebBrowserActivity.kt
+0
-1
WebViewFragment.kt
...se/browserwhite/ui/activity/webbrowser/WebViewFragment.kt
+26
-4
DownloadUtils.kt
...rc/main/java/com/base/browserwhite/utils/DownloadUtils.kt
+8
-2
No files found.
app/src/main/java/com/base/browserwhite/ui/activity/download/DownloadAdapter.kt
View file @
3f2e9fa5
...
@@ -33,6 +33,7 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
...
@@ -33,6 +33,7 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
inner
class
DownloadViewHolder
(
view
:
View
)
:
ViewHolder
(
view
)
inner
class
DownloadViewHolder
(
view
:
View
)
:
ViewHolder
(
view
)
var
beginProgressAction
:
(()
->
Unit
)?
=
null
//开始下载时调用,每个下载调用一次后设置为null
var
downloadAction
:
(()
->
Unit
)?
=
null
//下载按钮
var
downloadAction
:
(()
->
Unit
)?
=
null
//下载按钮
var
downloadFinishAction
:
((
id
:
Int
)
->
Unit
)?
=
null
//下载完成
var
downloadFinishAction
:
((
id
:
Int
)
->
Unit
)?
=
null
//下载完成
...
@@ -297,18 +298,20 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
...
@@ -297,18 +298,20 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
override
fun
progress
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
override
fun
progress
(
task
:
BaseDownloadTask
?,
soFarBytes
:
Int
,
totalBytes
:
Int
)
{
val
percent
=
soFarBytes
*
100
/
totalBytes
val
percent
=
soFarBytes
*
100
/
totalBytes
LogEx
.
logDebug
(
TAG
,
"progress tag=$tag item=${item.downloadId} percent=$percent ${item.path}"
)
if
(
percent
<
0
)
return
if
(
percent
<
0
)
return
item
.
progress
=
percent
item
.
progress
=
percent
item
.
status
=
FileDownloader
.
getImpl
().
getStatus
(
item
.
url
,
item
.
path
)
item
.
status
=
FileDownloader
.
getImpl
().
getStatus
(
item
.
url
,
item
.
path
)
LogEx
.
logDebug
(
TAG
,
"progress tag=$tag item=${item.downloadId} percent=$percent ${item.path} state=${task?.status}"
)
notifyItemChanged
(
position
,
"aaa"
)
notifyItemChanged
(
position
,
"aaa"
)
beginProgressAction
?.
invoke
()
beginProgressAction
=
null
}
}
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
()
LogEx
.
logDebug
(
TAG
,
"completed tag=$tag item=${item.downloadId} ${item.path} ${item.status}"
)
notifyItemChanged
(
position
,
"aaa"
)
notifyItemChanged
(
position
,
"aaa"
)
task
?.
let
{
downloadFinishAction
?.
invoke
(
it
.
id
)
}
task
?.
let
{
downloadFinishAction
?.
invoke
(
it
.
id
)
}
}
}
...
@@ -334,6 +337,8 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
...
@@ -334,6 +337,8 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
LogEx
.
logDebug
(
TAG
,
"connected tag=$tag item=${item.downloadId} isContinue=$isContinue"
)
LogEx
.
logDebug
(
TAG
,
"connected tag=$tag item=${item.downloadId} isContinue=$isContinue"
)
if
(
isContinue
)
{
if
(
isContinue
)
{
}
else
{
}
}
}
}
}
}
...
...
app/src/main/java/com/base/browserwhite/ui/activity/download/DownloadDialog.kt
View file @
3f2e9fa5
...
@@ -67,15 +67,6 @@ object DownloadDialog {
...
@@ -67,15 +67,6 @@ object DownloadDialog {
dismissAction
.
invoke
()
dismissAction
.
invoke
()
}
}
adapter
.
downloadAction
=
{
dialog
.
dismiss
()
}
// adapter.downloadFinishAction = { id ->
// dialog.dismiss()
// val recordFile = getDownloadJson()
// val bean = DownloadUtils.getDownloadJsonBean(recordFile).find { it.downloadId == id }
// bean?.let { showDownloadFinishDialog(it) }
// }
binding
.
tvDownloadDir
.
setOnClickListener
{
binding
.
tvDownloadDir
.
setOnClickListener
{
dialog
.
dismiss
()
dialog
.
dismiss
()
...
@@ -154,11 +145,11 @@ object DownloadDialog {
...
@@ -154,11 +145,11 @@ object DownloadDialog {
binding
.
tvPlay
.
setOnClickListener
{
binding
.
tvPlay
.
setOnClickListener
{
dialog
.
dismiss
()
dialog
.
dismiss
()
startActivity
(
Intent
(
this
,
MediaVideoDetailActivity
::
class
.
java
).
apply
{
startActivity
(
Intent
(
this
,
MediaVideoDetailActivity
::
class
.
java
).
apply
{
val
uri
=
FileProvider
.
getUriForFile
(
//
val uri = FileProvider.getUriForFile(
this
@showDownloadFinishDialog
,
//
this@showDownloadFinishDialog,
"com.base.browserwhite.provider"
,
File
(
bean
.
path
)
//
"com.base.browserwhite.provider", File(bean.path)
)
//
)
putExtra
(
"uri"
,
uri
)
putExtra
(
"uri"
,
bean
.
path
)
})
})
}
}
}
}
...
...
app/src/main/java/com/base/browserwhite/ui/activity/webbrowser/WebBrowserActivity.kt
View file @
3f2e9fa5
...
@@ -165,7 +165,6 @@ class WebBrowserActivity : BaseActivity<ActivityWebBrowserBinding>() {
...
@@ -165,7 +165,6 @@ class WebBrowserActivity : BaseActivity<ActivityWebBrowserBinding>() {
if
(
currentFragment
?.
canGoBack
()
==
true
)
{
if
(
currentFragment
?.
canGoBack
()
==
true
)
{
binding
.
ivLeft
.
setImageResource
(
R
.
mipmap
.
left_s
)
binding
.
ivLeft
.
setImageResource
(
R
.
mipmap
.
left_s
)
}
else
{
}
else
{
// binding.ivLeft.setImageResource(R.mipmap.left_n)
binding
.
ivLeft
.
setImageResource
(
R
.
mipmap
.
left_s
)
binding
.
ivLeft
.
setImageResource
(
R
.
mipmap
.
left_s
)
}
}
if
(
currentFragment
?.
canGoForward
()
==
true
)
{
if
(
currentFragment
?.
canGoForward
()
==
true
)
{
...
...
app/src/main/java/com/base/browserwhite/ui/activity/webbrowser/WebViewFragment.kt
View file @
3f2e9fa5
...
@@ -20,7 +20,6 @@ import android.webkit.WebSettings
...
@@ -20,7 +20,6 @@ import android.webkit.WebSettings
import
android.webkit.WebStorage
import
android.webkit.WebStorage
import
android.webkit.WebView
import
android.webkit.WebView
import
android.webkit.WebViewClient
import
android.webkit.WebViewClient
import
android.widget.Toast
import
androidx.core.view.isVisible
import
androidx.core.view.isVisible
import
androidx.lifecycle.lifecycleScope
import
androidx.lifecycle.lifecycleScope
import
com.base.browserwhite.MyApplication
import
com.base.browserwhite.MyApplication
...
@@ -30,10 +29,12 @@ import com.base.browserwhite.bean.DownloadBean
...
@@ -30,10 +29,12 @@ import com.base.browserwhite.bean.DownloadBean
import
com.base.browserwhite.bean.HistoryBean
import
com.base.browserwhite.bean.HistoryBean
import
com.base.browserwhite.databinding.FragmentWebViewBinding
import
com.base.browserwhite.databinding.FragmentWebViewBinding
import
com.base.browserwhite.ui.activity.download.DownloadAdapter
import
com.base.browserwhite.ui.activity.download.DownloadAdapter
import
com.base.browserwhite.ui.activity.download.DownloadDialog.showDownloadFinishDialog
import
com.base.browserwhite.ui.activity.download.DownloadDialog.showDownloadVideoDialog
import
com.base.browserwhite.ui.activity.download.DownloadDialog.showDownloadVideoDialog
import
com.base.browserwhite.ui.fragment.BaseFragment
import
com.base.browserwhite.ui.fragment.BaseFragment
import
com.base.browserwhite.ui.views.PermissionDialog.showPermissionBottomSheet
import
com.base.browserwhite.ui.views.PermissionDialog.showPermissionBottomSheet
import
com.base.browserwhite.utils.ColorUtils
import
com.base.browserwhite.utils.ColorUtils
import
com.base.browserwhite.utils.DownloadUtils
import
com.base.browserwhite.utils.DownloadUtils.getDownloadJson
import
com.base.browserwhite.utils.DownloadUtils.getDownloadJson
import
com.base.browserwhite.utils.DownloadUtils.getDownloadJsonBean
import
com.base.browserwhite.utils.DownloadUtils.getDownloadJsonBean
import
com.base.browserwhite.utils.DownloadUtils.saveDownloadRecordFile
import
com.base.browserwhite.utils.DownloadUtils.saveDownloadRecordFile
...
@@ -52,6 +53,7 @@ import okhttp3.Callback
...
@@ -52,6 +53,7 @@ import okhttp3.Callback
import
okhttp3.OkHttpClient
import
okhttp3.OkHttpClient
import
okhttp3.Request
import
okhttp3.Request
import
okhttp3.Response
import
okhttp3.Response
import
java.io.File
import
java.io.IOException
import
java.io.IOException
import
kotlin.random.Random
import
kotlin.random.Random
...
@@ -107,9 +109,8 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -107,9 +109,8 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
return
@setOnClickListener
return
@setOnClickListener
}
}
if
(
downloadAdapter
==
null
)
{
initDownloadAdapter
()
downloadAdapter
=
DownloadAdapter
()
}
downloadAdapter
?.
let
{
adapter
->
downloadAdapter
?.
let
{
adapter
->
downloadDialog
=
requireContext
().
showDownloadVideoDialog
(
downloadDialog
=
requireContext
().
showDownloadVideoDialog
(
adapter
,
downloadList
,
adapter
,
downloadList
,
...
@@ -124,6 +125,27 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
...
@@ -124,6 +125,27 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
}
}
private
fun
initDownloadAdapter
()
{
if
(
downloadAdapter
==
null
)
{
downloadAdapter
=
DownloadAdapter
()
}
downloadAdapter
?.
downloadAction
=
{
downloadDialog
?.
dismiss
()
downloadAdapter
?.
beginProgressAction
=
{
requireContext
().
saveDownloadRecordFile
(
downloadList
)
}
}
downloadAdapter
?.
downloadFinishAction
=
{
id
->
downloadDialog
?.
dismiss
()
val
recordFile
=
requireContext
().
getDownloadJson
()
val
bean
=
DownloadUtils
.
getDownloadJsonBean
(
recordFile
).
find
{
it
.
downloadId
==
id
}
val
file
=
File
(
bean
?.
path
?:
""
)
LogEx
.
logDebug
(
TAG
,
"downloadFinishAction id=$id ${bean?.downloadId} ${bean?.name} ${bean?.path}} exists=${file.exists()}"
)
bean
?.
let
{
requireContext
().
showDownloadFinishDialog
(
it
)
}
requireContext
().
saveDownloadRecordFile
(
downloadList
)
}
}
fun
dropAndBounceButton
(
button
:
View
)
{
fun
dropAndBounceButton
(
button
:
View
)
{
// 初始位置
// 初始位置
button
.
isVisible
=
downloadList
.
isNotEmpty
()
button
.
isVisible
=
downloadList
.
isNotEmpty
()
...
...
app/src/main/java/com/base/browserwhite/utils/DownloadUtils.kt
View file @
3f2e9fa5
...
@@ -29,6 +29,7 @@ object DownloadUtils {
...
@@ -29,6 +29,7 @@ object DownloadUtils {
fun
getDownloadJsonBean
(
recordFile
:
File
,
gson
:
Gson
=
downloadBeanGson
):
List
<
DownloadBean
>
{
fun
getDownloadJsonBean
(
recordFile
:
File
,
gson
:
Gson
=
downloadBeanGson
):
List
<
DownloadBean
>
{
val
olderText
=
recordFile
.
readText
()
val
olderText
=
recordFile
.
readText
()
LogEx
.
logDebug
(
TAG
,
"olderText=$olderText"
)
val
type
:
Type
=
object
:
TypeToken
<
List
<
DownloadBean
>>()
{}.
type
val
type
:
Type
=
object
:
TypeToken
<
List
<
DownloadBean
>>()
{}.
type
return
gson
.
fromJson
<
List
<
DownloadBean
>?>(
olderText
,
type
)
?:
listOf
()
return
gson
.
fromJson
<
List
<
DownloadBean
>?>(
olderText
,
type
)
?:
listOf
()
}
}
...
@@ -43,7 +44,7 @@ object DownloadUtils {
...
@@ -43,7 +44,7 @@ object DownloadUtils {
).
absolutePath
).
absolutePath
val
dirFile
=
File
(
dirPath
)
val
dirFile
=
File
(
dirPath
)
if
(!
dirFile
.
exists
()){
if
(!
dirFile
.
exists
())
{
dirFile
.
mkdirs
()
dirFile
.
mkdirs
()
}
}
...
@@ -77,11 +78,16 @@ object DownloadUtils {
...
@@ -77,11 +78,16 @@ object DownloadUtils {
fun
Context
.
saveDownloadRecordFile
(
downloadList
:
List
<
DownloadBean
>)
=
Thread
{
fun
Context
.
saveDownloadRecordFile
(
downloadList
:
List
<
DownloadBean
>)
=
Thread
{
downloadList
.
forEach
{
LogEx
.
logDebug
(
TAG
,
"saveDownloadRecordFile ${it.downloadId} ${it.name} ${it.path} status=${it.status}"
)
}
val
recordFile
=
getDownloadJson
()
val
recordFile
=
getDownloadJson
()
//已开始的任务
//已开始的任务
val
startedList
=
downloadList
.
filter
{
val
startedList
=
downloadList
.
filter
{
(
it
.
status
==
FileDownloadStatus
.
progress
||
it
.
status
==
FileDownloadStatus
.
paused
)
&&
!
it
.
isTime
(
it
.
status
==
FileDownloadStatus
.
progress
||
it
.
status
==
FileDownloadStatus
.
paused
)
&&
!
it
.
isTime
}
}
startedList
.
forEach
{
it
.
time
=
System
.
currentTimeMillis
()
}
startedList
.
forEach
{
it
.
time
=
System
.
currentTimeMillis
()
}
...
...
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