enhancement: update card and full post mode

This commit is contained in:
Diego Beraldin 2023-10-17 22:49:12 +02:00
parent df7b4632b7
commit 26e37d9ae8
5 changed files with 42 additions and 36 deletions

View File

@ -50,7 +50,8 @@ fun PostCard(
hideAuthor: Boolean = false, hideAuthor: Boolean = false,
postLayout: PostLayout = PostLayout.Card, postLayout: PostLayout = PostLayout.Card,
separateUpAndDownVotes: Boolean = false, separateUpAndDownVotes: Boolean = false,
withOverflowBlurred: Boolean = true, includeFullBody: Boolean = false,
limitBodyHeight: Boolean = false,
blurNsfw: Boolean = true, blurNsfw: Boolean = true,
options: List<String> = emptyList(), options: List<String> = emptyList(),
onOpenCommunity: ((CommunityModel) -> Unit)? = null, onOpenCommunity: ((CommunityModel) -> Unit)? = null,
@ -90,7 +91,8 @@ fun PostCard(
PostLayout.Card -> MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp) PostLayout.Card -> MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
else -> MaterialTheme.colorScheme.background else -> MaterialTheme.colorScheme.background
}, },
withOverflowBlurred = withOverflowBlurred, showBody = includeFullBody || postLayout == PostLayout.Full,
limitBodyHeight = limitBodyHeight,
separateUpAndDownVotes = separateUpAndDownVotes, separateUpAndDownVotes = separateUpAndDownVotes,
autoLoadImages = autoLoadImages, autoLoadImages = autoLoadImages,
blurNsfw = blurNsfw, blurNsfw = blurNsfw,
@ -205,10 +207,11 @@ private fun ExtendedPost(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
post: PostModel, post: PostModel,
autoLoadImages: Boolean = true, autoLoadImages: Boolean = true,
hideAuthor: Boolean, hideAuthor: Boolean = false,
blurNsfw: Boolean, blurNsfw: Boolean = true,
separateUpAndDownVotes: Boolean, separateUpAndDownVotes: Boolean = false,
withOverflowBlurred: Boolean, showBody: Boolean = false,
limitBodyHeight: Boolean = false,
backgroundColor: Color = MaterialTheme.colorScheme.background, backgroundColor: Color = MaterialTheme.colorScheme.background,
options: List<String> = emptyList(), options: List<String> = emptyList(),
onOpenCommunity: ((CommunityModel) -> Unit)? = null, onOpenCommunity: ((CommunityModel) -> Unit)? = null,
@ -248,35 +251,37 @@ private fun ExtendedPost(
onImageClick = onImageClick, onImageClick = onImageClick,
autoLoadImages = autoLoadImages, autoLoadImages = autoLoadImages,
) )
Box { if (showBody) {
val maxHeight = 200.dp Box {
val maxHeightPx = maxHeight.toLocalPixel() val maxHeight = 200.dp
var textHeightPx by remember { mutableStateOf(0f) } val maxHeightPx = maxHeight.toLocalPixel()
PostCardBody( var textHeightPx by remember { mutableStateOf(0f) }
modifier = Modifier.let { PostCardBody(
if (withOverflowBlurred) { modifier = Modifier.let {
it.heightIn(max = maxHeight) if (limitBodyHeight) {
} else { it.heightIn(max = maxHeight)
it } else {
} it
}.padding(horizontal = Spacing.xs).onGloballyPositioned { }
textHeightPx = it.size.toSize().height }.padding(horizontal = Spacing.xs).onGloballyPositioned {
}, textHeightPx = it.size.toSize().height
text = post.text, },
autoLoadImages = autoLoadImages, text = post.text,
) autoLoadImages = autoLoadImages,
if (withOverflowBlurred && textHeightPx >= maxHeightPx) { )
Box( if (limitBodyHeight && textHeightPx >= maxHeightPx) {
modifier = Modifier.height(Spacing.xxl).fillMaxWidth() Box(
.align(Alignment.BottomCenter).background( modifier = Modifier.height(Spacing.xxl).fillMaxWidth()
brush = Brush.verticalGradient( .align(Alignment.BottomCenter).background(
colors = listOf( brush = Brush.verticalGradient(
Color.Transparent, colors = listOf(
backgroundColor, Color.Transparent,
backgroundColor,
),
), ),
), ),
), )
) }
} }
} }
if (post.url != post.imageUrl) { if (post.url != post.imageUrl) {

View File

@ -179,6 +179,7 @@ class CreateCommentScreen(
modifier = referenceModifier, modifier = referenceModifier,
postLayout = uiState.postLayout, postLayout = uiState.postLayout,
post = originalPost, post = originalPost,
limitBodyHeight = true,
blurNsfw = false, blurNsfw = false,
separateUpAndDownVotes = uiState.separateUpAndDownVotes, separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages, autoLoadImages = uiState.autoLoadImages,

View File

@ -330,7 +330,7 @@ class CreatePostScreen(
PostCard( PostCard(
post = post, post = post,
postLayout = uiState.postLayout, postLayout = uiState.postLayout,
withOverflowBlurred = false, includeFullBody = true,
separateUpAndDownVotes = uiState.separateUpAndDownVotes, separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages, autoLoadImages = uiState.autoLoadImages,
) )

View File

@ -269,7 +269,7 @@ class PostDetailScreen(
PostCard( PostCard(
post = statePost, post = statePost,
postLayout = uiState.postLayout, postLayout = uiState.postLayout,
withOverflowBlurred = false, includeFullBody = true,
separateUpAndDownVotes = uiState.separateUpAndDownVotes, separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages, autoLoadImages = uiState.autoLoadImages,
blurNsfw = false, blurNsfw = false,

View File

@ -117,7 +117,7 @@
<string name="settings_custom_seed_color">Colore tema personalizzato</string> <string name="settings_custom_seed_color">Colore tema personalizzato</string>
<string name="settings_post_layout">Layout post</string> <string name="settings_post_layout">Layout post</string>
<string name="settings_post_layout_compact">Compatto</string> <string name="settings_post_layout_compact">Compatto</string>
<string name="settings_post_layout_card">Carta</string> <string name="settings_post_layout_card">Scheda</string>
<string name="settings_post_layout_full">Intero</string> <string name="settings_post_layout_full">Intero</string>
<string name="settings_color_blue">Blu aziendale</string> <string name="settings_color_blue">Blu aziendale</string>
<string name="settings_color_aquamarine">Acquamarina</string> <string name="settings_color_aquamarine">Acquamarina</string>