Skip to content

Commit

Permalink
Repost Notifications UI (#376)
Browse files Browse the repository at this point in the history
- Adding a UI for repost notifications
- Adding a no-op implementation of `NotificationInteractions` for use
with compose previews
- I want to start doing this instead of having default `Unit` values for
interface functions
- Adding a post preview state for `PostContentUiState`

---------

Co-authored-by: John Oberhauser <j.git-global@obez.io>
  • Loading branch information
JohnOberhauser and John Oberhauser committed Jan 17, 2024
1 parent a725044 commit 627b4eb
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ fun Notification.toUiState(
title = StringFactory.resource(resId = R.string.repost_title, account.displayName),
avatarUrl = account.avatarUrl,
accountId = account.accountId,
postContentUiState = status.toPostContentUiState(
currentUserAccountId = currentUserAccountId,
contentWarningOverride = "",
onlyShowPreviewOfText = true,
),
statusId = status.statusId,
)
is Notification.Follow -> NotificationUiState.Follow(
id = id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.mozilla.social.core.ui.notifications.cards.FollowRequestNotification
import org.mozilla.social.core.ui.notifications.cards.MentionNotificationContent
import org.mozilla.social.core.ui.notifications.cards.NewStatusNotification
import org.mozilla.social.core.ui.notifications.cards.PollEndedNotification
import org.mozilla.social.core.ui.notifications.cards.RepostNotification
import org.mozilla.social.core.ui.notifications.cards.RepostNotificationContent
import org.mozilla.social.core.ui.notifications.cards.StatusUpdatedNotification
import org.mozilla.social.core.ui.poll.PollInteractions

Expand All @@ -51,6 +51,9 @@ fun NotificationCard(
is NotificationUiState.Follow -> FollowNotification(uiState = uiState)
is NotificationUiState.FollowRequest -> FollowRequestNotification(uiState = uiState)
is NotificationUiState.Mention -> NotificationCard(
modifier = Modifier.clickable {
notificationInteractions.onMentionClicked(uiState.statusId)
},
uiState = uiState,
notificationInteractions = notificationInteractions,
notificationTypeIcon = MoSoIcons.at(),
Expand All @@ -64,7 +67,20 @@ fun NotificationCard(

is NotificationUiState.NewStatus -> NewStatusNotification(uiState = uiState)
is NotificationUiState.PollEnded -> PollEndedNotification(uiState = uiState)
is NotificationUiState.Repost -> RepostNotification(uiState = uiState)
is NotificationUiState.Repost -> NotificationCard(
modifier = Modifier.clickable {
notificationInteractions.onRepostClicked(uiState.statusId)
},
uiState = uiState,
notificationInteractions = notificationInteractions,
notificationTypeIcon = MoSoIcons.boost(),
) {
RepostNotificationContent(
uiState = uiState,
htmlContentInteractions = htmlContentInteractions,
pollInteractions = pollInteractions
)
}
is NotificationUiState.StatusUpdated -> StatusUpdatedNotification(uiState = uiState)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ class NotificationCardDelegate(
override fun onMentionClicked(statusId: String) {
navigateTo(NavigationDestination.Thread(statusId))
}

override fun onRepostClicked(statusId: String) {
navigateTo(NavigationDestination.Thread(statusId))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ package org.mozilla.social.core.ui.notifications
interface NotificationInteractions {
fun onAvatarClicked(accountId: String)
fun onMentionClicked(statusId: String)
fun onRepostClicked(statusId: String)
}

object NotificationInteractionsNoOp : NotificationInteractions {
override fun onAvatarClicked(accountId: String) = Unit
override fun onMentionClicked(statusId: String) = Unit
override fun onRepostClicked(statusId: String) = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ sealed class NotificationUiState {
override val avatarUrl: String,
override val timeStamp: StringFactory,
override val accountId: String,
val postContentUiState: PostContentUiState,
val statusId: String,
): NotificationUiState()

data class Follow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.mozilla.social.core.ui.common.utils.PreviewTheme
import org.mozilla.social.core.ui.htmlcontent.HtmlContentInteractions
import org.mozilla.social.core.ui.notifications.NotificationCard
import org.mozilla.social.core.ui.notifications.NotificationInteractions
import org.mozilla.social.core.ui.notifications.NotificationInteractionsNoOp
import org.mozilla.social.core.ui.notifications.NotificationUiState
import org.mozilla.social.core.ui.poll.PollInteractions
import org.mozilla.social.core.ui.postcard.PostContent
Expand Down Expand Up @@ -48,10 +49,7 @@ private fun MentionNotificationPreview() {
),
htmlContentInteractions = object : HtmlContentInteractions {},
pollInteractions = object : PollInteractions {},
notificationInteractions = object : NotificationInteractions {
override fun onAvatarClicked(accountId: String) = Unit
override fun onMentionClicked(statusId: String) = Unit
},
notificationInteractions = NotificationInteractionsNoOp,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
package org.mozilla.social.core.ui.notifications.cards

import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.tooling.preview.Preview
import org.mozilla.social.common.utils.StringFactory
import org.mozilla.social.core.ui.common.utils.PreviewTheme
import org.mozilla.social.core.ui.htmlcontent.HtmlContentInteractions
import org.mozilla.social.core.ui.notifications.NotificationCard
import org.mozilla.social.core.ui.notifications.NotificationInteractionsNoOp
import org.mozilla.social.core.ui.notifications.NotificationUiState
import org.mozilla.social.core.ui.poll.PollInteractions
import org.mozilla.social.core.ui.postcard.PostContent
import org.mozilla.social.core.ui.postcard.PostContentUiState

@Composable
fun RepostNotification(
uiState: NotificationUiState.Repost
internal fun RepostNotificationContent(
uiState: NotificationUiState.Repost,
htmlContentInteractions: HtmlContentInteractions,
pollInteractions: PollInteractions,
) {
Text(
modifier = Modifier.padding(8.dp),
text = "Repost ${uiState.id}"
PostContent(
uiState = uiState.postContentUiState,
htmlContentInteractions = htmlContentInteractions,
pollInteractions = pollInteractions,
)
}

@Preview
@Composable
private fun RepostNotificationPreview() {
PreviewTheme {
NotificationCard(
uiState = NotificationUiState.Repost(
id = 1,
timeStamp = StringFactory.literal("1 day ago"),
title = StringFactory.literal("John mentioned you:"),
avatarUrl = "",
postContentUiState = PostContentUiState(
pollUiState = null,
statusTextHtml = "this is a status",
mediaAttachments = emptyList(),
mentions = emptyList(),
previewCard = null,
contentWarning = "",
),
accountId = "",
statusId = "",
),
htmlContentInteractions = object : HtmlContentInteractions {},
pollInteractions = object : PollInteractions {},
notificationInteractions = NotificationInteractionsNoOp,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ fun PostContent(
mentions = uiState.mentions,
htmlText = uiState.statusTextHtml,
htmlContentInteractions = htmlContentInteractions,
maximumLineCount = if (uiState.onlyShowPreviewOfText) {
1
} else {
Int.MAX_VALUE
},
textColor = if (uiState.onlyShowPreviewOfText) {
MoSoTheme.colors.textSecondary
} else {
MoSoTheme.colors.textPrimary
}
)
Spacer(modifier = Modifier.padding(top = 8.dp))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ private fun Status.toMainPostCardUiState(currentUserAccountId: String): MainPost
postContentUiState = toPostContentUiState(currentUserAccountId)
)

fun Status.toPostContentUiState(currentUserAccountId: String): PostContentUiState = PostContentUiState(
fun Status.toPostContentUiState(
currentUserAccountId: String,
contentWarningOverride: String? = null,
onlyShowPreviewOfText: Boolean = false,
): PostContentUiState = PostContentUiState(
pollUiState = poll?.toPollUiState(
isUserCreatedPoll = currentUserAccountId == account.accountId,
),
statusTextHtml = content,
mediaAttachments = mediaAttachments,
mentions = mentions,
previewCard = card?.toPreviewCard(),
contentWarning = contentWarningText,
contentWarning = contentWarningOverride ?: contentWarningText,
onlyShowPreviewOfText = onlyShowPreviewOfText,
)

private fun Status.toTopRowMetaDataUiState(): TopRowMetaDataUiState? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data class PostContentUiState(
val mentions: List<Mention>,
val previewCard: PreviewCard?,
val contentWarning: String,
val onlyShowPreviewOfText: Boolean = false,
)

data class TopRowMetaDataUiState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.mozilla.social.core.ui.common.utils.PreviewTheme
import org.mozilla.social.core.ui.htmlcontent.HtmlContentInteractions
import org.mozilla.social.core.ui.notifications.NotificationCard
import org.mozilla.social.core.ui.notifications.NotificationInteractions
import org.mozilla.social.core.ui.notifications.NotificationInteractionsNoOp
import org.mozilla.social.core.ui.notifications.NotificationUiState
import org.mozilla.social.core.ui.poll.PollInteractions

Expand Down Expand Up @@ -167,10 +168,7 @@ private fun NotificationsScreenPreview() {
},
pollInteractions = object : PollInteractions {},
htmlContentInteractions = object : HtmlContentInteractions {},
notificationInteractions = object : NotificationInteractions {
override fun onAvatarClicked(accountId: String) = Unit
override fun onMentionClicked(statusId: String) = Unit
},
notificationInteractions = NotificationInteractionsNoOp,
)
}
}

0 comments on commit 627b4eb

Please sign in to comment.