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

Move time ago and score to a flowrow layout #1615

Merged
merged 9 commits into from
Aug 13, 2024
2 changes: 2 additions & 0 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.DisposableEffect
Expand Down Expand Up @@ -89,6 +90,7 @@ class MainActivity : AppCompatActivity() {
factoryProducer = { AccountSettingsViewModelFactory.Factory },
)

@OptIn(ExperimentalLayoutApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ fun getCommentIdDepthFromPath(

fun nsfwCheck(postView: PostView): Boolean = nsfwCheck(postView.post, postView.community)

fun nsfwCheck(
private fun nsfwCheck(
post: Post,
community: Community,
): Boolean = post.nsfw || community.nsfw
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/jerboa/datatypes/SampleData.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jerboa.datatypes

import com.jerboa.feat.InstantScores
import it.vercruysse.lemmyapi.datatypes.Comment
import it.vercruysse.lemmyapi.datatypes.CommentAggregates
import it.vercruysse.lemmyapi.datatypes.CommentReply
Expand Down Expand Up @@ -281,9 +282,9 @@ val samplePostAggregates =
PostAggregates(
post_id = 135129,
comments = 4,
score = 8,
score = 5,
upvotes = 8,
downvotes = 0,
downvotes = 3,
published = "2022-01-02T04:02:44.592929Z",
newest_comment_time = "2022-01-02T04:02:44.592929Z",
)
Expand Down Expand Up @@ -839,3 +840,11 @@ val samplePrivateMessageReportView =
creator = samplePerson2,
resolver = samplePerson3,
)

val sampleInstantScores =
InstantScores(
myVote = samplePostView.my_vote,
score = samplePostView.counts.score,
upvotes = samplePostView.counts.upvotes,
downvotes = samplePostView.counts.downvotes,
)
2 changes: 1 addition & 1 deletion app/src/main/java/com/jerboa/feat/Voting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun upvotePercent(
downvotes: Long,
): Float = (upvotes.toFloat() / (upvotes + downvotes))

fun formatPercent(pct: Float): String = "%.0f%%".format(pct * 100F)
fun formatPercent(pct: Float): String = "%.0f".format(pct * 100F)

private fun scoreOrPctStr(
score: Long,
Expand Down
37 changes: 21 additions & 16 deletions app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ import com.jerboa.ui.components.common.CommentOrPostNodeHeader
import com.jerboa.ui.components.common.MarkdownHelper
import com.jerboa.ui.components.common.MyMarkdownText
import com.jerboa.ui.components.common.SwipeToAction
import com.jerboa.ui.components.common.UpvotePercentage
import com.jerboa.ui.components.common.VoteGeneric
import com.jerboa.ui.components.common.VoteScore
import com.jerboa.ui.components.common.rememberSwipeActionState
import com.jerboa.ui.components.community.CommunityLink
import com.jerboa.ui.theme.BORDER_WIDTH
Expand All @@ -97,18 +99,14 @@ import it.vercruysse.lemmyapi.datatypes.PostId
fun CommentNodeHeader(
commentView: CommentView,
onPersonClick: (personId: PersonId) -> Unit,
instantScores: InstantScores,
collapsedCommentsCount: Long,
isExpanded: Boolean,
onClick: () -> Unit,
onLongClick: () -> Unit,
showAvatar: Boolean,
voteDisplayMode: LocalUserVoteDisplayMode,
) {
CommentOrPostNodeHeader(
creator = commentView.creator,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
published = commentView.comment.published,
updated = commentView.comment.updated,
deleted = commentView.comment.deleted,
Expand All @@ -121,6 +119,7 @@ fun CommentNodeHeader(
onLongCLick = onLongClick,
showAvatar = showAvatar,
isDistinguished = commentView.comment.distinguished,
isNsfw = false,
)
}

Expand All @@ -129,13 +128,6 @@ fun CommentNodeHeader(
fun CommentNodeHeaderPreview() {
CommentNodeHeader(
commentView = sampleCommentView,
instantScores = InstantScores(
score = 23,
upvotes = 21,
downvotes = 2,
myVote = 26,
),
voteDisplayMode = LocalUserVoteDisplayMode.default(),
onPersonClick = {},
onClick = {},
onLongClick = {},
Expand Down Expand Up @@ -329,8 +321,6 @@ fun LazyListScope.commentNodeItem(
CommentNodeHeader(
commentView = commentView,
onPersonClick = onPersonClick,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
onClick = {
onHeaderClick(commentView)
},
Expand Down Expand Up @@ -372,6 +362,7 @@ fun LazyListScope.commentNodeItem(
admins = admins,
moderators = moderators,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
onUpvoteClick = {
instantScores =
instantScores.update(VoteType.Upvote)
Expand Down Expand Up @@ -746,6 +737,7 @@ fun CommentFooterLine(
moderators: List<PersonId>?,
enableDownVotes: Boolean,
instantScores: InstantScores,
voteDisplayMode: LocalUserVoteDisplayMode,
onUpvoteClick: () -> Unit,
onDownvoteClick: () -> Unit,
onReplyClick: (commentView: CommentView) -> Unit,
Expand Down Expand Up @@ -822,17 +814,30 @@ fun CommentFooterLine(
).padding(top = MEDIUM_PADDING),
) {
Row(
horizontalArrangement = Arrangement.spacedBy(XXL_PADDING),
horizontalArrangement = Arrangement.spacedBy(LARGE_PADDING),
) {
VoteScore(
instantScores = instantScores,
onVoteClick = onUpvoteClick,
voteDisplayMode = voteDisplayMode,
account = account,
)
UpvotePercentage(
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
account = account,
)
VoteGeneric(
myVote = instantScores.myVote,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
type = VoteType.Upvote,
onVoteClick = onUpvoteClick,
account = account,
)
if (enableDownVotes) {
VoteGeneric(
myVote = instantScores.myVote,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
type = VoteType.Downvote,
onVoteClick = onDownvoteClick,
account = account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.jerboa.R
import com.jerboa.datatypes.sampleInstantScores
import com.jerboa.datatypes.samplePersonMentionView
import com.jerboa.db.entity.Account
import com.jerboa.db.entity.AnonAccount
import com.jerboa.feat.BlurNSFW
import com.jerboa.feat.InstantScores
import com.jerboa.feat.VoteType
Expand All @@ -38,10 +40,11 @@ import com.jerboa.ui.components.comment.CommentBody
import com.jerboa.ui.components.comment.PostAndCommunityContextHeader
import com.jerboa.ui.components.common.ActionBarButton
import com.jerboa.ui.components.common.CommentOrPostNodeHeader
import com.jerboa.ui.components.common.UpvotePercentage
import com.jerboa.ui.components.common.VoteGeneric
import com.jerboa.ui.components.common.VoteScore
import com.jerboa.ui.theme.LARGE_PADDING
import com.jerboa.ui.theme.SMALL_PADDING
import com.jerboa.ui.theme.XXL_PADDING
import it.vercruysse.lemmyapi.datatypes.Community
import it.vercruysse.lemmyapi.datatypes.LocalUserVoteDisplayMode
import it.vercruysse.lemmyapi.datatypes.Person
Expand All @@ -54,21 +57,18 @@ import it.vercruysse.lemmyapi.datatypes.PostId
fun CommentMentionNodeHeader(
personMentionView: PersonMentionView,
onPersonClick: (personId: PersonId) -> Unit,
instantScores: InstantScores,
onClick: () -> Unit,
onLongClick: () -> Unit,
showAvatar: Boolean,
voteDisplayMode: LocalUserVoteDisplayMode,
) {
CommentOrPostNodeHeader(
creator = personMentionView.creator,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
published = personMentionView.comment.published,
updated = personMentionView.comment.updated,
deleted = personMentionView.comment.deleted,
onPersonClick = onPersonClick,
isPostCreator = false,
isNsfw = false,
isDistinguished = personMentionView.comment.distinguished,
isCommunityBanned = personMentionView.creator_banned_from_community,
onClick = onClick,
Expand All @@ -82,13 +82,6 @@ fun CommentMentionNodeHeader(
fun CommentMentionNodeHeaderPreview() {
CommentMentionNodeHeader(
personMentionView = samplePersonMentionView,
instantScores = InstantScores(
score = 23,
myVote = 26,
upvotes = 21,
downvotes = 2,
),
voteDisplayMode = LocalUserVoteDisplayMode.default(),
onPersonClick = {},
onClick = {},
onLongClick = {},
Expand All @@ -112,7 +105,8 @@ fun CommentMentionNodeFooterLine(
onRemoveClick: (personMentionView: PersonMentionView) -> Unit,
onLinkClick: (personMentionView: PersonMentionView) -> Unit,
onBlockCreatorClick: (creator: Person) -> Unit,
myVote: Int,
instantScores: InstantScores,
voteDisplayMode: LocalUserVoteDisplayMode,
account: Account,
enableDownvotes: Boolean,
viewSource: Boolean,
Expand Down Expand Up @@ -153,17 +147,30 @@ fun CommentMentionNodeFooterLine(
.padding(top = LARGE_PADDING, bottom = SMALL_PADDING),
) {
Row(
horizontalArrangement = Arrangement.spacedBy(XXL_PADDING),
horizontalArrangement = Arrangement.spacedBy(LARGE_PADDING),
) {
VoteScore(
instantScores = instantScores,
onVoteClick = onUpvoteClick,
voteDisplayMode = voteDisplayMode,
account = account,
)
UpvotePercentage(
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
account = account,
)
VoteGeneric(
myVote = myVote,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
type = VoteType.Upvote,
onVoteClick = onUpvoteClick,
account = account,
)
if (enableDownvotes) {
VoteGeneric(
myVote = myVote,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
type = VoteType.Downvote,
onVoteClick = onDownvoteClick,
account = account,
Expand Down Expand Up @@ -239,6 +246,32 @@ fun CommentMentionNodeFooterLine(
}
}

@Composable
@Preview
fun CommentMentionNodeFooterLinePreview() {
CommentMentionNodeFooterLine(
personMentionView = samplePersonMentionView,
admins = listOf(),
moderators = listOf(),
onUpvoteClick = { },
onDownvoteClick = { },
onReplyClick = {},
onSaveClick = {},
onMarkAsReadClick = {},
onPersonClick = {},
onViewSourceClick = { },
onReportClick = {},
onRemoveClick = {},
onLinkClick = {},
onBlockCreatorClick = {},
instantScores = sampleInstantScores,
voteDisplayMode = LocalUserVoteDisplayMode.default(),
account = AnonAccount,
enableDownvotes = true,
viewSource = false,
)
}

@Composable
fun CommentMentionNode(
personMentionView: PersonMentionView,
Expand Down Expand Up @@ -294,8 +327,6 @@ fun CommentMentionNode(
CommentMentionNodeHeader(
personMentionView = personMentionView,
onPersonClick = onPersonClick,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
onClick = {
isExpanded = !isExpanded
},
Expand Down Expand Up @@ -352,7 +383,8 @@ fun CommentMentionNode(
account = account,
enableDownvotes = enableDownvotes,
viewSource = viewSource,
myVote = instantScores.myVote,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
)
}
}
Expand Down
Loading