提问人:leomuko 提问时间:11/17/2023 更新时间:11/17/2023 访问量:20
是否有活动选择器可以在图像上显示数字,以显示android jetpack compose的选择顺序
Is there an activity picker that displays the numbers on the images to show the order of selection with android jetpack compose
问:
我目前正在 Android 中实现一项功能,用户可以在帖子创建过程中选择多个媒体。然后,该媒体被压缩并按用户选择的顺序显示,
我能够在 Android 12 中实现这一点,但在使用 android 13 进行测试时,媒体首先按图像顺序排列和返回,视频丢失。
有没有人对此有解决方法,或者是否有选择器库可以按选择顺序排列媒体,甚至在顶部显示带有数字图标的媒体?
我目前正在使用 google 提供的官方 Photo Picker 库
https://developer.android.com/training/data-storage/shared/photopicker
下面是一个关于我如何处理返回的图像以及压缩的示例。
val multiplePhotoPickerLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickMultipleVisualMedia(5),
onResult = { data ->
if (data.isNotEmpty()) {
compressedVideos.clear()
selectedImage.apply {
addAll(data)
}
coroutineScope.launch {
for (i in data.indices) {
val isImage = getMediaType(
context, data[i]
) != MediaType.MediaTypeVideo
compressedVideos.add(
VideoItem(
data[i],
null,
false,
isImage,
"",
selectedMedias.size + i,
data[i].length(context)
)
)
Timber.tag("NoticeBoard").d("Item is Image ${isImage} is in postion ${i}")
}
val largeVideos = compressedVideos.filter { it.size > MAX_UPLOAD_SIZE }.map {
VideoItem(
it.currentPath,
it.currentPath,
it.isCompressed,
it.isImage,
it.itemId,
it.index,
it.size
)
}
compressedVideos.removeIf { it.size > MAX_UPLOAD_SIZE }
val compressor = MediaCompressor(context)
context.getActivity()?.let {
isCompressing.value = true
// function to compress videos
compressor.compressMultipleFiles(
it,
compressedVideos.filter { !it.isImage }.toMutableList(),
callback = { videosItems ->
//Compress Images
val images = compressImages(
compressedVideos.filter { it.isImage }.toMutableList(),
context
)
selectedMedias.addAll(images)
selectedMedias.addAll(videosItems)
selectedMedias.addAll(largeVideos)
selectedMedias.sortBy { it?.index }
isCompressing.value = false
}
)
}
}
}
}
)
答: 暂无答案
评论
MediaStore