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
0a81c9ad
Commit
0a81c9ad
authored
Aug 08, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
f87e78be
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
10 deletions
+82
-10
MediaBrowserActivity.kt
...serwhite/ui/activity/mediabrowser/MediaBrowserActivity.kt
+10
-4
MediaAdapter.kt
...ain/java/com/base/browserwhite/ui/adapter/MediaAdapter.kt
+6
-3
FileFragment.kt
...in/java/com/base/browserwhite/ui/fragment/FileFragment.kt
+5
-0
MediaStoreUtils.kt
.../main/java/com/base/browserwhite/utils/MediaStoreUtils.kt
+37
-3
fragment_file.xml
app/src/main/res/layout/fragment_file.xml
+1
-0
item_media_picture_video.xml
app/src/main/res/layout/item_media_picture_video.xml
+23
-0
No files found.
app/src/main/java/com/base/browserwhite/ui/activity/mediabrowser/MediaBrowserActivity.kt
View file @
0a81c9ad
...
@@ -11,6 +11,7 @@ import com.base.browserwhite.ui.activity.BaseActivity
...
@@ -11,6 +11,7 @@ import com.base.browserwhite.ui.activity.BaseActivity
import
com.base.browserwhite.ui.adapter.MediaAdapter
import
com.base.browserwhite.ui.adapter.MediaAdapter
import
com.base.browserwhite.utils.BarUtils
import
com.base.browserwhite.utils.BarUtils
import
com.base.browserwhite.utils.MediaStoreUtils.getMediaPhoto
import
com.base.browserwhite.utils.MediaStoreUtils.getMediaPhoto
import
com.base.browserwhite.utils.MediaStoreUtils.getMediaVideo
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
...
@@ -21,19 +22,19 @@ class MediaBrowserActivity : BaseActivity<ActivityMediaBrowserBinding>() {
...
@@ -21,19 +22,19 @@ class MediaBrowserActivity : BaseActivity<ActivityMediaBrowserBinding>() {
ActivityMediaBrowserBinding
.
inflate
(
layoutInflater
)
ActivityMediaBrowserBinding
.
inflate
(
layoutInflater
)
}
}
private
lateinit
var
adapter
:
MediaAdapter
private
lateinit
var
adapter
:
MediaAdapter
private
var
tittle
:
String
=
""
override
fun
initView
()
{
override
fun
initView
()
{
BarUtils
.
setStatusBarLightMode
(
this
,
true
)
BarUtils
.
setStatusBarLightMode
(
this
,
true
)
BarUtils
.
setStatusBarColor
(
this
,
Color
.
TRANSPARENT
)
BarUtils
.
setStatusBarColor
(
this
,
Color
.
TRANSPARENT
)
binding
.
root
.
updatePadding
(
top
=
BarUtils
.
getStatusBarHeight
())
binding
.
root
.
updatePadding
(
top
=
BarUtils
.
getStatusBarHeight
())
val
tittle
=
intent
.
extras
?.
getString
(
"tittle"
)
?:
""
tittle
=
intent
.
extras
?.
getString
(
"tittle"
)
?:
""
binding
.
tvTitle
.
text
=
tittle
binding
.
tvTitle
.
text
=
tittle
when
(
tittle
)
{
when
(
tittle
)
{
"Picture"
->
{
"Picture"
,
"Video"
->
{
adapter
=
MediaAdapter
(
1
)
adapter
=
MediaAdapter
(
1
)
binding
.
rv
.
layoutManager
=
GridLayoutManager
(
this
,
4
).
apply
{
binding
.
rv
.
layoutManager
=
GridLayoutManager
(
this
,
4
).
apply
{
spanSizeLookup
=
object
:
SpanSizeLookup
()
{
spanSizeLookup
=
object
:
SpanSizeLookup
()
{
...
@@ -62,7 +63,12 @@ class MediaBrowserActivity : BaseActivity<ActivityMediaBrowserBinding>() {
...
@@ -62,7 +63,12 @@ class MediaBrowserActivity : BaseActivity<ActivityMediaBrowserBinding>() {
}
}
private
fun
initData
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
private
fun
initData
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
val
mediaList
=
getMediaPhoto
()
val
mediaList
=
when
(
tittle
)
{
"Picture"
->
getMediaPhoto
()
"Video"
->
getMediaVideo
()
else
->
arrayListOf
()
}
launch
(
Dispatchers
.
Main
)
{
launch
(
Dispatchers
.
Main
)
{
adapter
.
setData
(
mediaList
)
adapter
.
setData
(
mediaList
)
}
}
...
...
app/src/main/java/com/base/browserwhite/ui/adapter/MediaAdapter.kt
View file @
0a81c9ad
...
@@ -15,7 +15,7 @@ import com.base.browserwhite.bean.ConstObject.MIME_TYPE_PPTX
...
@@ -15,7 +15,7 @@ import com.base.browserwhite.bean.ConstObject.MIME_TYPE_PPTX
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.MediaBean
import
com.base.browserwhite.bean.MediaBean
import
com.base.browserwhite.databinding.ItemMediaPictureBinding
import
com.base.browserwhite.databinding.ItemMediaPicture
Video
Binding
import
com.base.browserwhite.databinding.ItemMediaRecentBinding
import
com.base.browserwhite.databinding.ItemMediaRecentBinding
import
com.base.browserwhite.utils.KotlinExt.toFormatSize
import
com.base.browserwhite.utils.KotlinExt.toFormatSize
import
com.base.browserwhite.utils.XmlEx.inflate
import
com.base.browserwhite.utils.XmlEx.inflate
...
@@ -38,7 +38,7 @@ class MediaAdapter(
...
@@ -38,7 +38,7 @@ class MediaAdapter(
return
MediaViewHolder
(
R
.
layout
.
item_media_recent
.
inflate
(
parent
))
return
MediaViewHolder
(
R
.
layout
.
item_media_recent
.
inflate
(
parent
))
}
}
if
(
uiType
==
1
)
{
if
(
uiType
==
1
)
{
return
MediaViewHolder
(
R
.
layout
.
item_media_picture
.
inflate
(
parent
))
return
MediaViewHolder
(
R
.
layout
.
item_media_picture
_video
.
inflate
(
parent
))
}
}
return
MediaViewHolder
(
R
.
layout
.
item_media_recent
.
inflate
(
parent
))
return
MediaViewHolder
(
R
.
layout
.
item_media_recent
.
inflate
(
parent
))
}
}
...
@@ -102,11 +102,14 @@ class MediaAdapter(
...
@@ -102,11 +102,14 @@ class MediaAdapter(
clickAction
?.
invoke
(
bean
)
clickAction
?.
invoke
(
bean
)
}
}
}
else
if
(
uiType
==
1
)
{
}
else
if
(
uiType
==
1
)
{
val
binding
=
ItemMediaPictureBinding
.
bind
(
holder
.
itemView
)
val
binding
=
ItemMediaPicture
Video
Binding
.
bind
(
holder
.
itemView
)
Glide
.
with
(
context
).
load
(
bean
.
path
).
centerCrop
().
into
(
binding
.
iv
)
Glide
.
with
(
context
).
load
(
bean
.
path
).
centerCrop
().
into
(
binding
.
iv
)
binding
.
root
.
setOnClickListener
{
binding
.
root
.
setOnClickListener
{
clickAction
?.
invoke
(
bean
)
clickAction
?.
invoke
(
bean
)
}
}
if
(
bean
.
mimeType
.
contains
(
"video"
))
{
binding
.
ivShipin
.
visibility
=
View
.
VISIBLE
}
}
}
}
}
...
...
app/src/main/java/com/base/browserwhite/ui/fragment/FileFragment.kt
View file @
0a81c9ad
...
@@ -93,6 +93,11 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
...
@@ -93,6 +93,11 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
putExtra
(
"tittle"
,
"Picture"
)
putExtra
(
"tittle"
,
"Picture"
)
})
})
}
}
binding
.
llVideo
.
setOnClickListener
{
requireActivity
().
startActivity
(
Intent
(
requireContext
(),
MediaBrowserActivity
::
class
.
java
).
apply
{
putExtra
(
"tittle"
,
"Video"
)
})
}
}
}
...
...
app/src/main/java/com/base/browserwhite/utils/MediaStoreUtils.kt
View file @
0a81c9ad
...
@@ -130,7 +130,7 @@ object MediaStoreUtils {
...
@@ -130,7 +130,7 @@ object MediaStoreUtils {
// 定义查询的Uri和列
// 定义查询的Uri和列
val
baseUri
=
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
val
baseUri
=
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
val
projection
=
arrayOf
(
MediaStore
.
Images
.
Media
.
_ID
,
MediaStore
.
Files
.
FileColumns
.
DATA
)
val
projection
=
arrayOf
(
MediaStore
.
Images
.
Media
.
_ID
,
MediaStore
.
Images
.
Media
.
DATA
)
// 执行查询
// 执行查询
var
cursor
:
Cursor
?
=
null
var
cursor
:
Cursor
?
=
null
...
@@ -140,9 +140,9 @@ object MediaStoreUtils {
...
@@ -140,9 +140,9 @@ object MediaStoreUtils {
if
(
cursor
!=
null
)
{
if
(
cursor
!=
null
)
{
while
(
cursor
.
moveToNext
())
{
while
(
cursor
.
moveToNext
())
{
val
id
=
cursor
.
getInt
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Files
.
FileColumns
.
_ID
))
val
id
=
cursor
.
getInt
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
_ID
))
val
uri
=
Uri
.
withAppendedPath
(
baseUri
,
id
.
toString
())
val
uri
=
Uri
.
withAppendedPath
(
baseUri
,
id
.
toString
())
val
path
=
cursor
.
getString
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Files
.
FileColumns
.
DATA
))
val
path
=
cursor
.
getString
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
))
list
.
add
(
MediaBean
(
path
=
path
,
uri
=
uri
))
list
.
add
(
MediaBean
(
path
=
path
,
uri
=
uri
))
}
}
}
}
...
@@ -155,6 +155,40 @@ object MediaStoreUtils {
...
@@ -155,6 +155,40 @@ object MediaStoreUtils {
return
list
return
list
}
}
fun
Context
.
getMediaVideo
():
List
<
MediaBean
>
{
val
list
=
arrayListOf
<
MediaBean
>()
val
contentResolver
=
this
.
contentResolver
// 定义查询的Uri和列
val
baseUri
=
MediaStore
.
Video
.
Media
.
EXTERNAL_CONTENT_URI
val
projection
=
arrayOf
(
MediaStore
.
Video
.
Media
.
_ID
,
MediaStore
.
Video
.
Media
.
DATA
,
MediaStore
.
Video
.
Media
.
MIME_TYPE
)
// 执行查询
var
cursor
:
Cursor
?
=
null
try
{
cursor
=
contentResolver
.
query
(
baseUri
,
projection
,
null
,
null
,
null
)
if
(
cursor
!=
null
)
{
while
(
cursor
.
moveToNext
())
{
val
id
=
cursor
.
getInt
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Video
.
Media
.
_ID
))
val
uri
=
Uri
.
withAppendedPath
(
baseUri
,
id
.
toString
())
val
path
=
cursor
.
getString
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Video
.
Media
.
DATA
))
val
mimeType
=
cursor
.
getString
(
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Video
.
Media
.
MIME_TYPE
))
list
.
add
(
MediaBean
(
path
=
path
,
uri
=
uri
,
mimeType
=
mimeType
))
}
}
}
catch
(
e
:
Exception
)
{
}
finally
{
cursor
?.
close
()
}
return
list
}
fun
Context
.
getMediaVideoSize
():
Int
{
fun
Context
.
getMediaVideoSize
():
Int
{
var
count
=
0
var
count
=
0
runCatching
{
runCatching
{
...
...
app/src/main/res/layout/fragment_file.xml
View file @
0a81c9ad
...
@@ -313,6 +313,7 @@
...
@@ -313,6 +313,7 @@
</LinearLayout>
</LinearLayout>
<LinearLayout
<LinearLayout
android:id=
"@+id/ll_video"
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:layout_weight=
"1"
android:layout_weight=
"1"
...
...
app/src/main/res/layout/item_media_picture.xml
→
app/src/main/res/layout/item_media_picture
_video
.xml
View file @
0a81c9ad
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<
ImageView
xmlns:android=
"http://schemas.android.com/apk/res/android"
<
FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/iv"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"95dp"
android:layout_height=
"95dp"
android:layout_margin=
"3dp"
android:layout_margin=
"3dp"
tools:ignore=
"ContentDescription"
/>
tools:ignore=
"ContentDescription"
>
\ No newline at end of file
<ImageView
android:id=
"@+id/iv"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_gravity=
"center"
/>
<ImageView
android:id=
"@+id/iv_shipin"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:src=
"@mipmap/h_shipin"
android:visibility=
"gone"
/>
</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