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

View File

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

View File

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

View File

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

View File

@ -117,7 +117,7 @@
<string name="settings_custom_seed_color">Colore tema personalizzato</string>
<string name="settings_post_layout">Layout post</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_color_blue">Blu aziendale</string>
<string name="settings_color_aquamarine">Acquamarina</string>