Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
F
FileManager
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
yanglin
FileManager
Commits
ef567503
Commit
ef567503
authored
Apr 16, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片卡顿
parent
1fa11825
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
212 additions
and
126 deletions
+212
-126
build.gradle
MyDemo3/app/build.gradle
+2
-0
MediaActivity.kt
...n/java/com/xm/test/myfilemaster/activity/MediaActivity.kt
+38
-30
MediaAdapter2.kt
...in/java/com/xm/test/myfilemaster/adapter/MediaAdapter2.kt
+53
-0
FileUtil.kt
...p/src/main/java/com/xm/test/myfilemaster/util/FileUtil.kt
+73
-65
GlideApp.kt
...p/src/main/java/com/xm/test/myfilemaster/util/GlideApp.kt
+8
-0
activity_media.xml
MyDemo3/app/src/main/res/layout/activity_media.xml
+24
-31
item_image_video.xml
MyDemo3/app/src/main/res/layout/item_image_video.xml
+14
-0
No files found.
MyDemo3/app/build.gradle
View file @
ef567503
...
...
@@ -97,4 +97,6 @@ dependencies {
// compile(name:'trustlook_cleanjunk_sdk_release_3.0.4.20240322',ext:'aar')
implementation
files
(
'libs/trustlook_cleanjunk_sdk_release_3.0.4.20240322.aar'
)
implementation
files
(
'libs/cloudscan_sdk_5.0.5.20240306.aar'
)
implementation
(
"com.github.bumptech.glide:glide:4.15.1"
)
}
MyDemo3/app/src/main/java/com/xm/test/myfilemaster/activity/MediaActivity.kt
View file @
ef567503
...
...
@@ -13,6 +13,8 @@ import androidx.lifecycle.ViewModelProvider
import
com.kongzue.dialogx.dialogs.WaitDialog
import
com.xm.test.myfilemaster.R
import
com.xm.test.myfilemaster.adapter.MediaAdapter
import
com.xm.test.myfilemaster.adapter.MediaAdapter2
import
com.xm.test.myfilemaster.databinding.ActivityMediaBinding
import
com.xm.test.myfilemaster.model.FileBean
import
com.xm.test.myfilemaster.util.FileUtil
...
...
@@ -32,7 +34,10 @@ class MediaActivity : AppCompatActivity() {
lateinit
var
mItemCheckedArray
:
SparseBooleanArray
private
var
mItemDataList
=
ArrayList
<
FileBean
>()
private
var
mItemAdapter
:
MediaAdapter
?
=
null
private
lateinit
var
binding
:
ActivityMediaBinding
// private var mItemAdapter: MediaAdapter? = null
private
var
mItemAdapter
:
MediaAdapter2
?
=
null
private
var
mDataList
:
ArrayList
<
String
>
=
ArrayList
<
String
>()
private
var
mCheckedDataList
:
ArrayList
<
String
>
=
ArrayList
<
String
>()
...
...
@@ -40,27 +45,28 @@ class MediaActivity : AppCompatActivity() {
private
lateinit
var
mModel
:
BaseActivityViewModel
val
mFileTypeBeanList
:
ArrayList
<
String
>
=
ArrayList
()
val
mFileTypeBeanList
:
ArrayList
<
String
>
=
ArrayList
()
var
mShowBeanData
:
ArrayList
<
String
>
=
ArrayList
()
var
mStartNumber
:
Int
=
0
var
mIsCheckClick
=
false
companion
object
{
companion
object
{
var
isClickEditBtn
=
false
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_media
)
binding
=
ActivityMediaBinding
.
inflate
(
layoutInflater
)
setContentView
(
binding
.
root
)
initView
()
}
@SuppressLint
(
"ClickableViewAccessibility"
)
private
fun
initView
()
{
mGridView
=
findViewById
(
R
.
id
.
image_item_grid
)
//
mGridView = findViewById(R.id.image_item_grid)
mTitleBar
=
findViewById
(
R
.
id
.
title_bar
)
mSelectBar
=
findViewById
(
R
.
id
.
switch_and_select_layout
)
// mScrollView = findViewById(R.id.grid_view_scroll)
...
...
@@ -81,17 +87,19 @@ class MediaActivity : AppCompatActivity() {
mItemCheckedArray
=
SparseBooleanArray
()
val
fileType
=
intent
.
getStringExtra
(
"fileType"
).
toString
()
mItemAdapter
=
MediaAdapter
(
mItemDataList
,
this
,
mItemCheckedArray
,
fileType
,
118
)
mGridView
.
adapter
=
mItemAdapter
// mItemAdapter = MediaAdapter(mItemDataList, this, mItemCheckedArray, fileType, 118)
mItemAdapter
=
MediaAdapter2
()
// mGridView.adapter = mItemAdapter
binding
.
imageItemGrid
.
adapter
=
mItemAdapter
Thread
(
Runnable
{
WaitDialog
.
show
(
"please wait.."
)
mItemDataList
=
FileUtil
.
getMediaFiles
(
this
,
fileType
,
20
)
runOnUiThread
{
mItemAdapter
?.
setData
(
mItemDataList
)
WaitDialog
.
dismiss
()
for
(
fileBean
in
mItemDataList
){
for
(
fileBean
in
mItemDataList
)
{
mDataList
.
add
(
fileBean
.
filePath
)
}
mItemAdapter
?.
setData
(
mItemDataList
)
}
}).
start
()
...
...
@@ -131,31 +139,31 @@ class MediaActivity : AppCompatActivity() {
}
}
private
fun
setOnGridViewItemClickListener
(){
mGridView
.
setOnItemClickListener
{
parent
,
view
,
position
,
id
->
if
(
isClickEditBtn
)
{
updateCheckBoxStatus
(
view
,
position
)
}
else
{
//TODO 点击进入图片或视频播放
}
}
private
fun
setOnGridViewItemClickListener
()
{
//
mGridView.setOnItemClickListener { parent, view, position, id ->
// if (isClickEditBtn)
{
//
updateCheckBoxStatus(view, position)
// } else
{
//
//TODO 点击进入图片或视频播放
//
}
//
}
}
private
fun
setStateCheckedMap
(
isChecked
:
Boolean
){
for
(
i
in
mDataList
.
indices
)
{
private
fun
setStateCheckedMap
(
isChecked
:
Boolean
)
{
for
(
i
in
mDataList
.
indices
)
{
mItemCheckedArray
.
put
(
i
,
isChecked
)
mGridView
.
setItemChecked
(
i
,
isChecked
)
}
}
private
fun
updateCheckBoxStatus
(
view
:
View
,
position
:
Int
){
private
fun
updateCheckBoxStatus
(
view
:
View
,
position
:
Int
)
{
val
viewHolder
=
view
.
tag
as
MediaAdapter
.
ViewHolder
viewHolder
.
checkedBox
.
toggle
()
mGridView
.
setItemChecked
(
position
,
viewHolder
.
checkedBox
.
isChecked
)
mItemCheckedArray
.
put
(
position
,
viewHolder
.
checkedBox
.
isChecked
)
if
(
viewHolder
.
checkedBox
.
isChecked
){
if
(
viewHolder
.
checkedBox
.
isChecked
)
{
mCheckedDataList
.
add
(
mDataList
[
position
])
}
else
{
}
else
{
mCheckedDataList
.
remove
(
mDataList
[
position
])
}
mItemAdapter
?.
notifyDataSetChanged
()
...
...
@@ -163,14 +171,14 @@ class MediaActivity : AppCompatActivity() {
mModel
.
setNumber
(
mCheckedNumber
)
}
private
fun
selectAll
(){
private
fun
selectAll
()
{
mCheckedDataList
.
clear
()
mCheckedNumber
=
if
(
mIsCheckClick
){
setStateCheckedMap
(
true
)
mCheckedNumber
=
if
(
mIsCheckClick
)
{
setStateCheckedMap
(
true
)
mCheckedDataList
.
addAll
(
mDataList
)
mCheckedDataList
.
size
}
else
{
setStateCheckedMap
(
false
)
}
else
{
setStateCheckedMap
(
false
)
0
}
mModel
.
setNumber
(
mCheckedNumber
)
...
...
@@ -179,9 +187,9 @@ class MediaActivity : AppCompatActivity() {
override
fun
onBackPressed
()
{
mItemAdapter
?.
notifyDataSetChanged
()
if
(
isClickEditBtn
){
if
(
isClickEditBtn
)
{
cancelBtn
()
}
else
{
}
else
{
super
.
onBackPressed
()
}
}
...
...
MyDemo3/app/src/main/java/com/xm/test/myfilemaster/adapter/MediaAdapter2.kt
0 → 100644
View file @
ef567503
package
com.xm.test.myfilemaster.adapter
import
android.annotation.SuppressLint
import
android.content.Context
import
android.util.SparseBooleanArray
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.BaseAdapter
import
android.widget.CheckBox
import
android.widget.ImageView
import
androidx.recyclerview.widget.RecyclerView
import
com.bumptech.glide.Glide
import
com.xm.test.myfilemaster.R
import
com.xm.test.myfilemaster.activity.MediaActivity
import
com.xm.test.myfilemaster.databinding.ItemImageVideoBinding
import
com.xm.test.myfilemaster.model.FileBean
import
com.xm.test.myfilemaster.util.FileUtil
class
MediaAdapter2
:
RecyclerView
.
Adapter
<
MediaAdapter2
.
CCC
>()
{
private
var
mListData
:
ArrayList
<
FileBean
>
=
arrayListOf
()
fun
Int
.
inflate
(
parent
:
ViewGroup
,
attachToRoot
:
Boolean
=
false
):
View
{
return
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
this
,
parent
,
attachToRoot
)
}
class
CCC
(
view
:
View
)
:
RecyclerView
.
ViewHolder
(
view
)
{
val
binding
=
ItemImageVideoBinding
.
bind
(
view
)
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
CCC
{
return
CCC
(
R
.
layout
.
item_image_video
.
inflate
(
parent
))
}
override
fun
getItemCount
():
Int
{
return
mListData
.
size
}
override
fun
onBindViewHolder
(
holder
:
CCC
,
position
:
Int
)
{
val
data
=
mListData
[
position
]
val
context
=
holder
.
binding
.
root
.
context
Glide
.
with
(
context
).
load
(
data
.
filePath
).
centerCrop
().
into
(
holder
.
binding
.
ivMedia
)
}
@SuppressLint
(
"NotifyDataSetChanged"
)
fun
setData
(
datas
:
List
<
FileBean
>)
{
mListData
.
clear
()
mListData
.
addAll
(
datas
)
notifyDataSetChanged
()
}
}
\ No newline at end of file
MyDemo3/app/src/main/java/com/xm/test/myfilemaster/util/FileUtil.kt
View file @
ef567503
...
...
@@ -23,7 +23,7 @@ object FileUtil {
const
val
TEXT_MIME_TYPE
=
"text/plain"
const
val
ZIP_MIME_TYPE
=
"application/zip"
const
val
RAR_MIME_TYPE
=
"application/x-rar-compressed"
const
val
ZIP_7Z_MIME_TYPE
=
"application/x-7z-compressed"
const
val
ZIP_7Z_MIME_TYPE
=
"application/x-7z-compressed"
const
val
PDF_MIME_TYPE
=
"application/pdf"
const
val
WORD_MIME_TYPE
=
"application/msword"
const
val
EXCEL_MIME_TYPE
=
"application/vnd.ms-excel"
...
...
@@ -32,7 +32,7 @@ object FileUtil {
const
val
MP3_MIME_TYPE
=
"audio/mpeg"
const
val
WAV_MIME_TYPE
=
"audio/x-wav"
fun
getFileCreateTime
(
filePath
:
String
)
:
Triple
<
Int
,
Int
,
Int
>
{
fun
getFileCreateTime
(
filePath
:
String
)
:
Triple
<
Int
,
Int
,
Int
>
{
val
folder
=
File
(
filePath
)
val
fileCreateTime
=
folder
.
lastModified
()
val
date
=
Date
(
fileCreateTime
)
...
...
@@ -41,14 +41,14 @@ object FileUtil {
return
Triple
(
yearMonthDay
[
0
].
toInt
(),
yearMonthDay
[
1
].
toInt
(),
yearMonthDay
[
2
].
toInt
())
}
fun
createDirectory
(
path
:
String
,
fileDirName
:
String
):
FileBean
{
fun
createDirectory
(
path
:
String
,
fileDirName
:
String
):
FileBean
{
val
fileBean
=
FileBean
()
val
file
=
File
(
path
+
"/"
+
fileDirName
)
fileBean
.
filePath
=
"-1"
if
(!
file
.
exists
()){
if
(!
file
.
exists
())
{
val
mkdirs
=
file
.
mkdirs
()
if
(
mkdirs
){
if
(
file
.
isDirectory
){
if
(
mkdirs
)
{
if
(
file
.
isDirectory
)
{
fileBean
.
fileName
=
file
.
name
fileBean
.
filePath
=
file
.
path
fileBean
.
fileSize
=
file
.
length
()
...
...
@@ -63,8 +63,8 @@ object FileUtil {
@SuppressLint
(
"Range"
)
fun
scanFiles
(
context
:
Context
,
uri
:
Uri
,
minSize
:
Long
)
:
ArrayList
<
FileBean
>
{
var
filesItemBean
:
FileBean
fun
scanFiles
(
context
:
Context
,
uri
:
Uri
,
minSize
:
Long
)
:
ArrayList
<
FileBean
>
{
var
filesItemBean
:
FileBean
var
fileListItemBean
=
ArrayList
<
FileBean
>()
val
projection
=
arrayOf
(
MediaStore
.
Files
.
FileColumns
.
_ID
,
...
...
@@ -72,22 +72,25 @@ object FileUtil {
MediaStore
.
Files
.
FileColumns
.
SIZE
)
val
cursor
=
context
.
contentResolver
.
query
(
uri
,
projection
,
null
,
null
,
null
)
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
()){
val
cursor
=
context
.
contentResolver
.
query
(
uri
,
projection
,
null
,
null
,
null
)
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
do
{
val
fileSize
=
cursor
.
getLong
(
cursor
.
getColumnIndex
(
MediaStore
.
Files
.
FileColumns
.
SIZE
))
if
(
fileSize
>
minSize
){
val
fileSize
=
cursor
.
getLong
(
cursor
.
getColumnIndex
(
MediaStore
.
Files
.
FileColumns
.
SIZE
))
if
(
fileSize
>
minSize
)
{
filesItemBean
=
FileBean
()
filesItemBean
.
fileName
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
Files
.
FileColumns
.
DISPLAY_NAME
))
filesItemBean
.
fileName
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
Files
.
FileColumns
.
DISPLAY_NAME
))
filesItemBean
.
fileSize
=
fileSize
filesItemBean
.
filePath
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
Files
.
FileColumns
.
RELATIVE_PATH
))
filesItemBean
.
filePath
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
Files
.
FileColumns
.
RELATIVE_PATH
))
filesItemBean
.
isDir
=
false
filesItemBean
.
fileType
=
getFileType
(
File
(
filesItemBean
.
filePath
))
fileListItemBean
.
add
(
filesItemBean
)
}
}
while
(
cursor
.
moveToNext
())
}
while
(
cursor
.
moveToNext
())
cursor
.
close
()
}
...
...
@@ -96,31 +99,31 @@ object FileUtil {
}
@SuppressLint
(
"Range"
)
fun
sanRecursive
(
context
:
Context
,
uri
:
Uri
,
minSize
:
Long
):
ArrayList
<
FileBean
>{
fun
sanRecursive
(
context
:
Context
,
uri
:
Uri
,
minSize
:
Long
):
ArrayList
<
FileBean
>
{
var
filesItemBeanList
=
ArrayList
<
FileBean
>()
filesItemBeanList
.
addAll
(
scanFiles
(
context
,
uri
,
minSize
))
val
selection
=
MediaStore
.
Files
.
FileColumns
.
MEDIA_TYPE
+
"="
+
MediaStore
.
Files
.
FileColumns
.
MEDIA_TYPE_NONE
val
sortOrder
=
MediaStore
.
Files
.
FileColumns
.
DATE_MODIFIED
val
cursor
=
context
.
contentResolver
.
query
(
uri
,
null
,
selection
,
null
,
sortOrder
)
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
()){
val
cursor
=
context
.
contentResolver
.
query
(
uri
,
null
,
selection
,
null
,
sortOrder
)
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
do
{
val
fileId
=
cursor
.
getLong
(
cursor
.
getColumnIndex
(
MediaStore
.
Files
.
FileColumns
.
_ID
))
val
chiIdUri
=
Uri
.
withAppendedPath
(
uri
,
""
+
fileId
)
filesItemBeanList
.
addAll
(
scanFiles
(
context
,
chiIdUri
,
minSize
))
val
chiIdUri
=
Uri
.
withAppendedPath
(
uri
,
""
+
fileId
)
filesItemBeanList
.
addAll
(
scanFiles
(
context
,
chiIdUri
,
minSize
))
}
while
(
cursor
.
moveToNext
())
}
while
(
cursor
.
moveToNext
())
cursor
.
close
()
}
return
filesItemBeanList
}
fun
getAllFilesAndDirectories
(
context
:
Context
):
ArrayList
<
FileBean
>{
fun
getAllFilesAndDirectories
(
context
:
Context
):
ArrayList
<
FileBean
>
{
var
fileList
=
ArrayList
<
FileBean
>()
// val internalStorageDir = context.filesDir
val
internalStorageDir
=
File
(
EXTERNAL_STORAGE
)
if
(
internalStorageDir
!=
null
&&
internalStorageDir
.
exists
()){
if
(
internalStorageDir
!=
null
&&
internalStorageDir
.
exists
())
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
traverseDirectory
(
internalStorageDir
,
fileList
)
}
...
...
@@ -129,22 +132,22 @@ object FileUtil {
return
fileList
}
fun
traverseDirectory
(
directory
:
File
,
fileList
:
ArrayList
<
FileBean
>)
{
fun
traverseDirectory
(
directory
:
File
,
fileList
:
ArrayList
<
FileBean
>)
{
val
files
=
directory
.
listFiles
()
if
(
files
!=
null
)
{
for
(
file
:
File
in
files
){
if
(
files
!=
null
)
{
for
(
file
:
File
in
files
)
{
val
fileBean
:
FileBean
=
FileBean
()
fileBean
.
fileName
=
file
.
name
fileBean
.
filePath
=
file
.
path
fileBean
.
isDir
=
file
.
isDirectory
// val type = Files.probeContentType(Paths.get(file.path))
if
(
file
.
isDirectory
){
if
(
file
.
isDirectory
)
{
val
children
=
ArrayList
<
FileBean
>()
// traverseDirectory(file, children)
fileBean
.
childList
=
children
fileBean
.
fileType
=
"dir"
}
else
{
}
else
{
fileBean
.
fileType
=
getFileType
(
file
)
fileBean
.
fileSize
=
file
.
length
()
}
...
...
@@ -153,44 +156,44 @@ object FileUtil {
}
}
fun
getFileList
(
directory
:
File
)
:
ArrayList
<
FileBean
>
{
fun
getFileList
(
directory
:
File
)
:
ArrayList
<
FileBean
>
{
val
fileBeans
=
ArrayList
<
FileBean
>()
// val directory = Environment.getExternalStorageDirectory()
val
files
=
directory
.
listFiles
()
for
(
file
in
files
!!
){
for
(
file
in
files
!!
)
{
if
(!
file
.
isHidden
&&
!
file
.
name
.
startsWith
(
"."
)
&&
file
.
name
!=
".face"
)
{
val
fileBean
=
FileBean
()
fileBean
.
fileName
=
file
.
name
fileBean
.
filePath
=
file
.
path
fileBean
.
isDir
=
file
.
isDirectory
// val type = Files.probeContentType(Paths.get(file.path))
if
(
file
.
isDirectory
){
if
(
file
.
isDirectory
)
{
val
children
=
ArrayList
<
FileBean
>()
traverseDirectory
(
file
,
children
)
fileBean
.
childList
=
children
fileBean
.
fileType
=
"dir"
}
else
{
}
else
{
fileBean
.
fileType
=
getFileType
(
file
)
fileBean
.
fileSize
=
file
.
length
()
}
Log
.
e
(
"yanglin"
,
"getFileList: childList.size = ${fileBean.childList.size}"
,
)
Log
.
e
(
"yanglin"
,
"getFileList: childList.size = ${fileBean.childList.size}"
)
fileBeans
.
add
(
fileBean
)
}
}
return
fileBeans
}
fun
getFileType
(
file
:
File
):
String
{
fun
getFileType
(
file
:
File
):
String
{
val
fileName
=
file
.
name
val
indexOf
=
fileName
.
lastIndexOf
(
"."
)
if
(
indexOf
!=
-
1
&&
indexOf
<
fileName
.
length
-
1
)
{
if
(
indexOf
!=
-
1
&&
indexOf
<
fileName
.
length
-
1
)
{
return
fileName
.
substring
(
indexOf
+
1
)
}
else
{
}
else
{
return
"notType"
}
}
fun
fileListSort
(
fileList
:
ArrayList
<
FileBean
>):
ArrayList
<
FileBean
>{
fun
fileListSort
(
fileList
:
ArrayList
<
FileBean
>):
ArrayList
<
FileBean
>
{
fileList
.
sortWith
(
Comparator
{
fileBean1
,
fileBean2
->
if
(
File
(
fileBean1
.
filePath
).
isDirectory
&&
!
File
(
fileBean2
.
filePath
).
isDirectory
)
{
-
1
...
...
@@ -202,10 +205,11 @@ object FileUtil {
})
return
fileList
}
/**
* 查询大于10M的文件
* ***/
fun
search10MFiles
(
context
:
Context
,
sizeInByte
:
Int
):
ArrayList
<
FileBean
>{
fun
search10MFiles
(
context
:
Context
,
sizeInByte
:
Int
):
ArrayList
<
FileBean
>
{
val
fileBeans
=
ArrayList
<
FileBean
>()
val
projection
=
arrayOf
(
MediaStore
.
Files
.
FileColumns
.
DATA
,
...
...
@@ -259,27 +263,28 @@ object FileUtil {
return
allDeleted
}
fun
moveFile
(
path
:
String
,
destinationPath
:
String
)
:
Boolean
{
fun
moveFile
(
path
:
String
,
destinationPath
:
String
)
:
Boolean
{
val
file
=
File
(
path
)
val
destinationFile
=
File
(
destinationPath
)
Log
.
e
(
"yanglin"
,
"moveFile: filePath = ${path}, currentPath = $destinationPath"
,
)
Log
.
e
(
"yanglin"
,
"moveFile: filePath = ${path}, currentPath = $destinationPath"
)
return
file
.
renameTo
(
destinationFile
)
}
fun
copyFile
(
path
:
String
,
destinationPath
:
String
):
Boolean
{
fun
copyFile
(
path
:
String
,
destinationPath
:
String
):
Boolean
{
return
try
{
File
(
path
).
inputStream
().
use
{
input
->
File
(
destinationPath
).
outputStream
().
use
{
output
->
File
(
path
).
inputStream
().
use
{
input
->
File
(
destinationPath
).
outputStream
().
use
{
output
->
input
.
copyTo
(
output
)
}
}
true
}
catch
(
e
:
IOException
)
{
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
false
}
}
fun
scanEmptyFiles
(
filePath
:
String
,
fileList
:
ArrayList
<
FileBean
>){
fun
scanEmptyFiles
(
filePath
:
String
,
fileList
:
ArrayList
<
FileBean
>)
{
val
files
=
File
(
filePath
).
listFiles
()
// 获取当前目录下的所有文件和文件夹
if
(
files
!=
null
)
{
for
(
file
in
files
)
{
...
...
@@ -292,15 +297,15 @@ object FileUtil {
fileBean
.
isDir
=
true
fileList
.
add
(
fileBean
)
}
else
if
(
file
.
isDirectory
)
{
scanEmptyFiles
(
file
.
path
,
fileList
)
}
else
if
(
file
.
isDirectory
)
{
scanEmptyFiles
(
file
.
path
,
fileList
)
}
}
}
}
fun
dpToPx
(
dp
:
Int
,
context
:
Context
):
Int
{
fun
dpToPx
(
dp
:
Int
,
context
:
Context
):
Int
{
return
TypedValue
.
applyDimension
(
TypedValue
.
COMPLEX_UNIT_DIP
,
dp
.
toFloat
(),
...
...
@@ -309,7 +314,7 @@ object FileUtil {
}
@SuppressLint
(
"Recycle"
)
fun
getMediaData
(
context
:
Context
):
ArrayList
<
FileBean
>{
fun
getMediaData
(
context
:
Context
):
ArrayList
<
FileBean
>
{
val
fileBeans
=
ArrayList
<
FileBean
>()
val
projection
=
arrayOf
(
MediaStore
.
Images
.
Media
.
DATA
)
val
cursor
=
context
.
contentResolver
.
query
(
...
...
@@ -320,7 +325,7 @@ object FileUtil {
cursor
?.
let
{
val
indexOrThrow
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
)
while
(
cursor
.
moveToNext
()){
while
(
cursor
.
moveToNext
())
{
val
imagePath
=
cursor
.
getString
(
indexOrThrow
)
val
bitmap
=
BitmapFactory
.
decodeFile
(
imagePath
)
val
file
=
File
(
imagePath
)
...
...
@@ -330,24 +335,24 @@ object FileUtil {
fileBean
.
fileName
=
file
.
name
fileBean
.
filePath
=
imagePath
fileBean
.
fileType
=
getFileType
(
file
)
Log
.
e
(
"yanglin"
,
"getFileList: childList.size = ${imagePath}"
,
)
Log
.
e
(
"yanglin"
,
"getFileList: childList.size = ${imagePath}"
)
fileBeans
.
add
(
fileBean
)
}
}
return
fileBeans
}
fun
getTypeFiles
(
types
:
Array
<
String
>,
fileBeans
:
ArrayList
<
FileBean
>){
fun
getTypeFiles
(
types
:
Array
<
String
>,
fileBeans
:
ArrayList
<
FileBean
>)
{
MediaStore
.
Files
()
val
externalStorageDir
=
Environment
.
getExternalStorageDirectory
()
externalStorageDir
.
listFiles
()
?.
forEach
{
if
(
it
.
isDirectory
){
if
(
it
.
isDirectory
)
{
getTypeFiles
(
types
,
fileBeans
)
}
else
{
}
else
{
val
fileBean
=
FileBean
()
for
(
type
in
types
){
if
(
type
.
contains
(
getFileType
(
it
))){
for
(
type
in
types
)
{
if
(
type
.
contains
(
getFileType
(
it
)))
{
fileBean
.
fileName
=
it
.
name
fileBean
.
filePath
=
it
.
path
...
...
@@ -366,14 +371,14 @@ object FileUtil {
fun
getMediaFiles
(
context
:
Context
,
fileType
:
String
,
limit
:
Int
):
ArrayList
<
FileBean
>
{
val
fileBeans
=
ArrayList
<
FileBean
>()
val
projection
=
arrayOf
(
MediaStore
.
Images
.
Media
.
DATA
)
var
contentUri
:
Uri
if
(
fileType
.
contains
(
"image"
)){
var
contentUri
:
Uri
if
(
fileType
.
contains
(
"image"
))
{
contentUri
=
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
}
else
if
(
fileType
.
contains
(
"video"
))
{
}
else
if
(
fileType
.
contains
(
"video"
))
{
contentUri
=
MediaStore
.
Video
.
Media
.
EXTERNAL_CONTENT_URI
}
else
if
(
fileType
.
contains
(
"audio"
))
{
}
else
if
(
fileType
.
contains
(
"audio"
))
{
contentUri
=
MediaStore
.
Audio
.
Media
.
EXTERNAL_CONTENT_URI
}
else
{
}
else
{
contentUri
=
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
}
val
cursor
=
context
.
contentResolver
.
query
(
...
...
@@ -386,7 +391,7 @@ object FileUtil {
cursor
?.
use
{
var
count
=
0
while
(
it
.
moveToNext
())
{
if
(
count
<
limit
){
if
(
count
<
limit
)
{
val
imagePath
=
it
.
getString
(
it
.
getColumnIndex
(
MediaStore
.
Images
.
Media
.
DATA
))
// images.add(imagePath)
val
fileBean
=
FileBean
()
...
...
@@ -396,10 +401,13 @@ object FileUtil {
fileBean
.
fileSize
=
file
.
length
()
fileBean
.
fileType
=
getFileType
(
file
)
fileBean
.
isDir
=
false
fileBean
.
drawable
=
if
(
fileType
.
contains
(
"image"
))
BitmapDrawable
(
context
.
resources
,
BitmapFactory
.
decodeFile
(
file
.
path
))
else
null
fileBean
.
drawable
=
if
(
fileType
.
contains
(
"image"
))
BitmapDrawable
(
context
.
resources
,
BitmapFactory
.
decodeFile
(
file
.
path
)
)
else
null
fileBeans
.
add
(
fileBean
)
}
count
++
count
++
}
cursor
.
close
()
}
...
...
@@ -407,7 +415,7 @@ object FileUtil {
return
fileBeans
}
fun
getFileType
(
mimeType
:
String
,
context
:
Context
):
ArrayList
<
FileBean
>{
fun
getFileType
(
mimeType
:
String
,
context
:
Context
):
ArrayList
<
FileBean
>
{
val
fileBeans
:
ArrayList
<
FileBean
>
=
ArrayList
()
val
projection
=
arrayOf
(
MediaStore
.
Files
.
FileColumns
.
DATA
,
...
...
MyDemo3/app/src/main/java/com/xm/test/myfilemaster/util/GlideApp.kt
0 → 100644
View file @
ef567503
package
com.xm.test.myfilemaster.util
import
android.app.Application
import
com.bumptech.glide.annotation.GlideModule
@GlideModule
class
GlideApp
:
Application
()
{
}
\ No newline at end of file
MyDemo3/app/src/main/res/layout/activity_media.xml
View file @
ef567503
...
...
@@ -3,43 +3,36 @@
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/main"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
tools:context=
".activity.MediaActivity"
>
<include
android:id=
"@+id/title_bar"
layout=
"@layout/title_bar_layout"
/>
layout=
"@layout/title_bar_layout"
/>
<!-- <ScrollView-->
<!-- android:id="@+id/grid_view_scroll"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:layout_marginTop="12dp"-->
<!-- android:layout_marginStart="16dp"-->
<!-- android:layout_marginEnd="16dp">-->
<!-- <ScrollView-->
<!-- android:id="@+id/grid_view_scroll"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:layout_marginTop="12dp"-->
<!-- android:layout_marginStart="16dp"-->
<!-- android:layout_marginEnd="16dp">-->
<GridView
android:layout_marginTop=
"12dp"
android:layout_marginStart=
"16dp"
android:layout_marginEnd=
"16dp"
<androidx.recyclerview.widget.RecyclerView
android:id=
"@+id/image_item_grid"
android:layout_width=
"fill
_parent"
android:layout_width=
"match
_parent"
android:layout_height=
"wrap_content"
android:fadingEdge=
"none
"
android:horizontalSpacing=
"1
dp"
android:listSelector=
"#00000000
"
android:layout_marginStart=
"16dp
"
android:layout_marginTop=
"12
dp"
android:layout_marginEnd=
"16dp
"
android:padding=
"1dp"
android:scrollbars=
"none"
android:verticalSpacing=
"5dp"
android:numColumns=
"3"
android:columnWidth=
"118dp"
/>
<!-- </ScrollView>-->
app:layoutManager=
"androidx.recyclerview.widget.GridLayoutManager"
app:spanCount=
"3"
/>
<!-- </ScrollView>-->
</LinearLayout>
\ No newline at end of file
MyDemo3/app/src/main/res/layout/item_image_video.xml
0 → 100644
View file @
ef567503
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"wrap_content"
android:layout_margin=
"15dp"
android:layout_height=
"wrap_content"
>
<ImageView
android:id=
"@+id/iv_media"
android:layout_width=
"100dp"
android:layout_height=
"100dp"
tools:ignore=
"ContentDescription"
/>
</FrameLayout>
\ No newline at end of file
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