diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/model/PollNoteEvent.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/model/PollNoteEvent.kt index db0608076..32e7e59c1 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/model/PollNoteEvent.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/model/PollNoteEvent.kt @@ -31,11 +31,19 @@ class PollNoteEvent( fun replyTos() = tags.filter { it.firstOrNull() == "e" }.mapNotNull { it.getOrNull(1) } - fun pollOptions() = tags.filter { it.firstOrNull() == POLL_OPTIONS }.mapNotNull { it.getOrNull(1) } - fun valueMaximum() = tags.filter { it.firstOrNull() == VALUE_MAXIMUM }.mapNotNull { it.getOrNull(1) } - fun valueMinimum() = tags.filter { it.firstOrNull() == VALUE_MINIMUM }.mapNotNull { it.getOrNull(1) } - fun consensusThreshold() = tags.filter { it.firstOrNull() == CONSENSUS_THRESHOLD }.mapNotNull { it.getOrNull(1) } - fun closedAt() = tags.filter { it.firstOrNull() == CLOSED_AT }.mapNotNull { it.getOrNull(1) } + fun pollOptions() = jsonToPollOptions(tags.filter { it.firstOrNull() == POLL_OPTIONS }[0][1]) + fun valueMaximum() = tags.filter { it.firstOrNull() == VALUE_MAXIMUM }.mapNotNull { + it.getOrNull(1)?.get(1) + } + fun valueMinimum() = tags.filter { it.firstOrNull() == VALUE_MINIMUM }.mapNotNull { + it.getOrNull(1)?.get(1) + } + fun consensusThreshold() = tags.filter { it.firstOrNull() == CONSENSUS_THRESHOLD }.mapNotNull { + it.getOrNull(1)?.get(1) + } + fun closedAt() = tags.filter { it.firstOrNull() == CLOSED_AT }.mapNotNull { + it.getOrNull(1)?.get(1) + } companion object { const val kind = 6969 diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt index c006f2cac..6806c7bd0 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt @@ -282,7 +282,7 @@ fun NoteCompose( Spacer(modifier = Modifier.height(3.dp)) - if (noteEvent is TextNoteEvent && (note.replyTo != null || note.mentions != null)) { + if ((noteEvent is TextNoteEvent || noteEvent is PollNoteEvent) && (note.replyTo != null || note.mentions != null)) { val replyingDirectlyTo = note.replyTo?.lastOrNull() if (replyingDirectlyTo != null && unPackReply) { NoteCompose( @@ -314,31 +314,6 @@ fun NoteCompose( } } - if (noteEvent is PollNoteEvent && (note.replyTo != null || note.mentions != null)) { - val replyingDirectlyTo = note.replyTo?.lastOrNull() - if (replyingDirectlyTo != null && unPackReply) { - NoteCompose( - baseNote = replyingDirectlyTo, - isQuotedNote = true, - modifier = Modifier - .padding(0.dp) - .fillMaxWidth() - .clip(shape = RoundedCornerShape(15.dp)) - .border( - 1.dp, - MaterialTheme.colors.onSurface.copy(alpha = 0.12f), - RoundedCornerShape(15.dp) - ), - unPackReply = false, - makeItShort = true, - parentBackgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.05f) - .compositeOver(backgroundColor), - accountViewModel = accountViewModel, - navController = navController - ) - } - } - if (noteEvent is ReactionEvent || noteEvent is RepostEvent) { note.replyTo?.lastOrNull()?.let { NoteCompose( @@ -469,6 +444,10 @@ fun NoteCompose( accountViewModel, navController ) + + if (noteEvent is PollNoteEvent) { + PollNote(noteEvent, canPreview, makeItShort, accountViewModel, navController) + } } if (!makeItShort) { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNote.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNote.kt new file mode 100644 index 000000000..5df027a2b --- /dev/null +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNote.kt @@ -0,0 +1,35 @@ +package com.vitorpamplona.amethyst.ui.note + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.MaterialTheme +import androidx.compose.material.SnackbarDefaults.backgroundColor +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.navigation.NavController +import com.vitorpamplona.amethyst.service.model.PollNoteEvent +import com.vitorpamplona.amethyst.ui.components.TranslateableRichTextViewer +import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel + +@Composable +fun PollNote( + pollEvent: PollNoteEvent, + canPreview: Boolean, + makeItShort: Boolean, + accountViewModel: AccountViewModel, + navController: NavController +) { + pollEvent.pollOptions().values.forEachIndexed { index, string -> + TranslateableRichTextViewer( + string, + canPreview = canPreview && !makeItShort, + Modifier.fillMaxWidth().border(BorderStroke(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.32f))), + pollEvent.tags(), + backgroundColor, + accountViewModel, + navController + ) + } +}