mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-03 13:57:32 +01:00
fix: separate upvotes and downvotes in inbox
This commit is contained in:
parent
c406ff7b7f
commit
cb0f030295
@ -38,6 +38,7 @@ fun InboxCard(
|
||||
mention: PersonMentionModel,
|
||||
type: InboxCardType,
|
||||
autoLoadImages: Boolean = true,
|
||||
separateUpAndDownVotes: Boolean = true,
|
||||
postLayout: PostLayout = PostLayout.Card,
|
||||
onOpenPost: (PostModel) -> Unit,
|
||||
onOpenCreator: (UserModel) -> Unit,
|
||||
@ -91,6 +92,9 @@ fun InboxCard(
|
||||
autoLoadImages = autoLoadImages,
|
||||
date = mention.publishDate,
|
||||
score = mention.score,
|
||||
upvotes = mention.upvotes,
|
||||
downvotes = mention.downvotes,
|
||||
separateUpAndDownVotes = separateUpAndDownVotes,
|
||||
upVoted = mention.myVote > 0,
|
||||
downVoted = mention.myVote < 0,
|
||||
onOpenCommunity = onOpenCommunity,
|
||||
|
@ -22,6 +22,8 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.graphics.FilterQuality
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
@ -40,7 +42,10 @@ fun InboxReplySubtitle(
|
||||
community: CommunityModel? = null,
|
||||
iconSize: Dp = 20.dp,
|
||||
date: String? = null,
|
||||
score: Int,
|
||||
score: Int = 0,
|
||||
upvotes: Int = 0,
|
||||
downvotes: Int = 0,
|
||||
separateUpAndDownVotes: Boolean = false,
|
||||
upVoted: Boolean = false,
|
||||
downVoted: Boolean = false,
|
||||
onOpenCommunity: ((CommunityModel) -> Unit)? = null,
|
||||
@ -198,7 +203,47 @@ fun InboxReplySubtitle(
|
||||
),
|
||||
)
|
||||
Text(
|
||||
text = "$score",
|
||||
text = buildAnnotatedString {
|
||||
if (separateUpAndDownVotes) {
|
||||
val upvoteText = upvotes.toString()
|
||||
append(upvoteText)
|
||||
if (upVoted) {
|
||||
addStyle(
|
||||
style = SpanStyle(color = MaterialTheme.colorScheme.surfaceTint),
|
||||
start = 0,
|
||||
end = upvoteText.length
|
||||
)
|
||||
}
|
||||
append(" / ")
|
||||
val downvoteText = downvotes.toString()
|
||||
append(downvoteText)
|
||||
if (downVoted) {
|
||||
addStyle(
|
||||
style = SpanStyle(color = MaterialTheme.colorScheme.tertiary),
|
||||
start = upvoteText.length + 3,
|
||||
end = upvoteText.length + 3 + downvoteText.length
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val text = score.toString()
|
||||
append(text)
|
||||
if (upVoted) {
|
||||
addStyle(
|
||||
style = SpanStyle(color = MaterialTheme.colorScheme.surfaceTint),
|
||||
start = 0,
|
||||
end = text.length
|
||||
)
|
||||
} else if (downVoted) {
|
||||
addStyle(
|
||||
style = SpanStyle(color = MaterialTheme.colorScheme.tertiary),
|
||||
start = 0,
|
||||
end = length
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
Image(
|
||||
modifier = buttonModifier
|
||||
|
@ -387,6 +387,8 @@ class PostDetailScreen(
|
||||
modifier = Modifier.padding(
|
||||
top = Spacing.xxs,
|
||||
bottom = Spacing.s,
|
||||
start = Spacing.s,
|
||||
end = Spacing.s,
|
||||
),
|
||||
horizontalArrangement = Arrangement.spacedBy(Spacing.xxs),
|
||||
) {
|
||||
|
@ -77,7 +77,7 @@ internal class DefaultSettingsRepository(
|
||||
keyStore[KeyStoreKeys.UiTheme, 0]
|
||||
} else null,
|
||||
uiFontScale = keyStore[KeyStoreKeys.UiFontScale, 1f],
|
||||
uiFontFamily = keyStore[KeyStoreKeys.UiFontFamily, 1],
|
||||
uiFontFamily = keyStore[KeyStoreKeys.UiFontFamily, 0],
|
||||
contentFontScale = keyStore[KeyStoreKeys.ContentFontScale, 1f],
|
||||
locale = keyStore[KeyStoreKeys.Locale, ""].takeIf { it.isNotEmpty() },
|
||||
defaultListingType = keyStore[KeyStoreKeys.DefaultListingType, 0],
|
||||
|
@ -9,6 +9,8 @@ data class PersonMentionModel(
|
||||
val comment: CommentModel,
|
||||
val community: CommunityModel,
|
||||
val score: Int,
|
||||
val upvotes: Int,
|
||||
val downvotes: Int,
|
||||
val myVote: Int,
|
||||
val saved: Boolean,
|
||||
val isOwnPost: Boolean = false,
|
||||
|
@ -126,6 +126,14 @@ class CommentRepository(
|
||||
!voted -> mention.score - 1
|
||||
else -> mention.score
|
||||
},
|
||||
upvotes = when {
|
||||
voted -> mention.upvotes + 1
|
||||
else -> mention.upvotes - 1
|
||||
},
|
||||
downvotes = when {
|
||||
mention.myVote < 0 -> mention.downvotes - 1
|
||||
else -> mention.downvotes
|
||||
}
|
||||
)
|
||||
|
||||
suspend fun upVote(comment: CommentModel, auth: String, voted: Boolean) {
|
||||
@ -163,6 +171,14 @@ class CommentRepository(
|
||||
!downVoted -> mention.score + 1
|
||||
else -> mention.score
|
||||
},
|
||||
downvotes = when {
|
||||
downVoted -> mention.downvotes + 1
|
||||
else -> mention.downvotes - 1
|
||||
},
|
||||
upvotes = when {
|
||||
mention.myVote > 0 -> mention.upvotes - 1
|
||||
else -> mention.upvotes
|
||||
}
|
||||
)
|
||||
|
||||
suspend fun downVote(comment: CommentModel, auth: String, downVoted: Boolean) = runCatching {
|
||||
|
@ -172,6 +172,8 @@ internal fun PersonMentionView.toModel() = PersonMentionModel(
|
||||
myVote = myVote ?: 0,
|
||||
saved = saved,
|
||||
publishDate = personMention.published,
|
||||
upvotes = counts.upvotes,
|
||||
downvotes = counts.downvotes,
|
||||
)
|
||||
|
||||
internal fun CommentReplyView.toModel() = PersonMentionModel(
|
||||
@ -206,6 +208,8 @@ internal fun CommentReplyView.toModel() = PersonMentionModel(
|
||||
myVote = myVote ?: 0,
|
||||
saved = saved,
|
||||
publishDate = commentReply.published,
|
||||
upvotes = counts.upvotes,
|
||||
downvotes = counts.downvotes,
|
||||
)
|
||||
|
||||
internal fun PrivateMessageView.toModel() = PrivateMessageModel(
|
||||
|
@ -28,6 +28,7 @@ interface InboxMentionsMviModel :
|
||||
val swipeActionsEnabled: Boolean = true,
|
||||
val postLayout: PostLayout = PostLayout.Card,
|
||||
val autoLoadImages: Boolean = true,
|
||||
val separateUpAndDownVotes: Boolean = true,
|
||||
)
|
||||
|
||||
sealed interface Effect {
|
||||
|
@ -171,6 +171,7 @@ class InboxMentionsScreen : Tab {
|
||||
postLayout = uiState.postLayout,
|
||||
type = InboxCardType.Mention,
|
||||
autoLoadImages = uiState.autoLoadImages,
|
||||
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
|
||||
onOpenPost = { post ->
|
||||
navigator?.push(
|
||||
PostDetailScreen(
|
||||
|
@ -67,6 +67,7 @@ class InboxMentionsViewModel(
|
||||
it.copy(
|
||||
swipeActionsEnabled = settings.enableSwipeActions,
|
||||
autoLoadImages = settings.autoLoadImages,
|
||||
separateUpAndDownVotes = settings.separateUpAndDownVotes,
|
||||
)
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
@ -28,6 +28,7 @@ interface InboxRepliesMviModel :
|
||||
val postLayout: PostLayout = PostLayout.Card,
|
||||
val swipeActionsEnabled: Boolean = true,
|
||||
val autoLoadImages: Boolean = true,
|
||||
val separateUpAndDownVotes: Boolean = true,
|
||||
)
|
||||
|
||||
sealed interface Effect {
|
||||
|
@ -200,6 +200,7 @@ class InboxRepliesScreen : Tab {
|
||||
postLayout = uiState.postLayout,
|
||||
type = InboxCardType.Reply,
|
||||
autoLoadImages = uiState.autoLoadImages,
|
||||
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
|
||||
onOpenPost = { post ->
|
||||
navigator?.push(
|
||||
PostDetailScreen(
|
||||
|
@ -70,6 +70,7 @@ class InboxRepliesViewModel(
|
||||
it.copy(
|
||||
swipeActionsEnabled = settings.enableSwipeActions,
|
||||
autoLoadImages = settings.autoLoadImages,
|
||||
separateUpAndDownVotes = settings.separateUpAndDownVotes,
|
||||
)
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
Loading…
x
Reference in New Issue
Block a user