Skip to content

Commit 3dc8bca

Browse files
committed
Adding modified times. Fixes #46
1 parent 91bc0d6 commit 3dc8bca

File tree

7 files changed

+53
-20
lines changed

7 files changed

+53
-20
lines changed

app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fun CommentNodeHeader(
4343
score = score,
4444
myVote = myVote,
4545
published = commentView.comment.published,
46+
updated = commentView.comment.updated,
4647
onPersonClick = onPersonClick,
4748
isPostCreator = isPostCreator(commentView),
4849
isModerator = isModerator,

app/src/main/java/com/jerboa/ui/components/common/AppBars.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ fun CommentOrPostNodeHeader(
140140
score: Int,
141141
myVote: Int?,
142142
published: String,
143+
updated: String?,
143144
onPersonClick: (personId: Int) -> Unit = {},
144145
isPostCreator: Boolean,
145146
isModerator: Boolean,
@@ -171,7 +172,7 @@ fun CommentOrPostNodeHeader(
171172
color = scoreColor(myVote = myVote)
172173
)
173174
DotSpacer(0.dp)
174-
TimeAgo(dateStr = published)
175+
TimeAgo(published = published, updated = updated)
175176
}
176177
}
177178
}
Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.jerboa.ui.components.common
22

3+
import androidx.compose.foundation.layout.Row
34
import androidx.compose.material.Text
45
import androidx.compose.runtime.Composable
6+
import androidx.compose.ui.text.font.FontStyle
57
import androidx.compose.ui.tooling.preview.Preview
68
import com.jerboa.datatypes.samplePersonSafe
79
import com.jerboa.prettyTime
@@ -11,28 +13,50 @@ import java.time.Instant
1113
import java.util.*
1214

1315
@Composable
14-
fun TimeAgo(dateStr: String, precedingString: String? = null, includeAgo: Boolean = false) {
15-
val then = Date.from(Instant.parse(dateStr + "Z"))
16-
val pt = prettyTime.formatDuration(then)
16+
fun TimeAgo(
17+
published: String,
18+
updated: String? = null,
19+
precedingString: String? = null,
20+
includeAgo: Boolean = false
21+
) {
22+
val publishedPretty = dateStringToPretty(published, includeAgo)
1723

18-
val pretty = if (includeAgo) {
19-
pt
20-
} else {
21-
prettyTimeShortener(pt)
24+
val afterPreceding = precedingString?.let {
25+
"$it $publishedPretty ago"
26+
} ?: run { publishedPretty }
27+
28+
Row {
29+
Text(
30+
text = afterPreceding,
31+
color = Muted,
32+
)
33+
34+
updated?.also {
35+
val updatedPretty = dateStringToPretty(it, includeAgo)
36+
37+
DotSpacer()
38+
Text(
39+
text = "($updatedPretty)",
40+
color = Muted,
41+
fontStyle = FontStyle.Italic,
42+
)
43+
}
2244
}
45+
}
2346

24-
val afterPreceding = precedingString?.let {
25-
"$it $pretty ago"
26-
} ?: run { pretty }
47+
fun dateStringToPretty(dateStr: String, includeAgo: Boolean = false): String {
48+
val publishedDate = Date.from(Instant.parse(dateStr + "Z"))
49+
val prettyPublished = prettyTime.formatDuration(publishedDate)
2750

28-
Text(
29-
text = afterPreceding,
30-
color = Muted,
31-
)
51+
return if (includeAgo) {
52+
prettyPublished
53+
} else {
54+
prettyTimeShortener(prettyPublished)
55+
}
3256
}
3357

3458
@Preview
3559
@Composable
3660
fun TimeAgoPreview() {
37-
TimeAgo(samplePersonSafe.published)
61+
TimeAgo(samplePersonSafe.published, samplePersonSafe.updated)
3862
}

app/src/main/java/com/jerboa/ui/components/home/Sidebar.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fun Sidebar(siteView: SiteView) {
4646
TimeAgo(
4747
precedingString = "Created",
4848
includeAgo = true,
49-
dateStr = site.published
49+
published = site.published
5050
)
5151
CommentsAndPosts(siteView = siteView)
5252
site.sidebar?.also {

app/src/main/java/com/jerboa/ui/components/person/PersonProfile.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fun PersonProfileTopSection(
5959
TimeAgo(
6060
precedingString = "Joined",
6161
includeAgo = true,
62-
dateStr = personView.person.published
62+
published = personView.person.published
6363
)
6464
CommentsAndPosts(personView)
6565
personView.person.bio?.also {

app/src/main/java/com/jerboa/ui/components/post/PostListing.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ fun PostHeaderLine(
6363
}
6464
}
6565

66-
TimeAgo(dateStr = postView.post.published)
66+
TimeAgo(
67+
published = postView.post.published,
68+
updated = postView.post.updated,
69+
)
6770
}
6871
}
6972

@@ -85,6 +88,7 @@ fun PostNodeHeader(
8588
score = postView.counts.score,
8689
myVote = postView.my_vote,
8790
published = postView.post.published,
91+
updated = postView.post.updated,
8892
onPersonClick = onPersonClick,
8993
isPostCreator = true,
9094
isModerator = isModerator,

app/src/main/java/com/jerboa/ui/components/private_message/PrivateMessage.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ fun PrivateMessageHeader(
5858
)
5959
}
6060

61-
TimeAgo(dateStr = privateMessageView.private_message.published)
61+
TimeAgo(
62+
published = privateMessageView.private_message.published,
63+
updated = privateMessageView.private_message.updated,
64+
)
6265
}
6366
}
6467

0 commit comments

Comments
 (0)