feat: 缩略图长按菜单

This commit is contained in:
HuanCheng65 2023-09-30 18:56:55 +08:00
parent 6a261393d6
commit 40915c0325
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
4 changed files with 56 additions and 35 deletions

View File

@ -30,7 +30,8 @@ fun getPhotoViewData(
objType = "pb", objType = "pb",
picId = picId, picId = picId,
picIndex = 1, picIndex = 1,
seeLz = seeLz seeLz = seeLz,
originUrl = originUrl,
), ),
picItems = listOf( picItems = listOf(
PicItem( PicItem(
@ -84,7 +85,8 @@ fun getPhotoViewData(
seeLz = false, seeLz = false,
objType = "index", objType = "index",
picId = ImageUtil.getPicId(media.originPic), picId = ImageUtil.getPicId(media.originPic),
picIndex = index + 1 picIndex = index + 1,
originUrl = media.originPic
), ),
picItems = medias.mapIndexed { mediaIndex, mediaItem -> picItems = medias.mapIndexed { mediaIndex, mediaItem ->
PicItem( PicItem(

View File

@ -2,8 +2,13 @@ package com.huanchengfly.tieba.post.ui.widgets.compose
import android.content.Context import android.content.Context
import android.os.Parcelable import android.os.Parcelable
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -15,9 +20,11 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ColorMatrix import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.github.panpf.sketch.compose.AsyncImage import com.github.panpf.sketch.compose.AsyncImage
import com.github.panpf.sketch.request.Depth import com.github.panpf.sketch.request.Depth
import com.github.panpf.sketch.request.DisplayRequest import com.github.panpf.sketch.request.DisplayRequest
import com.huanchengfly.tieba.post.R
import com.huanchengfly.tieba.post.arch.ImmutableHolder import com.huanchengfly.tieba.post.arch.ImmutableHolder
import com.huanchengfly.tieba.post.goToActivity import com.huanchengfly.tieba.post.goToActivity
import com.huanchengfly.tieba.post.models.protos.PhotoViewData import com.huanchengfly.tieba.post.models.protos.PhotoViewData
@ -50,20 +57,8 @@ fun NetworkImage(
) { ) {
val context = LocalContext.current val context = LocalContext.current
var shouldLoad by remember { mutableStateOf(shouldLoadImage(context, skipNetworkCheck)) } var shouldLoad by remember { mutableStateOf(shouldLoadImage(context, skipNetworkCheck)) }
val clickableModifier = if (photoViewData != null || !shouldLoad) { val enableClick = remember(photoViewData, shouldLoad) { photoViewData != null || !shouldLoad }
Modifier.clickable(
indication = null,
interactionSource = remember { MutableInteractionSource() }
) {
if (!shouldLoad) {
shouldLoad = true
} else if (photoViewData != null) {
context.goToActivity<PhotoViewActivity> {
putExtra(EXTRA_PHOTO_VIEW_DATA, photoViewData.get() as Parcelable)
}
}
}
} else Modifier
val request = remember(imageUri, shouldLoad) { val request = remember(imageUri, shouldLoad) {
DisplayRequest(context, imageUri) { DisplayRequest(context, imageUri) {
placeholder(ImageUtil.getPlaceHolder(context, 0)) placeholder(ImageUtil.getPlaceHolder(context, 0))
@ -89,13 +84,42 @@ fun NetworkImage(
) )
} else null } else null
LongClickMenu(
enabled = enableClick,
indication = null,
interactionSource = remember { MutableInteractionSource() },
onClick = {
if (!shouldLoad) {
shouldLoad = true
} else if (photoViewData != null) {
context.goToActivity<PhotoViewActivity> {
putExtra(EXTRA_PHOTO_VIEW_DATA, photoViewData.get() as Parcelable)
}
}
},
menuContent = {
DropdownMenuItem(
onClick = {
ImageUtil.download(
context,
photoViewData?.get { this.data_?.originUrl } ?: imageUri)
}
) {
Text(text = stringResource(id = R.string.title_save_image))
}
},
modifier = modifier
.width(IntrinsicSize.Min)
.height(IntrinsicSize.Min),
) {
AsyncImage( AsyncImage(
request = request, request = request,
modifier = Modifier.fillMaxSize(),
contentDescription = contentDescription, contentDescription = contentDescription,
modifier = modifier.then(clickableModifier),
contentScale = contentScale, contentScale = contentScale,
colorFilter = colorFilter, colorFilter = colorFilter,
) )
}
} }
@Composable @Composable

View File

@ -1,6 +1,5 @@
package com.huanchengfly.tieba.post.ui.widgets.compose package com.huanchengfly.tieba.post.ui.widgets.compose
import android.util.Log
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Indication import androidx.compose.foundation.Indication
import androidx.compose.foundation.LocalIndication import androidx.compose.foundation.LocalIndication
@ -119,7 +118,7 @@ fun LongClickMenu(
indication: Indication? = LocalIndication.current, indication: Indication? = LocalIndication.current,
content: @Composable () -> Unit, content: @Composable () -> Unit,
) { ) {
LaunchedEffect(key1 = null) { LaunchedEffect(Unit) {
launch { launch {
interactionSource.interactions interactionSource.interactions
.filterIsInstance<PressInteraction.Press>() .filterIsInstance<PressInteraction.Press>()
@ -127,16 +126,9 @@ fun LongClickMenu(
menuState.offset = it.pressPosition menuState.offset = it.pressPosition
} }
} }
launch {
interactionSource.interactions
.collect {
Log.i("Indication", "$it")
}
}
} }
Box( Box(
modifier = Modifier modifier = modifier
.clip(shape)
.combinedClickable( .combinedClickable(
interactionSource = interactionSource, interactionSource = interactionSource,
indication = indication, indication = indication,
@ -161,7 +153,9 @@ fun LongClickMenu(
DropdownMenu( DropdownMenu(
expanded = menuState.expanded, expanded = menuState.expanded,
onDismissRequest = { menuState.expanded = false }, onDismissRequest = { menuState.expanded = false },
modifier = modifier.background(color = ExtendedTheme.colors.menuBackground) modifier = Modifier
.clip(shape)
.background(color = ExtendedTheme.colors.menuBackground)
) { ) {
ProvideContentColor(color = ExtendedTheme.colors.text) { ProvideContentColor(color = ExtendedTheme.colors.text) {
menuContent() menuContent()

View File

@ -17,6 +17,7 @@ message LoadPicPageData {
uint32 picIndex = 6; uint32 picIndex = 6;
int64 postId = 7; int64 postId = 7;
int64 threadId = 8; int64 threadId = 8;
optional string originUrl = 9;
} }
message PicItem { message PicItem {