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

Adding vote icons. Fixes #302 #313

Merged
merged 1 commit into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,14 @@ 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
) {
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)
Expand Down
66 changes: 29 additions & 37 deletions app/src/main/java/com/jerboa/ui/components/common/VoteHelpers.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,14 +20,9 @@ fun <T> 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) {
Expand All @@ -42,43 +34,43 @@ fun <T> 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<ImageVector, Color> {
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<ImageVector, Color> {
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
)
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/down_filled.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="768"
android:viewportWidth="768" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#000" android:pathData="M589.25,340.99c-24.99,-24.99 -65.5,-24.99 -90.5,0l-50.75,50.75v-231.74c0,-35.36 -28.67,-64 -64,-64 -35.36,0 -64,28.64 -64,64v231.74l-50.75,-50.75c-24.99,-24.99 -65.5,-24.99 -90.5,0s-24.99,65.5 0,90.5l205.25,205.25 205.25,-205.25c24.99,-24.99 24.99,-65.47 0,-90.5z"/>
</vector>
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/down_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="768"
android:viewportWidth="768" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#000" android:pathData="M384,681.98l-227.87,-227.87c-37.44,-37.44 -37.44,-98.34 0,-135.74 35.01,-35.01 95.3,-36.42 131.87,-3.68v-154.69c0,-52.93 43.07,-96 96,-96s96,43.07 96,96v154.69c36.58,-32.74 96.86,-31.33 131.87,3.68 37.44,37.41 37.44,98.3 0,135.74l-227.87,227.87zM224,354.24c-8.58,0 -16.58,3.33 -22.62,9.38 -12.51,12.48 -12.51,32.74 0,45.25l182.62,182.62 182.62,-182.62c12.51,-12.51 12.51,-32.77 0,-45.25 -12.13,-12.13 -33.12,-12.13 -45.25,0l-105.38,105.38v-308.99c0,-17.63 -14.34,-32 -32,-32s-32,14.37 -32,32v308.99l-105.38,-105.38c-6.05,-6.05 -14.05,-9.38 -22.62,-9.38z"/>
</vector>
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/up_filled.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="768"
android:viewportWidth="768" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#000" android:pathData="M384,101.5l-205.25,205.25c-24.99,24.99 -24.99,65.5 0,90.5s65.5,24.99 90.5,0l50.75,-50.75v231.74c0,35.33 28.64,64 64,64 35.33,0 64,-28.67 64,-64v-231.74l50.75,50.75c12.51,12.51 28.86,18.75 45.25,18.75s32.74,-6.24 45.25,-18.75c24.99,-24.99 24.99,-65.5 0,-90.5l-205.25,-205.25z"/>
</vector>
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/up_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="768"
android:viewportWidth="768" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#000" android:pathData="M384,672c-52.93,0 -96,-43.07 -96,-96v-152.45c-36.58,32.77 -96.8,31.33 -131.87,-3.68 -37.44,-37.41 -37.44,-98.34 0,-135.74l227.87,-227.87 227.87,227.87c37.44,37.41 37.44,98.34 0,135.74 -35.01,35.04 -95.33,36.48 -131.87,3.68v152.45c0,52.93 -43.07,96 -96,96zM352,269.25v306.75c0,17.63 14.34,32 32,32s32,-14.37 32,-32v-306.75l105.38,105.38c12.13,12.1 33.12,12.1 45.25,0 12.51,-12.51 12.51,-32.74 0,-45.25l-182.62,-182.62 -182.62,182.62c-12.51,12.51 -12.51,32.74 0,45.25 12.13,12.1 33.12,12.1 45.25,0l105.38,-105.38z"/>
</vector>