kopia lustrzana https://github.com/vitorpamplona/amethyst
add PollNote to ui.note,
simplify code for displaying PollNoteEvents with replyTos or mentions, fix pollOptions (and other poll fields) get from tags functionspull/283/head
rodzic
d1f61c0bba
commit
771cdd6ebe
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue