diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/BlogPostView.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/BlogPostView.kt index ecbaf9658dda1d41329cb3167cd2bbf2e27eedc2..ca402d880a69f8c8ef5682632b0a181f3eecdfec 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/BlogPostView.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/BlogPostView.kt @@ -62,6 +62,7 @@ import org.briarproject.briar.api.blog.MessageType import org.briarproject.briar.api.identity.AuthorInfo import org.briarproject.briar.api.identity.AuthorInfo.Status.OURSELVES import org.briarproject.briar.desktop.contact.ProfileCircle +import org.briarproject.briar.desktop.contact.ProfileCircleRss import org.briarproject.briar.desktop.theme.Blue500 import org.briarproject.briar.desktop.ui.AuthorView import org.briarproject.briar.desktop.ui.HorizontalDivider @@ -87,14 +88,14 @@ fun main() = preview { ) BlogPostView(post, {}, {}) val commentPost = getRandomBlogCommentItem( - post = post, + parent = post, comment = "This is a comment on that first blog post.\n\nIt has two lines as well.", time = System.currentTimeMillis() - 500_000 ) BlogPostView(commentPost, {}, {}) BlogPostView( getRandomBlogCommentItem( - post = commentPost, + parent = commentPost, comment = "This is a second comment on that first blog post. It has only one line, but a long one.", time = System.currentTimeMillis() ), @@ -175,11 +176,19 @@ private fun BlogPostViewHeader( if (item is BlogCommentItem) { val postHeader = item.postHeader // This isn't clickable, because item.type is WRAPPED_POST, so not easy to get the GroupId of the blog - AuthorView( - author = postHeader.author, - authorInfo = postHeader.authorInfo, - timestamp = postHeader.timestamp, - ) + if (postHeader.isRssFeed) { + // todo: currently only re-blogged RSS feeds are supported + RssAuthorView( + name = postHeader.author.name, + timestamp = postHeader.timestamp, + ) + } else { + AuthorView( + author = postHeader.author, + authorInfo = postHeader.authorInfo, + timestamp = postHeader.timestamp, + ) + } } } if (onItemRepeat != null) IconButton(onClick = { onItemRepeat(item) }) { @@ -251,6 +260,37 @@ private fun RepeatAuthorView( } } +@Composable +private fun RssAuthorView( + name: String, + timestamp: Long, +) { + Row( + horizontalArrangement = spacedBy(8.dp), + verticalAlignment = CenterVertically, + ) { + Row( + modifier = Modifier.weight(1f), + horizontalArrangement = spacedBy(8.dp), + verticalAlignment = CenterVertically, + ) { + ProfileCircleRss(27.dp) + Text( + modifier = Modifier.weight(1f, fill = false), + text = name, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } + Text( + text = getFormattedTimestamp(timestamp), + textAlign = TextAlign.End, + style = MaterialTheme.typography.caption, + maxLines = 1, + ) + } +} + internal fun getRandomBlogPostItem(text: String, time: Long) = BlogPostItem( header = BlogPostHeader( MessageType.POST, @@ -284,12 +324,12 @@ private fun BlogCommentView(header: BlogCommentHeader, modifier: Modifier = Modi } } -internal fun getRandomBlogCommentItem(post: BlogPost, comment: String?, time: Long) = BlogCommentItem( +internal fun getRandomBlogCommentItem(parent: BlogPost, comment: String?, time: Long) = BlogCommentItem( header = BlogCommentHeader( MessageType.COMMENT, GroupId(getRandomId()), comment, - if (post is BlogCommentItem) post.header else post.postHeader, + parent.header, MessageId(getRandomId()), time, System.currentTimeMillis(), @@ -297,8 +337,8 @@ internal fun getRandomBlogCommentItem(post: BlogPost, comment: String?, time: Lo AuthorInfo(AuthorInfo.Status.values().filter { it != AuthorInfo.Status.NONE }.random()), Random.nextBoolean(), ), - postHeader = post.postHeader, - text = comment, + postHeader = parent.postHeader, + text = parent.text, ) internal fun getRandomBlogPost(text: String, time: Long): BlogPost { diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/contact/ProfileCircle.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/contact/ProfileCircle.kt index 13732ba0cb4fac620123a41f81d2d5196f999f62..7c8233a99323b6bc76956cb2bea227c1af18811d 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/contact/ProfileCircle.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/contact/ProfileCircle.kt @@ -1,6 +1,6 @@ /* * Briar Desktop - * Copyright (C) 2021-2022 The Briar Project + * Copyright (C) 2021-2023 The Briar Project * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -20,15 +20,20 @@ package org.briarproject.briar.desktop.contact import androidx.compose.foundation.Canvas import androidx.compose.foundation.Image +import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.Icon import androidx.compose.material.MaterialTheme +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.RssFeed import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.Dp @@ -49,6 +54,8 @@ fun main() = preview { ProfileCircle(90.dp, bytes) ProfileCircle(90.dp) + + ProfileCircleRss(90.dp) } /** @@ -131,3 +138,21 @@ fun ProfileCircle(size: Dp, modifier: Modifier = Modifier) { drawLine(color, Offset(center, center), Offset(size * 0.7f, size * 0.7f), width) } } + +/** + * Display an RSS avatar for RSS feeds. + * + * @param size the size of the circle. + */ +@Composable +fun ProfileCircleRss(size: Dp) { + val modifier = Modifier.size(size).clip(CircleShape) + .border(1.dp, MaterialTheme.colors.outline, CircleShape) + .background(Color(0xfffc9403)) + Icon( + imageVector = Icons.Default.RssFeed, + contentDescription = null, + tint = Color.White, + modifier = modifier, + ) +}