Skip to content

Commit

Permalink
Adding ui for favorite notifications (#381)
Browse files Browse the repository at this point in the history
- Adding UI for favorite notifications

Co-authored-by: John Oberhauser <j.git-global@obez.io>
  • Loading branch information
JohnOberhauser and John Oberhauser committed Jan 18, 2024
1 parent 5ce07c8 commit d2223b7
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ fun Notification.toUiState(
avatarUrl = account.avatarUrl,
accountId = account.accountId,
accountName = account.displayName,
postContentUiState = status.toPostContentUiState(
currentUserAccountId = currentUserAccountId,
contentWarningOverride = "",
onlyShowPreviewOfText = true,
),
statusId = status.statusId,
)
is Notification.PollEnded -> NotificationUiState.PollEnded(
id = id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.mozilla.social.core.designsystem.utils.NoRipple
import org.mozilla.social.core.ui.common.text.MediumTextLabel
import org.mozilla.social.core.ui.common.text.SmallTextLabel
import org.mozilla.social.core.ui.htmlcontent.HtmlContentInteractions
import org.mozilla.social.core.ui.notifications.cards.FavoriteNotification
import org.mozilla.social.core.ui.notifications.cards.FavoriteNotificationContent
import org.mozilla.social.core.ui.notifications.cards.FollowNotification
import org.mozilla.social.core.ui.notifications.cards.FollowRequestNotification
import org.mozilla.social.core.ui.notifications.cards.MentionNotificationContent
Expand All @@ -49,7 +49,20 @@ fun NotificationCard(
) {
Box(modifier = modifier) {
when (uiState) {
is NotificationUiState.Favorite -> FavoriteNotification(uiState = uiState)
is NotificationUiState.Favorite -> NotificationCard(
modifier = Modifier.clickable {
notificationInteractions.onFavoritedCardClicked(uiState.statusId)
},
uiState = uiState,
notificationInteractions = notificationInteractions,
notificationTypeIcon = MoSoIcons.heart(),
) {
FavoriteNotificationContent(
uiState = uiState,
htmlContentInteractions = htmlContentInteractions,
pollInteractions = pollInteractions,
)
}
is NotificationUiState.Follow -> FollowNotification(uiState = uiState)
is NotificationUiState.FollowRequest -> FollowRequestNotification(uiState = uiState)
is NotificationUiState.Mention -> NotificationCard(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ class NotificationCardDelegate(
override fun onNewStatusClicked(statusId: String) {
navigateTo(NavigationDestination.Thread(statusId))
}

override fun onFavoritedCardClicked(statusId: String) {
navigateTo(NavigationDestination.Thread(statusId))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface NotificationInteractions {
fun onPollEndedClicked(statusId: String)
fun onStatusUpdatedCardClicked(statusId: String)
fun onNewStatusClicked(statusId: String)
fun onFavoritedCardClicked(statusId: String)
}

object NotificationInteractionsNoOp : NotificationInteractions {
Expand All @@ -16,4 +17,5 @@ object NotificationInteractionsNoOp : NotificationInteractions {
override fun onPollEndedClicked(statusId: String) = Unit
override fun onStatusUpdatedCardClicked(statusId: String) = Unit
override fun onNewStatusClicked(statusId: String) = Unit
override fun onFavoritedCardClicked(statusId: String) = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ sealed class NotificationUiState {
override val timeStamp: StringFactory,
override val accountId: String,
override val accountName: String,
val postContentUiState: PostContentUiState,
val statusId: String,
): NotificationUiState()

data class PollEnded(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,55 @@
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 FavoriteNotification(
uiState: NotificationUiState.Favorite
internal fun FavoriteNotificationContent(
uiState: NotificationUiState.Favorite,
htmlContentInteractions: HtmlContentInteractions,
pollInteractions: PollInteractions,
) {
Text(
modifier = Modifier.padding(8.dp),
text = "Favorite ${uiState.id}"
PostContent(
uiState = uiState.postContentUiState,
htmlContentInteractions = htmlContentInteractions,
pollInteractions = pollInteractions,
)
}
}

@Preview
@Composable
private fun FavoriteNotificationPreview() {
PreviewTheme {
NotificationCard(
uiState = NotificationUiState.Favorite(
id = 1,
timeStamp = StringFactory.literal("1 day ago"),
title = StringFactory.literal("John favorited your post:"),
avatarUrl = "",
postContentUiState = PostContentUiState(
pollUiState = null,
statusTextHtml = "this is a status",
mediaAttachments = emptyList(),
mentions = emptyList(),
previewCard = null,
contentWarning = "",
),
accountId = "",
statusId = "",
accountName = "",
),
htmlContentInteractions = object : HtmlContentInteractions {},
pollInteractions = object : PollInteractions {},
notificationInteractions = NotificationInteractionsNoOp,
)
}
}

0 comments on commit d2223b7

Please sign in to comment.