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
7cbdf3da
Commit
7cbdf3da
authored
Aug 08, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
d5231a14
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
198 additions
and
13 deletions
+198
-13
ConstObject.kt
app/src/main/java/com/base/browserwhite/bean/ConstObject.kt
+2
-1
FileFragment.kt
...in/java/com/base/browserwhite/ui/fragment/FileFragment.kt
+24
-0
MediaStoreUtils.kt
.../main/java/com/base/browserwhite/utils/MediaStoreUtils.kt
+162
-7
fragment_file.xml
app/src/main/res/layout/fragment_file.xml
+10
-5
No files found.
app/src/main/java/com/base/browserwhite/bean/ConstObject.kt
View file @
7cbdf3da
...
@@ -20,5 +20,6 @@ object ConstObject {
...
@@ -20,5 +20,6 @@ object ConstObject {
const
val
MIME_TYPE_XLSX
=
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
const
val
MIME_TYPE_XLSX
=
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
const
val
MIME_TYPE_PPT
=
"application/vnd.ms-powerpoint"
const
val
MIME_TYPE_PPT
=
"application/vnd.ms-powerpoint"
const
val
MIME_TYPE_PPTX
=
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
const
val
MIME_TYPE_PPTX
=
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
const
val
MIME_TYPE_APK
=
"application/vnd.android.package-archive/*"
const
val
MIME_TYPE_APK
=
"application/vnd.android.package-archive"
const
val
MIME_TYPE_ZIP
=
"application/zip"
}
}
\ No newline at end of file
app/src/main/java/com/base/browserwhite/ui/fragment/FileFragment.kt
View file @
7cbdf3da
...
@@ -14,6 +14,12 @@ import com.base.browserwhite.ui.activity.MainActivity
...
@@ -14,6 +14,12 @@ import com.base.browserwhite.ui.activity.MainActivity
import
com.base.browserwhite.ui.adapter.MediaAdapter
import
com.base.browserwhite.ui.adapter.MediaAdapter
import
com.base.browserwhite.utils.KotlinExt.toFormatSize
import
com.base.browserwhite.utils.KotlinExt.toFormatSize
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.MediaStoreUtils.getMediaApkSize
import
com.base.browserwhite.utils.MediaStoreUtils.getMediaAudioSize
import
com.base.browserwhite.utils.MediaStoreUtils.getMediaDocumentSize
import
com.base.browserwhite.utils.MediaStoreUtils.getMediaPhotoSize
import
com.base.browserwhite.utils.MediaStoreUtils.getMediaVideoSize
import
com.base.browserwhite.utils.MediaStoreUtils.getMediaZipSize
import
com.base.browserwhite.utils.MediaStoreUtils.getRecentMedia
import
com.base.browserwhite.utils.MediaStoreUtils.getRecentMedia
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
...
@@ -95,6 +101,24 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
...
@@ -95,6 +101,24 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
}
}
private
fun
initData
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
private
fun
initData
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
val
pictureSize
=
requireContext
().
getMediaPhotoSize
()
val
videoSize
=
requireContext
().
getMediaVideoSize
()
val
documentSize
=
requireContext
().
getMediaDocumentSize
()
val
apkSize
=
requireContext
().
getMediaApkSize
()
val
audioSize
=
requireContext
().
getMediaAudioSize
()
val
zipSize
=
requireContext
().
getMediaZipSize
()
launch
(
Dispatchers
.
Main
)
{
binding
.
tvPhotoSize
.
text
=
pictureSize
.
toString
()
binding
.
tvVideoSize
.
text
=
videoSize
.
toString
()
binding
.
tvDocument
.
text
=
documentSize
.
toString
()
binding
.
tvApkSize
.
text
=
apkSize
.
toString
()
binding
.
tvAudioSize
.
text
=
audioSize
.
toString
()
binding
.
tvZipSize
.
text
=
zipSize
.
toString
()
}
val
mediaList
=
requireContext
().
getRecentMedia
().
filter
{
val
mediaList
=
requireContext
().
getRecentMedia
().
filter
{
val
file
=
File
(
it
.
path
)
val
file
=
File
(
it
.
path
)
System
.
currentTimeMillis
()
-
file
.
lastModified
()
<=
15L
*
24
*
60
*
60
*
1000
System
.
currentTimeMillis
()
-
file
.
lastModified
()
<=
15L
*
24
*
60
*
60
*
1000
...
...
app/src/main/java/com/base/browserwhite/utils/MediaStoreUtils.kt
View file @
7cbdf3da
...
@@ -13,6 +13,7 @@ import com.base.browserwhite.bean.ConstObject.MIME_TYPE_PPTX
...
@@ -13,6 +13,7 @@ import com.base.browserwhite.bean.ConstObject.MIME_TYPE_PPTX
import
com.base.browserwhite.bean.ConstObject.MIME_TYPE_VIDEO
import
com.base.browserwhite.bean.ConstObject.MIME_TYPE_VIDEO
import
com.base.browserwhite.bean.ConstObject.MIME_TYPE_XLS
import
com.base.browserwhite.bean.ConstObject.MIME_TYPE_XLS
import
com.base.browserwhite.bean.ConstObject.MIME_TYPE_XLSX
import
com.base.browserwhite.bean.ConstObject.MIME_TYPE_XLSX
import
com.base.browserwhite.bean.ConstObject.MIME_TYPE_ZIP
import
com.base.browserwhite.bean.MediaBean
import
com.base.browserwhite.bean.MediaBean
...
@@ -67,7 +68,8 @@ object MediaStoreUtils {
...
@@ -67,7 +68,8 @@ object MediaStoreUtils {
)
)
if
(
cursor
!=
null
)
{
if
(
cursor
!=
null
)
{
while
(
cursor
.
moveToNext
())
{
while
(
cursor
.
moveToNext
())
{
// val id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID))
runCatching
{
// val id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID))
val
path
=
cursor
.
getString
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Files
.
FileColumns
.
DATA
))
val
path
=
cursor
.
getString
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Files
.
FileColumns
.
DATA
))
// val title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.TITLE))
// val title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.TITLE))
val
mimeType
=
cursor
.
getString
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Files
.
FileColumns
.
MIME_TYPE
))
val
mimeType
=
cursor
.
getString
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Files
.
FileColumns
.
MIME_TYPE
))
...
@@ -79,6 +81,7 @@ object MediaStoreUtils {
...
@@ -79,6 +81,7 @@ object MediaStoreUtils {
)
)
}
}
}
}
}
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
LogEx
.
logDebug
(
TAG
,
"Exception $e"
)
LogEx
.
logDebug
(
TAG
,
"Exception $e"
)
...
@@ -89,4 +92,156 @@ object MediaStoreUtils {
...
@@ -89,4 +92,156 @@ object MediaStoreUtils {
return
list
return
list
}
}
fun
Context
.
getMediaPhotoSize
():
Int
{
var
count
=
0
runCatching
{
val
contentResolver
=
this
.
contentResolver
// 定义查询的Uri和列
val
uri
=
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
val
projection
=
arrayOf
(
MediaStore
.
Images
.
Media
.
_ID
)
// 执行查询
val
cursor
=
contentResolver
.
query
(
uri
,
projection
,
null
,
null
,
null
)
// 检查cursor是否包含数据
count
=
cursor
?.
count
?:
0
// 关闭cursor
cursor
?.
close
()
}
return
count
}
fun
Context
.
getMediaVideoSize
():
Int
{
var
count
=
0
runCatching
{
val
contentResolver
=
this
.
contentResolver
// 定义查询的Uri和列
val
uri
=
MediaStore
.
Video
.
Media
.
EXTERNAL_CONTENT_URI
val
projection
=
arrayOf
(
MediaStore
.
Video
.
Media
.
_ID
)
// 执行查询
val
cursor
=
contentResolver
.
query
(
uri
,
projection
,
null
,
null
,
null
)
// 检查cursor是否包含数据
count
=
cursor
?.
count
?:
0
// 关闭cursor
cursor
?.
close
()
}
return
count
}
fun
Context
.
getMediaAudioSize
():
Int
{
var
count
=
0
runCatching
{
val
contentResolver
=
this
.
contentResolver
// 定义查询的Uri和列
val
uri
=
MediaStore
.
Audio
.
Media
.
EXTERNAL_CONTENT_URI
val
projection
=
arrayOf
(
MediaStore
.
Audio
.
Media
.
_ID
)
// 执行查询
val
cursor
=
contentResolver
.
query
(
uri
,
projection
,
null
,
null
,
null
)
// 检查cursor是否包含数据
count
=
cursor
?.
count
?:
0
// 关闭cursor
cursor
?.
close
()
}
return
count
}
fun
Context
.
getMediaDocumentSize
():
Int
{
var
count
=
0
runCatching
{
val
contentResolver
=
this
.
contentResolver
val
mimeTypeSelectionArgs
=
arrayOf
(
MIME_TYPE_PDF
,
MIME_TYPE_DOC
,
MIME_TYPE_DOCX
,
MIME_TYPE_XLS
,
MIME_TYPE_XLSX
,
MIME_TYPE_PPT
,
MIME_TYPE_PPTX
,
)
val
mimeTypeSelection
=
"${MediaStore.Files.FileColumns.MIME_TYPE} IN ("
+
mimeTypeSelectionArgs
.
joinToString
(
","
)
{
"?"
}
+
")"
// 定义查询的Uri和列
val
uri
=
MediaStore
.
Files
.
getContentUri
(
"external"
)
val
projection
=
arrayOf
(
MediaStore
.
Files
.
FileColumns
.
_ID
)
// 执行查询
val
cursor
=
contentResolver
.
query
(
uri
,
projection
,
mimeTypeSelection
,
mimeTypeSelectionArgs
,
null
)
// 检查cursor是否包含数据
count
=
cursor
?.
count
?:
0
// 关闭cursor
cursor
?.
close
()
}
return
count
}
fun
Context
.
getMediaApkSize
():
Int
{
var
count
=
0
runCatching
{
val
contentResolver
=
this
.
contentResolver
val
mimeTypeSelectionArgs
=
arrayOf
(
MIME_TYPE_APK
)
val
mimeTypeSelection
=
"${MediaStore.Files.FileColumns.MIME_TYPE} = ?"
// 定义查询的Uri和列
val
uri
=
MediaStore
.
Files
.
getContentUri
(
"external"
)
val
projection
=
arrayOf
(
MediaStore
.
Files
.
FileColumns
.
_ID
)
// 执行查询
val
cursor
=
contentResolver
.
query
(
uri
,
projection
,
mimeTypeSelection
,
mimeTypeSelectionArgs
,
null
)
// 检查cursor是否包含数据
count
=
cursor
?.
count
?:
0
// 关闭cursor
cursor
?.
close
()
}
return
count
}
fun
Context
.
getMediaZipSize
():
Int
{
var
count
=
0
runCatching
{
val
contentResolver
=
this
.
contentResolver
val
mimeTypeSelectionArgs
=
arrayOf
(
MIME_TYPE_ZIP
)
val
mimeTypeSelection
=
"${MediaStore.Files.FileColumns.MIME_TYPE} = ?"
// 定义查询的Uri和列
val
uri
=
MediaStore
.
Files
.
getContentUri
(
"external"
)
val
projection
=
arrayOf
(
MediaStore
.
Files
.
FileColumns
.
_ID
)
// 执行查询
val
cursor
=
contentResolver
.
query
(
uri
,
projection
,
mimeTypeSelection
,
mimeTypeSelectionArgs
,
null
)
// 检查cursor是否包含数据
count
=
cursor
?.
count
?:
0
// 关闭cursor
cursor
?.
close
()
}
return
count
}
}
}
\ No newline at end of file
app/src/main/res/layout/fragment_file.xml
View file @
7cbdf3da
...
@@ -264,7 +264,6 @@
...
@@ -264,7 +264,6 @@
android:layout_marginHorizontal=
"16dp"
android:layout_marginHorizontal=
"16dp"
android:layout_marginBottom=
"8dp"
android:layout_marginBottom=
"8dp"
android:background=
"@drawable/bg_storke_dee9f4"
android:background=
"@drawable/bg_storke_dee9f4"
android:elevation=
"2dp"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
<LinearLayout
<LinearLayout
...
@@ -301,6 +300,7 @@
...
@@ -301,6 +300,7 @@
tools:ignore=
"HardcodedText"
/>
tools:ignore=
"HardcodedText"
/>
<TextView
<TextView
android:id=
"@+id/tv_photo_size"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:layout_gravity=
"center"
...
@@ -336,6 +336,7 @@
...
@@ -336,6 +336,7 @@
tools:ignore=
"HardcodedText"
/>
tools:ignore=
"HardcodedText"
/>
<TextView
<TextView
android:id=
"@+id/tv_video_size"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:layout_gravity=
"center"
...
@@ -365,12 +366,13 @@
...
@@ -365,12 +366,13 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:layout_gravity=
"center_horizontal"
android:layout_marginTop=
"2dp"
android:layout_marginTop=
"2dp"
android:text=
"
Picture
"
android:text=
"
Document
"
android:textColor=
"#010101"
android:textColor=
"#010101"
android:textSize=
"14sp"
android:textSize=
"14sp"
tools:ignore=
"HardcodedText"
/>
tools:ignore=
"HardcodedText"
/>
<TextView
<TextView
android:id=
"@+id/tv_document"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:layout_gravity=
"center"
...
@@ -420,6 +422,7 @@
...
@@ -420,6 +422,7 @@
tools:ignore=
"HardcodedText"
/>
tools:ignore=
"HardcodedText"
/>
<TextView
<TextView
android:id=
"@+id/tv_apk_size"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:layout_gravity=
"center"
...
@@ -449,12 +452,13 @@
...
@@ -449,12 +452,13 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:layout_gravity=
"center_horizontal"
android:layout_marginTop=
"2dp"
android:layout_marginTop=
"2dp"
android:text=
"
Picture
"
android:text=
"
Music
"
android:textColor=
"#010101"
android:textColor=
"#010101"
android:textSize=
"14sp"
android:textSize=
"14sp"
tools:ignore=
"HardcodedText"
/>
tools:ignore=
"HardcodedText"
/>
<TextView
<TextView
android:id=
"@+id/tv_audio_size"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:layout_gravity=
"center"
...
@@ -484,12 +488,13 @@
...
@@ -484,12 +488,13 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:layout_gravity=
"center_horizontal"
android:layout_marginTop=
"2dp"
android:layout_marginTop=
"2dp"
android:text=
"
Pictur
e"
android:text=
"
Zip Fil
e"
android:textColor=
"#010101"
android:textColor=
"#010101"
android:textSize=
"14sp"
android:textSize=
"14sp"
tools:ignore=
"HardcodedText"
/>
tools:ignore=
"HardcodedText"
/>
<TextView
<TextView
android:id=
"@+id/tv_zip_size"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:layout_gravity=
"center"
...
@@ -515,12 +520,12 @@
...
@@ -515,12 +520,12 @@
tools:ignore=
"HardcodedText"
/>
tools:ignore=
"HardcodedText"
/>
<LinearLayout
<LinearLayout
android:background=
"@drawable/bg_storke_dee9f4"
android:id=
"@+id/ll_permission"
android:id=
"@+id/ll_permission"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"75dp"
android:layout_height=
"75dp"
android:layout_marginHorizontal=
"15dp"
android:layout_marginHorizontal=
"15dp"
android:layout_marginTop=
"18dp"
android:layout_marginTop=
"18dp"
android:background=
"@drawable/bg_storke_dee9f4"
android:orientation=
"horizontal"
>
android:orientation=
"horizontal"
>
<ImageView
<ImageView
...
...
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