feat: 缩略图长按菜单
This commit is contained in:
parent
6a261393d6
commit
40915c0325
|
|
@ -30,7 +30,8 @@ fun getPhotoViewData(
|
|||
objType = "pb",
|
||||
picId = picId,
|
||||
picIndex = 1,
|
||||
seeLz = seeLz
|
||||
seeLz = seeLz,
|
||||
originUrl = originUrl,
|
||||
),
|
||||
picItems = listOf(
|
||||
PicItem(
|
||||
|
|
@ -84,7 +85,8 @@ fun getPhotoViewData(
|
|||
seeLz = false,
|
||||
objType = "index",
|
||||
picId = ImageUtil.getPicId(media.originPic),
|
||||
picIndex = index + 1
|
||||
picIndex = index + 1,
|
||||
originUrl = media.originPic
|
||||
),
|
||||
picItems = medias.mapIndexed { mediaIndex, mediaItem ->
|
||||
PicItem(
|
||||
|
|
|
|||
|
|
@ -2,8 +2,13 @@ package com.huanchengfly.tieba.post.ui.widgets.compose
|
|||
|
||||
import android.content.Context
|
||||
import android.os.Parcelable
|
||||
import androidx.compose.foundation.clickable
|
||||
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.getValue
|
||||
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.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.github.panpf.sketch.compose.AsyncImage
|
||||
import com.github.panpf.sketch.request.Depth
|
||||
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.goToActivity
|
||||
import com.huanchengfly.tieba.post.models.protos.PhotoViewData
|
||||
|
|
@ -50,20 +57,8 @@ fun NetworkImage(
|
|||
) {
|
||||
val context = LocalContext.current
|
||||
var shouldLoad by remember { mutableStateOf(shouldLoadImage(context, skipNetworkCheck)) }
|
||||
val clickableModifier = if (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 enableClick = remember(photoViewData, shouldLoad) { photoViewData != null || !shouldLoad }
|
||||
|
||||
val request = remember(imageUri, shouldLoad) {
|
||||
DisplayRequest(context, imageUri) {
|
||||
placeholder(ImageUtil.getPlaceHolder(context, 0))
|
||||
|
|
@ -89,13 +84,42 @@ fun NetworkImage(
|
|||
)
|
||||
} 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(
|
||||
request = request,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier.then(clickableModifier),
|
||||
contentScale = contentScale,
|
||||
colorFilter = colorFilter,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.huanchengfly.tieba.post.ui.widgets.compose
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.Indication
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
|
|
@ -119,7 +118,7 @@ fun LongClickMenu(
|
|||
indication: Indication? = LocalIndication.current,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
LaunchedEffect(key1 = null) {
|
||||
LaunchedEffect(Unit) {
|
||||
launch {
|
||||
interactionSource.interactions
|
||||
.filterIsInstance<PressInteraction.Press>()
|
||||
|
|
@ -127,16 +126,9 @@ fun LongClickMenu(
|
|||
menuState.offset = it.pressPosition
|
||||
}
|
||||
}
|
||||
launch {
|
||||
interactionSource.interactions
|
||||
.collect {
|
||||
Log.i("Indication", "$it")
|
||||
}
|
||||
}
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clip(shape)
|
||||
modifier = modifier
|
||||
.combinedClickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = indication,
|
||||
|
|
@ -161,7 +153,9 @@ fun LongClickMenu(
|
|||
DropdownMenu(
|
||||
expanded = menuState.expanded,
|
||||
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) {
|
||||
menuContent()
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ message LoadPicPageData {
|
|||
uint32 picIndex = 6;
|
||||
int64 postId = 7;
|
||||
int64 threadId = 8;
|
||||
optional string originUrl = 9;
|
||||
}
|
||||
|
||||
message PicItem {
|
||||
|
|
|
|||
Loading…
Reference in New Issue