From 7f78238a5a54b90a43850987317334e587e7d2f5 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 4 Feb 2023 22:33:33 -0500 Subject: [PATCH] Adding vote icons. Fixes #302 (#313) --- .../jerboa/ui/components/common/TimeAgo.kt | 4 +- .../ui/components/common/VoteHelpers.kt | 66 ++++++++----------- app/src/main/res/drawable/down_filled.xml | 4 ++ app/src/main/res/drawable/down_outline.xml | 4 ++ app/src/main/res/drawable/up_filled.xml | 4 ++ app/src/main/res/drawable/up_outline.xml | 4 ++ 6 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 app/src/main/res/drawable/down_filled.xml create mode 100644 app/src/main/res/drawable/down_outline.xml create mode 100644 app/src/main/res/drawable/up_filled.xml create mode 100644 app/src/main/res/drawable/up_outline.xml diff --git a/app/src/main/java/com/jerboa/ui/components/common/TimeAgo.kt b/app/src/main/java/com/jerboa/ui/components/common/TimeAgo.kt index 98e5963e3..e23f80fb6 100644 --- a/app/src/main/java/com/jerboa/ui/components/common/TimeAgo.kt +++ b/app/src/main/java/com/jerboa/ui/components/common/TimeAgo.kt @@ -79,8 +79,6 @@ fun ScoreAndTime( published: String, updated: String? ) { - val expandSize = if (myVote == 0) { 1.0 } else { 1.3 } - Row( horizontalArrangement = Arrangement.spacedBy(SMALL_PADDING), verticalAlignment = Alignment.CenterVertically @@ -88,7 +86,7 @@ fun ScoreAndTime( Text( text = score.toString(), color = scoreColor(myVote = myVote), - fontSize = MaterialTheme.typography.bodyMedium.fontSize.times(expandSize) + fontSize = MaterialTheme.typography.bodyMedium.fontSize.times(1.3) ) DotSpacer(0.dp, MaterialTheme.typography.bodyMedium) TimeAgo(published = published, updated = updated) diff --git a/app/src/main/java/com/jerboa/ui/components/common/VoteHelpers.kt b/app/src/main/java/com/jerboa/ui/components/common/VoteHelpers.kt index 5c5e02e90..3d75b4cb6 100644 --- a/app/src/main/java/com/jerboa/ui/components/common/VoteHelpers.kt +++ b/app/src/main/java/com/jerboa/ui/components/common/VoteHelpers.kt @@ -1,14 +1,11 @@ package com.jerboa.ui.components.common -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ThumbDown -import androidx.compose.material.icons.outlined.Favorite -import androidx.compose.material.icons.outlined.FavoriteBorder -import androidx.compose.material.icons.outlined.ThumbDown import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.vectorResource +import com.jerboa.R import com.jerboa.VoteType import com.jerboa.db.Account import com.jerboa.ui.theme.muted @@ -23,14 +20,9 @@ fun VoteGeneric( showNumber: Boolean = true, account: Account? ) { - val voteColor = - when (type) { - VoteType.Upvote -> upvoteColor(myVote = myVote) - else -> downvoteColor(myVote = myVote) - } - val voteIcon = when (type) { - VoteType.Upvote -> upvoteIcon(myVote = myVote) - else -> downvoteIcon(myVote = myVote) + val iconAndColor = when (type) { + VoteType.Upvote -> upvoteIconAndColor(myVote = myVote) + else -> downvoteIconAndColor(myVote = myVote) } val votesStr = if (showNumber) { @@ -42,43 +34,43 @@ fun VoteGeneric( } else { null } - ActionBarButton( onClick = { onVoteClick(item) }, - contentColor = voteColor, - icon = voteIcon, + contentColor = iconAndColor.second, + icon = iconAndColor.first, text = votesStr, account = account ) } @Composable -fun upvoteColor(myVote: Int?): Color { +fun upvoteIconAndColor(myVote: Int?): Pair { return when (myVote) { - 1 -> MaterialTheme.colorScheme.primary - else -> MaterialTheme.colorScheme.onBackground.muted + 1 -> Pair( + ImageVector.vectorResource(id = R.drawable.up_filled), + MaterialTheme.colorScheme + .primary + ) + else -> Pair( + ImageVector.vectorResource(id = R.drawable.up_outline), + MaterialTheme + .colorScheme.onBackground.muted + ) } } @Composable -fun upvoteIcon(myVote: Int?): ImageVector { - return when (myVote) { - 1 -> Icons.Outlined.Favorite - else -> Icons.Outlined.FavoriteBorder - } -} - -@Composable -fun downvoteColor(myVote: Int?): Color { - return when (myVote) { - -1 -> MaterialTheme.colorScheme.error - else -> MaterialTheme.colorScheme.onBackground.muted - } -} - -fun downvoteIcon(myVote: Int?): ImageVector { +fun downvoteIconAndColor(myVote: Int?): Pair { return when (myVote) { - -1 -> Icons.Filled.ThumbDown - else -> Icons.Outlined.ThumbDown + -1 -> Pair( + ImageVector.vectorResource(id = R.drawable.down_filled), + MaterialTheme + .colorScheme.error + ) + else -> Pair( + ImageVector.vectorResource(id = R.drawable.down_outline), + MaterialTheme + .colorScheme.onBackground.muted + ) } } diff --git a/app/src/main/res/drawable/down_filled.xml b/app/src/main/res/drawable/down_filled.xml new file mode 100644 index 000000000..fa79d1f8c --- /dev/null +++ b/app/src/main/res/drawable/down_filled.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/drawable/down_outline.xml b/app/src/main/res/drawable/down_outline.xml new file mode 100644 index 000000000..774a40aa6 --- /dev/null +++ b/app/src/main/res/drawable/down_outline.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/drawable/up_filled.xml b/app/src/main/res/drawable/up_filled.xml new file mode 100644 index 000000000..6c71d82db --- /dev/null +++ b/app/src/main/res/drawable/up_filled.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/drawable/up_outline.xml b/app/src/main/res/drawable/up_outline.xml new file mode 100644 index 000000000..16fd23dad --- /dev/null +++ b/app/src/main/res/drawable/up_outline.xml @@ -0,0 +1,4 @@ + + +