feat: 收藏中已被删除贴子提示

This commit is contained in:
HuanCheng65 2023-07-24 12:05:49 +08:00
parent c7c646d7de
commit 2edb341451
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
3 changed files with 110 additions and 102 deletions

View File

@ -32,7 +32,6 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.ExperimentalTextApi import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.Placeholder import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.PlaceholderVerticalAlign import androidx.compose.ui.text.PlaceholderVerticalAlign
import androidx.compose.ui.text.TextMeasurer
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
@ -138,8 +137,6 @@ fun ThreadStorePage(
) )
} }
) { contentPaddings -> ) { contentPaddings ->
val textMeasurer = rememberTextMeasurer()
StateScreen( StateScreen(
isEmpty = data.isEmpty(), isEmpty = data.isEmpty(),
isError = isError, isError = isError,
@ -171,16 +168,15 @@ fun ThreadStorePage(
items = data, items = data,
key = { it.threadId } key = { it.threadId }
) { info -> ) { info ->
LongClickMenu( StoreItem(
menuContent = { info = info,
DropdownMenuItem(onClick = { onUserClick = {
viewModel.send( info.author.lzUid?.let {
ThreadStoreUiIntent.Delete( UserActivity.launch(
info.threadId context,
it,
StringUtil.getAvatarUrl(info.author.userPortrait)
) )
)
}) {
Text(text = stringResource(id = R.string.title_collect_on))
} }
}, },
onClick = { onClick = {
@ -196,22 +192,15 @@ fun ThreadStorePage(
) )
) )
) )
}
) {
StoreItem(
info = info,
onUserClick = {
info.author.lzUid?.let {
UserActivity.launch(
context,
it,
StringUtil.getAvatarUrl(info.author.userPortrait)
)
}
}, },
textMeasurer = textMeasurer onDelete = {
viewModel.send(
ThreadStoreUiIntent.Delete(
info.threadId
)
) )
} }
)
} }
} }
} }
@ -233,12 +222,21 @@ fun ThreadStorePage(
private fun StoreItem( private fun StoreItem(
info: ThreadStoreBean.ThreadStoreInfo, info: ThreadStoreBean.ThreadStoreInfo,
onUserClick: () -> Unit, onUserClick: () -> Unit,
onDelete: () -> Unit,
onClick: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
textMeasurer: TextMeasurer = rememberTextMeasurer()
) { ) {
val hasUpdate = info.count != "0" && info.postNo != "0" val hasUpdate = remember(info) { info.count != "0" && info.postNo != "0" }
var width = 0 val isDeleted = remember(info) { info.isDeleted == "1" }
var height = 0 val textMeasurer = rememberTextMeasurer()
LongClickMenu(
menuContent = {
DropdownMenuItem(onClick = onDelete) {
Text(text = stringResource(id = R.string.title_collect_on))
}
},
onClick = onClick
) {
Column( Column(
modifier = modifier modifier = modifier
.padding(16.dp), .padding(16.dp),
@ -277,19 +275,18 @@ private fun StoreItem(
id = R.string.tip_thread_store_update, id = R.string.tip_thread_store_update,
info.postNo info.postNo
) )
if (hasUpdate) { val result = remember {
val result = textMeasurer.measure( textMeasurer.measure(
AnnotatedString(updateTip), AnnotatedString(updateTip),
style = UpdateTipTextStyle style = UpdateTipTextStyle
) ).size
width =
result.size.width.pxToSp() + 12F.dpToPxFloat().pxToSp() * 2 + 1
height = result.size.height.pxToSp() + 4F.dpToPxFloat().pxToSp() * 2
} }
val width = result.width.pxToSp() + 12F.dpToPxFloat().pxToSp() * 2 + 1
val height = result.height.pxToSp() + 4F.dpToPxFloat().pxToSp() * 2
Text( Text(
text = title, text = title,
fontSize = 15.sp, fontSize = 15.sp,
color = ExtendedTheme.colors.text, color = if (isDeleted) ExtendedTheme.colors.textDisabled else ExtendedTheme.colors.text,
inlineContent = mapOf( inlineContent = mapOf(
"Update" to InlineTextContent( "Update" to InlineTextContent(
placeholder = Placeholder( placeholder = Placeholder(
@ -318,5 +315,13 @@ private fun StoreItem(
) )
) )
) )
if (isDeleted) {
Text(
text = stringResource(id = R.string.tip_thread_store_deleted),
fontSize = 12.sp,
color = ExtendedTheme.colors.textDisabled
)
}
}
} }
} }

View File

@ -110,12 +110,13 @@ fun ClickMenu(
fun LongClickMenu( fun LongClickMenu(
menuContent: @Composable (ColumnScope.() -> Unit), menuContent: @Composable (ColumnScope.() -> Unit),
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
enabled: Boolean = true,
menuState: MenuState = rememberMenuState(), menuState: MenuState = rememberMenuState(),
onClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null,
shape: Shape = RoundedCornerShape(14.dp), shape: Shape = RoundedCornerShape(14.dp),
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
indication: Indication? = LocalIndication.current, indication: Indication? = LocalIndication.current,
content: @Composable () -> Unit content: @Composable () -> Unit,
) { ) {
LaunchedEffect(key1 = null) { LaunchedEffect(key1 = null) {
launch { launch {
@ -138,6 +139,7 @@ fun LongClickMenu(
.combinedClickable( .combinedClickable(
interactionSource = interactionSource, interactionSource = interactionSource,
indication = indication, indication = indication,
enabled = enabled,
onLongClick = { onLongClick = {
menuState.expanded = true menuState.expanded = true
} }

View File

@ -708,4 +708,5 @@
<string name="btn_open_origin_thread">查看原贴</string> <string name="btn_open_origin_thread">查看原贴</string>
<string name="tip_blocked_thread">由于你的屏蔽设置,该贴已被屏蔽</string> <string name="tip_blocked_thread">由于你的屏蔽设置,该贴已被屏蔽</string>
<string name="desc_picture">图片</string> <string name="desc_picture">图片</string>
<string name="tip_thread_store_deleted">该贴已被删除</string>
</resources> </resources>