Skip to content

Commit

Permalink
[fix]onClick on MediaPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-Mr committed Oct 3, 2024
1 parent c0d228b commit eac75e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
33 changes: 9 additions & 24 deletions app/src/main/java/top/maary/oblivionis/ui/ActionComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package top.maary.oblivionis.ui

import android.net.Uri
import android.provider.MediaStore
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction
Expand Down Expand Up @@ -61,40 +63,24 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest
import top.maary.oblivionis.R

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun MediaPlayer(
modifier: Modifier,
uri: Uri,
imageLoader: ImageLoader,
isMultiSelectionState: Boolean = false,
isSelected: Boolean = false, // 用于表示当前项是否被选中
onImageClick: () -> Unit = {},
onVideoClick: () -> Unit = {},
onMediaClick: () -> Unit = {},
onLongPress: () -> Unit = {} // 长按事件
) {
Box(
modifier = Modifier
.wrapContentSize()
.pointerInput(Unit) {
detectTapGestures(
onLongPress = {
onLongPress() // 处理长按事件
},
onTap = {
if (uri
.toString()
.startsWith(MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString())
) {
onImageClick()
} else if (uri
.toString()
.startsWith(MediaStore.Video.Media.EXTERNAL_CONTENT_URI.toString())
) {
onVideoClick()
}
}
)
}
.combinedClickable (
onLongClick = { onLongPress() },
onClick = { onMediaClick() }
)
) {
when {
// 处理图片显示
Expand Down Expand Up @@ -326,14 +312,13 @@ fun VideoViewAlt(
) {
Box(
modifier = modifier
.clickable { onClick() }, contentAlignment = Alignment.BottomEnd
, contentAlignment = Alignment.BottomEnd
) {
AsyncImage(
model = uri,
contentDescription = "",
imageLoader = imageLoader,
modifier = modifier
.clickable { onClick() }
.fillMaxWidth()
.clip(RoundedCornerShape(8.dp))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package top.maary.oblivionis.ui.screen

import android.content.Intent
import android.provider.MediaStore
import android.util.Log
import androidx.compose.animation.core.animate
import androidx.compose.animation.core.tween
import androidx.compose.foundation.gestures.Orientation
Expand Down Expand Up @@ -321,13 +322,15 @@ fun ActionScreen(
MediaPlayer(modifier = Modifier.fillMaxWidth(),
uri = uri,
imageLoader = imageLoader,
onVideoClick = {
onMediaClick = {
Log.v("OBLIVIONIS", "IMAGE CLICK")
context.startActivity(
Intent.createChooser(
intent, context.getString(R.string.choose_app)
)
)
})
}
)
if (images.value[page].isExcluded) {
IconButton(
onClick = {}, colors = IconButtonColors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,7 @@ fun RecycleScreen(
isMultiSelectionState = selectedItems.value.isNotEmpty(),
isSelected = selectedItems.value.contains(index),
imageLoader = imageLoader,
onImageClick = {
if (selectedItems.value.isNotEmpty()) {
val newSet = selectedItems.value.toMutableSet() // 创建一个新集合
if (!newSet.add(index)) {
newSet.remove(index) // 如果元素已存在,则移除
}
selectedItems.value = newSet // 更新 `selectedItems.value`,触发重组
return@MediaPlayer
}
clickedIndex.intValue = index
openDialog.value = true
},
onVideoClick = {
onMediaClick = {
if (selectedItems.value.isNotEmpty()) {
val newSet = selectedItems.value.toMutableSet() // 创建一个新集合
if (!newSet.add(index)) {
Expand Down

0 comments on commit eac75e0

Please sign in to comment.