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
3fa3215f
Commit
3fa3215f
authored
Aug 23, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
0005e330
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
154 additions
and
64 deletions
+154
-64
build.gradle.kts
app/build.gradle.kts
+1
-0
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+4
-0
WebViewFragment.kt
...se/browserwhite/ui/activity/webbrowser/WebViewFragment.kt
+52
-13
DownloadAdapter.kt
.../java/com/base/browserwhite/ui/adapter/DownloadAdapter.kt
+27
-1
FileFragment.kt
...in/java/com/base/browserwhite/ui/fragment/FileFragment.kt
+15
-9
ColorProgress.kt
...main/java/com/base/browserwhite/ui/views/ColorProgress.kt
+0
-2
DialogViews.kt
...c/main/java/com/base/browserwhite/ui/views/DialogViews.kt
+2
-0
DownloadHelper.kt
...c/main/java/com/base/browserwhite/utils/DownloadHelper.kt
+33
-0
ViewExts.kt
app/src/main/java/com/base/browserwhite/utils/ViewExts.kt
+0
-8
progress_bar_download.xml
app/src/main/res/drawable/progress_bar_download.xml
+0
-22
item_download_card.xml
app/src/main/res/layout/item_download_card.xml
+20
-9
t_wancheng_download.png
app/src/main/res/mipmap-xxhdpi/t_wancheng_download.png
+0
-0
No files found.
app/build.gradle.kts
View file @
3fa3215f
...
...
@@ -98,6 +98,7 @@ dependencies {
implementation
(
"de.hdodenhof:circleimageview:3.1.0"
)
implementation
(
"com.github.pokercc:ExpandableRecyclerView:0.9.3"
)
implementation
(
"io.github.cymchad:BaseRecyclerViewAdapterHelper4:4.1.4"
)
implementation
(
"com.mikhaellopez:circularprogressbar:3.1.0"
)
//相机
val
cameraxVersion
=
"1.2.2"
...
...
app/src/main/AndroidManifest.xml
View file @
3fa3215f
...
...
@@ -132,6 +132,10 @@
android:name=
".service.StayNotificationService"
android:foregroundServiceType=
"dataSync"
/>
<meta-data
android:name=
"com.google.android.gms.ads.APPLICATION_ID"
android:value=
"ca-app-pub-3940256099942544~3347511713"
/>
<meta-data
android:name=
"com.facebook.sdk.ApplicationId"
android:value=
"@string/facebook_app_id"
/>
...
...
app/src/main/java/com/base/browserwhite/ui/activity/webbrowser/WebViewFragment.kt
View file @
3fa3215f
package
com.base.browserwhite.ui.activity.webbrowser
import
android.annotation.SuppressLint
import
android.app.DownloadManager
import
android.net.Uri
import
android.net.http.SslError
import
android.view.View
...
...
@@ -21,22 +22,27 @@ import com.base.browserwhite.databinding.FragmentWebViewBinding
import
com.base.browserwhite.ui.adapter.DownloadAdapter
import
com.base.browserwhite.ui.fragment.BaseFragment
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.VideoDownloader
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.Job
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.isActive
import
kotlinx.coroutines.launch
import
org.json.JSONArray
import
java.io.File
import
java.lang.reflect.Type
import
kotlin.random.Random
class
WebViewFragment
:
BaseFragment
<
FragmentWebViewBinding
>()
{
private
val
TAG
=
"WebViewFragment"
private
var
progressJob
:
Job
?
=
null
var
url
:
String
=
""
private
val
downloadList
=
arrayListOf
<
DownloadBean
>()
...
...
@@ -81,31 +87,58 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
bean
.
path
=
pair
.
second
.
absolutePath
},
dismissAction
=
{
progressJob
?.
cancel
()
isUpdating
=
false
saveDownloadRecordFile
(
downloadList
)
},
)
progressJob
?.
cancel
()
progressJob
=
upDataProgress
(
adapter
)
isUpdating
=
true
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"
)
private
fun
upDataProgress
(
adapter
:
DownloadAdapter
)
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
private
fun
upDataProgress
(
adapter
:
DownloadAdapter
)
=
Thread
{
while
(
is
Active
)
{
downloadList
.
forEach
{
bean
:
DownloadBean
->
while
(
is
Updating
)
{
downloadList
.
f
ilter
{
it
.
state
==
DownloadManager
.
STATUS_RUNNING
}.
f
orEach
{
bean
:
DownloadBean
->
queryDownloadProgress
(
requireContext
(),
bean
.
downloadId
,
uiAction
=
{
progress
->
LogEx
.
logDebug
(
TAG
,
"item ${bean.downloadId} progress=$progress "
)
bean
.
progress
=
progress
},
noRunningAction
=
{
status
->
bean
.
state
=
status
})
}
adapter
.
notifyDataSetChanged
()
delay
(
1000
)
binding
.
root
.
post
{
adapter
.
notifyDataSetChanged
()
}
Thread
.
sleep
(
250
)
}
}
}
.
start
()
private
fun
reloadWebView
()
{
binding
.
llError
.
visibility
=
View
.
GONE
...
...
@@ -161,7 +194,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
)
{
...
...
@@ -279,11 +312,17 @@ class WebViewFragment : BaseFragment<FragmentWebViewBinding>() {
binding
.
flDownload
.
visibility
=
View
.
VISIBLE
binding
.
tvDownloadNumber
.
text
=
jsonArray
.
length
().
toString
()
}
val
recordFile
=
requireContext
().
getDownloadJson
()
val
olderList
=
getOlderList
(
recordFile
,
Gson
())
for
(
i
in
0
until
jsonArray
.
length
())
{
val
videoUrl
=
jsonArray
.
optString
(
i
)
LogEx
.
logDebug
(
TAG
,
videoUrl
)
downloadList
.
add
(
DownloadBean
(
uri
=
videoUrl
).
apply
{
uiType
=
2
})
val
olderBean
=
olderList
.
findLast
{
it
.
uri
==
videoUrl
}
if
(
olderBean
!=
null
)
{
downloadList
.
add
(
olderBean
)
}
else
{
downloadList
.
add
(
DownloadBean
(
uri
=
videoUrl
).
apply
{
uiType
=
2
})
}
}
isParsing
=
false
})
...
...
app/src/main/java/com/base/browserwhite/ui/adapter/DownloadAdapter.kt
View file @
3fa3215f
package
com.base.browserwhite.ui.adapter
import
android.app.DownloadManager
import
android.content.Context
import
android.view.View
import
android.view.ViewGroup
import
androidx.core.view.isVisible
import
androidx.recyclerview.widget.RecyclerView.ViewHolder
import
com.base.browserwhite.R
import
com.base.browserwhite.bean.DownloadBean
...
...
@@ -36,10 +38,34 @@ class DownloadAdapter : BaseQuickAdapter<DownloadBean, DownloadAdapter.DownloadV
}
else
if
(
item
.
uiType
==
2
)
{
val
binding
=
ItemDownloadCardBinding
.
bind
(
holder
.
itemView
)
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
{
downloadAction
?.
invoke
(
item
)
}
}
}
...
...
app/src/main/java/com/base/browserwhite/ui/fragment/FileFragment.kt
View file @
3fa3215f
...
...
@@ -195,21 +195,27 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
}
binding
.
colorProgress
.
finishAnimation
=
{
val
list
=
requireContext
().
getMediaFile
().
filter
{
val
file
=
File
(
it
.
path
)
if
(
BuildConfig
.
DEBUG
)
{
true
}
else
{
System
.
currentTimeMillis
()
-
file
.
lastModified
()
<=
15L
*
24
*
60
*
60
*
1000
}
initMediaData
()
}
}
private
fun
initMediaData
()
=
Thread
{
val
list
=
requireContext
().
getMediaFile
().
filter
{
val
file
=
File
(
it
.
path
)
if
(
BuildConfig
.
DEBUG
)
{
true
}
else
{
System
.
currentTimeMillis
()
-
file
.
lastModified
()
<=
15L
*
24
*
60
*
60
*
1000
}
}
binding
.
root
.
post
{
if
(
list
.
isEmpty
())
{
binding
.
tvTitleRecent
.
visibility
=
View
.
GONE
}
adapter
.
setData
(
list
)
}
}
}.
start
()
}
\ No newline at end of file
app/src/main/java/com/base/browserwhite/ui/views/ColorProgress.kt
View file @
3fa3215f
package
com.base.browserwhite.ui.views
import
android.animation.Animator
import
android.animation.AnimatorListenerAdapter
import
android.animation.AnimatorSet
import
android.animation.ValueAnimator
import
android.content.Context
import
android.graphics.Canvas
...
...
app/src/main/java/com/base/browserwhite/ui/views/DialogViews.kt
View file @
3fa3215f
...
...
@@ -3,6 +3,7 @@ package com.base.browserwhite.ui.views
import
android.annotation.SuppressLint
import
android.app.AlertDialog
import
android.app.Dialog
import
android.app.DownloadManager
import
android.content.Context
import
android.graphics.Color
import
android.graphics.drawable.ColorDrawable
...
...
@@ -253,6 +254,7 @@ object DialogViews {
adapter
.
downloadAction
=
{
item
:
DownloadBean
->
dialog
.
dismiss
()
showDownloadConfirmDialog
(
item
)
{
item
.
state
=
DownloadManager
.
STATUS_RUNNING
download
.
invoke
(
item
)
}
}
...
...
app/src/main/java/com/base/browserwhite/utils/DownloadHelper.kt
0 → 100644
View file @
3fa3215f
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
app/src/main/java/com/base/browserwhite/utils/ViewExts.kt
deleted
100644 → 0
View file @
0005e330
package
com.base.browserwhite.utils
import
android.view.View
internal
fun
View
.
scale
(
factor
:
Float
)
{
scaleX
=
factor
scaleY
=
factor
}
app/src/main/res/drawable/progress_bar_download.xml
deleted
100644 → 0
View file @
0005e330
<?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
app/src/main/res/layout/item_download_card.xml
View file @
3fa3215f
...
...
@@ -80,20 +80,31 @@
android:visibility=
"gone"
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
android:visibility=
"gone"
android:id=
"@+id/fl_download"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<ProgressBar
android:id=
"@+id/progress_bar"
android:layout_width=
"35dp"
android:layout_height=
"35dp"
android:indeterminate=
"false"
android:max=
"100"
android:progressDrawable=
"@drawable/progress_bar_clean"
tools:progress=
"50"
/>
<com.mikhaellopez.circularprogressbar.CircularProgressBar
android:id=
"@+id/circularProgressBar"
android:layout_width=
"30dp"
android:layout_height=
"30dp"
app:cpb_background_progressbar_color=
"#E8E8F1"
app:cpb_background_progressbar_width=
"3dp"
app:cpb_progress_direction=
"to_left"
app:cpb_progress_max=
"100"
app:cpb_progressbar_color=
"#0570EC"
app:cpb_progressbar_width=
"3dp"
app:cpb_round_border=
"true"
/>
<ImageView
android:id=
"@+id/iv_xiazai_zantin"
...
...
app/src/main/res/mipmap-xxhdpi/t_wancheng_download.png
0 → 100644
View file @
3fa3215f
5.19 KB
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