Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: implement special tags (me, op, mod) #223

Merged
merged 14 commits into from
Jan 6, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ fun CollapsedCommentCard(
actionButtonsActive: Boolean = true,
isOp: Boolean = false,
isMod: Boolean = false,
isCurrentUser: Boolean = false,
showBot: Boolean = false,
adminTagColor: Int? = null,
botTagColor: Int? = null,
meTagColor: Int? = null,
opTagColor: Int? = null,
modTagColor: Int? = null,
options: List<Option> = emptyList(),
onClick: (() -> Unit)? = null,
onOpenCreator: ((UserModel) -> Unit)? = null,
Expand Down Expand Up @@ -212,7 +218,13 @@ fun CollapsedCommentCard(
distinguished = comment.distinguished,
isOp = isOp,
isMod = isMod,
isCurrentUser = isCurrentUser,
isBot = comment.creator?.bot?.takeIf { showBot } ?: false,
adminTagColor = adminTagColor,
botTagColor = botTagColor,
meTagColor = meTagColor,
opTagColor = opTagColor,
modTagColor = modTagColor,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
onToggleExpanded = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ fun CommentCard(
isOp: Boolean = false,
isMod: Boolean = false,
isAdmin: Boolean = false,
isCurrentUser: Boolean = false,
showBot: Boolean = false,
adminTagColor: Int? = null,
botTagColor: Int? = null,
meTagColor: Int? = null,
opTagColor: Int? = null,
modTagColor: Int? = null,
downVoteEnabled: Boolean = true,
highlightText: String? = null,
options: List<Option> = emptyList(),
Expand Down Expand Up @@ -293,6 +299,12 @@ fun CommentCard(
isMod = isMod,
isAdmin = isAdmin,
isBot = comment.creator?.bot.takeIf { showBot } ?: false,
isCurrentUser = isCurrentUser,
adminTagColor = adminTagColor,
botTagColor = botTagColor,
meTagColor = meTagColor,
opTagColor = opTagColor,
modTagColor = modTagColor,
onOpenCreator = { user ->
onOpenCreator?.invoke(user, "")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.FilterQuality
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.text.LinkAnnotation
Expand All @@ -47,13 +48,9 @@ import com.livefast.eattrash.raccoonforlemmy.core.l10n.LocalStrings
import com.livefast.eattrash.raccoonforlemmy.core.utils.compose.onClick
import com.livefast.eattrash.raccoonforlemmy.domain.lemmy.data.CommunityModel
import com.livefast.eattrash.raccoonforlemmy.domain.lemmy.data.UserModel
import com.livefast.eattrash.raccoonforlemmy.domain.lemmy.data.populateSpecialTags
import com.livefast.eattrash.raccoonforlemmy.domain.lemmy.data.readableName

private const val OP_LABEL = "OP"
private const val BOT_LABEL = "BOT"
private const val MOD_LABEL = "M"
private const val ADMIN_LABEL = "A"

@Composable
fun CommunityAndCreatorInfo(
modifier: Modifier = Modifier,
Expand All @@ -72,8 +69,14 @@ fun CommunityAndCreatorInfo(
isBot: Boolean = false,
isMod: Boolean = false,
isAdmin: Boolean = false,
isCurrentUser: Boolean = false,
markRead: Boolean = false,
compact: Boolean = false,
adminTagColor: Int? = null,
botTagColor: Int? = null,
meTagColor: Int? = null,
opTagColor: Int? = null,
modTagColor: Int? = null,
onOpenCommunity: ((CommunityModel) -> Unit)? = null,
onOpenCreator: ((UserModel) -> Unit)? = null,
onToggleExpanded: (() -> Unit)? = null,
Expand Down Expand Up @@ -218,54 +221,53 @@ fun CommunityAndCreatorInfo(
).clearAndSetSemantics { },
text = creatorName,
style = MaterialTheme.typography.bodySmall,
color = ancillaryColor,
color =
when {
isCurrentUser && meTagColor != null -> Color(meTagColor)
isOp && opTagColor != null -> Color(opTagColor)
else -> ancillaryColor
},
maxLines = 1,
)

// user tags
if (creator.tags.isNotEmpty()) {
val userWithTags =
creator.populateSpecialTags(
isAdmin = isAdmin,
isOp = isOp,
isMe = isCurrentUser,
isBot = isBot,
isMod = isMod,
adminColor = adminTagColor,
opColor = opTagColor,
meColor = meTagColor,
botColor = botTagColor,
modColor = modTagColor,
)
if (userWithTags.tags.isNotEmpty()) {
LazyRow(
modifier = Modifier.widthIn(max = 150.dp),
modifier = Modifier.widthIn(max = 180.dp),
horizontalArrangement = Arrangement.spacedBy(Spacing.xs),
verticalAlignment = Alignment.CenterVertically,
) {
items(creator.tags) { tag ->
items(userWithTags.tags) { tag ->
val isColorful =
tag.color != null && tag.color != Color.Transparent.toArgb()
val tagColor =
tag.color?.let {
Color(it)
} ?: MaterialTheme.colorScheme.onBackground
IndicatorChip(
text = tag.name,
color =
tag.color?.let { Color(it) }
?: MaterialTheme.colorScheme.onBackground,
full = true,
color = tagColor,
full = isColorful,
)
}
}
}
}
}
}
if (isOp) {
IndicatorChip(
modifier = Modifier.align(Alignment.CenterVertically),
text = OP_LABEL,
)
}
if (isBot) {
IndicatorChip(
modifier = Modifier.align(Alignment.CenterVertically),
text = BOT_LABEL,
)
}
if (isMod) {
IndicatorChip(
modifier = Modifier.align(Alignment.CenterVertically),
text = MOD_LABEL,
)
}
if (isAdmin) {
IndicatorChip(
modifier = Modifier.align(Alignment.CenterVertically),
text = ADMIN_LABEL,
)
}

Spacer(modifier = Modifier.weight(1f))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ fun PostCard(
preferNicknames: Boolean = true,
showScores: Boolean = true,
hideAuthor: Boolean = false,
isCurrentUser: Boolean = false,
showBot: Boolean = false,
postLayout: PostLayout = PostLayout.Card,
voteFormat: VoteFormat = VoteFormat.Aggregated,
includeFullBody: Boolean = false,
Expand All @@ -81,6 +83,8 @@ fun PostCard(
actionButtonsActive: Boolean = true,
downVoteEnabled: Boolean = true,
highlightText: String? = null,
botTagColor: Int? = null,
meTagColor: Int? = null,
options: List<Option> = emptyList(),
onOpenCommunity: ((CommunityModel, String) -> Unit)? = null,
onOpenCreator: ((UserModel, String) -> Unit)? = null,
Expand Down Expand Up @@ -218,6 +222,8 @@ fun PostCard(
ExtendedPost(
post = post,
isFromModerator = isFromModerator,
isCurrentUser = isCurrentUser,
showBot = showBot,
hideAuthor = hideAuthor,
backgroundColor =
when (postLayout) {
Expand All @@ -239,6 +245,8 @@ fun PostCard(
actionButtonsActive = actionButtonsActive,
showUnreadComments = showUnreadComments,
downVoteEnabled = downVoteEnabled,
botTagColor = botTagColor,
meTagColor = meTagColor,
options = options,
onOpenCommunity = onOpenCommunity,
onOpenCreator = onOpenCreator,
Expand All @@ -260,6 +268,8 @@ fun PostCard(
CompactPost(
post = post,
isFromModerator = isFromModerator,
isCurrentUser = isCurrentUser,
showBot = showBot,
hideAuthor = hideAuthor,
blurNsfw = blurNsfw,
markRead = markRead,
Expand All @@ -271,6 +281,8 @@ fun PostCard(
actionButtonsActive = actionButtonsActive,
showUnreadComments = showUnreadComments,
downVoteEnabled = downVoteEnabled,
botTagColor = botTagColor,
meTagColor = meTagColor,
options = options,
onOpenCommunity = onOpenCommunity,
onOpenCreator = onOpenCreator,
Expand All @@ -297,6 +309,8 @@ private fun CompactPost(
modifier: Modifier = Modifier,
post: PostModel,
isFromModerator: Boolean,
isCurrentUser: Boolean,
showBot: Boolean,
autoLoadImages: Boolean,
preferNicknames: Boolean,
showScores: Boolean,
Expand All @@ -308,6 +322,8 @@ private fun CompactPost(
voteFormat: VoteFormat,
showUnreadComments: Boolean,
downVoteEnabled: Boolean,
botTagColor: Int? = null,
meTagColor: Int? = null,
optionsMenuOpen: Boolean,
options: List<Option>,
onOpenCommunity: ((CommunityModel, String) -> Unit)?,
Expand Down Expand Up @@ -382,6 +398,10 @@ private fun CompactPost(
markRead = markRead,
compact = true,
isFromModerator = isFromModerator,
isCurrentUser = isCurrentUser,
isBot = post.creator?.bot.takeIf { showBot } ?: false,
botTagColor = botTagColor,
meTagColor = meTagColor,
onOpenCommunity = { community ->
onOpenCommunity?.invoke(community, "")
},
Expand Down Expand Up @@ -529,6 +549,8 @@ private fun ExtendedPost(
modifier: Modifier = Modifier,
post: PostModel,
isFromModerator: Boolean,
isCurrentUser: Boolean,
showBot: Boolean,
autoLoadImages: Boolean,
preferNicknames: Boolean,
showScores: Boolean,
Expand All @@ -546,6 +568,8 @@ private fun ExtendedPost(
backgroundColor: Color,
showUnreadComments: Boolean,
downVoteEnabled: Boolean,
botTagColor: Int? = null,
meTagColor: Int? = null,
optionsMenuOpen: Boolean,
options: List<Option>,
onOpenCommunity: ((CommunityModel, String) -> Unit)?,
Expand Down Expand Up @@ -621,6 +645,10 @@ private fun ExtendedPost(
locked = post.locked,
markRead = markRead,
isFromModerator = isFromModerator,
isBot = post.creator?.bot.takeIf { showBot } ?: false,
isCurrentUser = isCurrentUser,
botTagColor = botTagColor,
meTagColor = meTagColor,
onOpenCommunity = { community ->
onOpenCommunity?.invoke(community, "")
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.RemoveCircle
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.CornerSize
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.Spacing
import com.livefast.eattrash.raccoonforlemmy.core.l10n.LocalStrings
import com.livefast.eattrash.raccoonforlemmy.core.utils.compose.onClick

@Composable
Expand All @@ -27,6 +35,7 @@ fun SettingsColorRow(
modifier: Modifier = Modifier,
subtitle: String? = null,
onTap: (() -> Unit)? = null,
onClear: (() -> Unit)? = null,
) {
Row(
modifier =
Expand Down Expand Up @@ -55,12 +64,37 @@ fun SettingsColorRow(
)
}
}
Spacer(modifier = Modifier.weight(1f))
if (onClear != null && value != Color.Transparent) {
IconButton(
onClick = {
onClear()
},
) {
Icon(
imageVector = Icons.Default.RemoveCircle,
contentDescription = LocalStrings.current.actionClear,
tint = MaterialTheme.colorScheme.onBackground,
)
}
}
Box(
modifier =
Modifier
.padding(start = Spacing.xs)
.size(36.dp)
.background(color = value, shape = CircleShape),
.background(color = value, shape = CircleShape)
.then(
if (value == Color.Transparent) {
Modifier.border(
color = MaterialTheme.colorScheme.onBackground,
width = Dp.Hairline,
shape = CircleShape,
)
} else {
Modifier
},
),
)
}
}
Loading
Loading