Skip to content

Commit

Permalink
Show post score next to time. Fixes #303 (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines authored Feb 4, 2023
1 parent aaa1c04 commit dfe9945
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 15 deletions.
33 changes: 20 additions & 13 deletions app/src/main/java/com/jerboa/ui/components/common/AppBars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import com.google.accompanist.flowlayout.FlowMainAxisAlignment
import com.google.accompanist.flowlayout.FlowRow
import com.jerboa.datatypes.PersonSafe
import com.jerboa.datatypes.api.GetUnreadCountResponse
import com.jerboa.datatypes.samplePersonSafe
import com.jerboa.datatypes.samplePost
import com.jerboa.db.Account
import com.jerboa.loginFirstToast
import com.jerboa.siFormat
Expand Down Expand Up @@ -239,22 +241,27 @@ fun CommentOrPostNodeHeader(
isCommunityBanned = isCommunityBanned
)
}

Row(
horizontalArrangement = Arrangement.spacedBy(SMALL_PADDING),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = score.toString(),
color = scoreColor(myVote = myVote),
fontSize = MaterialTheme.typography.bodyLarge.fontSize.times(1.1)
)
DotSpacer(0.dp, MaterialTheme.typography.bodyMedium)
TimeAgo(published = published, updated = updated)
}
ScoreAndTime(score = score, myVote = myVote, published = published, updated = updated)
}
}

@Preview
@Composable
fun CommentOrPostNodeHeaderPreview() {
CommentOrPostNodeHeader(
creator = samplePersonSafe,
score = 23,
myVote = 1,
published = samplePost.published,
updated = samplePost.updated,
deleted = false,
onPersonClick = {},
isPostCreator = true,
isModerator = true,
isCommunityBanned = false
)
}

@Composable
fun ActionBarButton(
onClick: () -> Unit,
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/java/com/jerboa/ui/components/common/TimeAgo.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.jerboa.ui.components.common

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.jerboa.datatypes.samplePersonSafe
import com.jerboa.datatypes.samplePost
import com.jerboa.prettyTime
import com.jerboa.prettyTimeShortener
import com.jerboa.ui.theme.SMALL_PADDING
Expand Down Expand Up @@ -67,3 +71,37 @@ fun dateStringToPretty(dateStr: String, includeAgo: Boolean = false): String {
fun TimeAgoPreview() {
TimeAgo(samplePersonSafe.published, samplePersonSafe.updated)
}

@Composable
fun ScoreAndTime(
score: Int,
myVote: Int?,
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)
)
DotSpacer(0.dp, MaterialTheme.typography.bodyMedium)
TimeAgo(published = published, updated = updated)
}
}

@Preview
@Composable
fun ScoreAndTimePreview() {
ScoreAndTime(
score = 23,
myVote = -1,
published = samplePost.published,
updated = samplePost.updated
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ import com.jerboa.ui.components.common.MyMarkdownText
import com.jerboa.ui.components.common.PictrsThumbnailImage
import com.jerboa.ui.components.common.PictrsUrlImage
import com.jerboa.ui.components.common.PreviewLines
import com.jerboa.ui.components.common.ScoreAndTime
import com.jerboa.ui.components.common.SimpleTopAppBar
import com.jerboa.ui.components.common.TimeAgo
import com.jerboa.ui.components.common.VoteGeneric
import com.jerboa.ui.components.community.CommunityName
import com.jerboa.ui.components.person.PersonProfileLink
Expand Down Expand Up @@ -157,7 +157,9 @@ fun PostHeaderLine(
}
}
}
TimeAgo(
ScoreAndTime(
score = postView.counts.score,
myVote = postView.my_vote,
published = postView.post.published,
updated = postView.post.updated
)
Expand Down Expand Up @@ -466,6 +468,7 @@ fun PostFooterLine(
votes = upvotes,
item = postView,
type = VoteType.Upvote,
showNumber = (downvotes != 0),
onVoteClick = {
onUpvoteClick(it)
},
Expand Down

0 comments on commit dfe9945

Please sign in to comment.