Fixes poll rendering with images are included in the options
This commit is contained in:
@@ -32,6 +32,7 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.ColumnScope
|
import androidx.compose.foundation.layout.ColumnScope
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.RowScope
|
import androidx.compose.foundation.layout.RowScope
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
@@ -83,6 +84,7 @@ import com.vitorpamplona.amethyst.ui.theme.Size25dp
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.SmallishBorder
|
import com.vitorpamplona.amethyst.ui.theme.SmallishBorder
|
||||||
import com.vitorpamplona.amethyst.ui.theme.SpacedBy10dp
|
import com.vitorpamplona.amethyst.ui.theme.SpacedBy10dp
|
||||||
import com.vitorpamplona.amethyst.ui.theme.SpacedBy5dp
|
import com.vitorpamplona.amethyst.ui.theme.SpacedBy5dp
|
||||||
|
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
||||||
import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn
|
import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn
|
||||||
import com.vitorpamplona.amethyst.ui.theme.allGoodColor
|
import com.vitorpamplona.amethyst.ui.theme.allGoodColor
|
||||||
import com.vitorpamplona.amethyst.ui.theme.grayText
|
import com.vitorpamplona.amethyst.ui.theme.grayText
|
||||||
@@ -176,7 +178,7 @@ fun InnerRenderPoll(
|
|||||||
content = label,
|
content = label,
|
||||||
canPreview = canPreview,
|
canPreview = canPreview,
|
||||||
quotesLeft = 1,
|
quotesLeft = 1,
|
||||||
modifier = Modifier,
|
modifier = Modifier.fillMaxWidth(),
|
||||||
tags = tags,
|
tags = tags,
|
||||||
backgroundColor = backgroundColor,
|
backgroundColor = backgroundColor,
|
||||||
id = note.idHex + code,
|
id = note.idHex + code,
|
||||||
@@ -218,7 +220,7 @@ fun RenderPollCard(
|
|||||||
pollState: PollResponsesCache,
|
pollState: PollResponsesCache,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
galleryUser: @Composable RowScope.(user: User) -> Unit,
|
galleryUser: @Composable RowScope.(user: User) -> Unit,
|
||||||
labelContent: @Composable RowScope.(code: String, label: String) -> Unit,
|
labelContent: @Composable ColumnScope.(code: String, label: String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val card =
|
val card =
|
||||||
remember(event) {
|
remember(event) {
|
||||||
@@ -271,7 +273,7 @@ fun RenderPollCard(
|
|||||||
card: PollCard,
|
card: PollCard,
|
||||||
onRespond: (Set<String>) -> Unit,
|
onRespond: (Set<String>) -> Unit,
|
||||||
resultContent: @Composable RowScope.(user: User) -> Unit,
|
resultContent: @Composable RowScope.(user: User) -> Unit,
|
||||||
labelContent: @Composable RowScope.(code: String, label: String) -> Unit,
|
labelContent: @Composable ColumnScope.(code: String, label: String) -> Unit,
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = SpacedBy5dp,
|
verticalArrangement = SpacedBy5dp,
|
||||||
@@ -303,7 +305,7 @@ fun RenderPollCard(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun ColumnScope.RenderSingleChoiceOptions(
|
private fun ColumnScope.RenderSingleChoiceOptions(
|
||||||
card: PollCard,
|
card: PollCard,
|
||||||
labelContent: @Composable (RowScope.(String, String) -> Unit),
|
labelContent: @Composable (ColumnScope.(String, String) -> Unit),
|
||||||
onRespond: (Set<String>) -> Unit,
|
onRespond: (Set<String>) -> Unit,
|
||||||
) {
|
) {
|
||||||
card.options.forEach {
|
card.options.forEach {
|
||||||
@@ -324,17 +326,23 @@ private fun ColumnScope.RenderSingleChoiceOptions(
|
|||||||
modifier = BigPadding,
|
modifier = BigPadding,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
) {
|
) {
|
||||||
labelContent(it.code, it.label)
|
labelContent(it.code, it.label)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ColumnScope.RenderMultiChoiceOptions(
|
private fun ColumnScope.RenderMultiChoiceOptions(
|
||||||
card: PollCard,
|
card: PollCard,
|
||||||
labelContent: @Composable (RowScope.(String, String) -> Unit),
|
labelContent: @Composable (ColumnScope.(String, String) -> Unit),
|
||||||
onRespond: (Set<String>) -> Unit,
|
onRespond: (Set<String>) -> Unit,
|
||||||
) {
|
) {
|
||||||
var multichoice by
|
var multichoice by
|
||||||
@@ -368,10 +376,14 @@ private fun ColumnScope.RenderMultiChoiceOptions(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
) {
|
||||||
labelContent(option.code, option.label)
|
labelContent(option.code, option.label)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
@@ -388,7 +400,7 @@ private fun ColumnScope.RenderMultiChoiceOptions(
|
|||||||
private fun RenderResults(
|
private fun RenderResults(
|
||||||
card: PollCard,
|
card: PollCard,
|
||||||
resultContent: @Composable RowScope.(user: User) -> Unit,
|
resultContent: @Composable RowScope.(user: User) -> Unit,
|
||||||
labelContent: @Composable (RowScope.(code: String, label: String) -> Unit),
|
labelContent: @Composable (ColumnScope.(code: String, label: String) -> Unit),
|
||||||
) {
|
) {
|
||||||
card.options.forEach { pollItem ->
|
card.options.forEach { pollItem ->
|
||||||
RenderClosedItem(pollItem, resultContent) {
|
RenderClosedItem(pollItem, resultContent) {
|
||||||
@@ -401,7 +413,7 @@ private fun RenderResults(
|
|||||||
private fun RenderClosedItem(
|
private fun RenderClosedItem(
|
||||||
item: PollItemCard,
|
item: PollItemCard,
|
||||||
resultContent: @Composable RowScope.(user: User) -> Unit,
|
resultContent: @Composable RowScope.(user: User) -> Unit,
|
||||||
labelContent: @Composable RowScope.() -> Unit,
|
labelContent: @Composable ColumnScope.() -> Unit,
|
||||||
) {
|
) {
|
||||||
val tally by item.results.collectAsStateWithLifecycle(item.currentResults())
|
val tally by item.results.collectAsStateWithLifecycle(item.currentResults())
|
||||||
|
|
||||||
@@ -412,7 +424,7 @@ private fun RenderClosedItem(
|
|||||||
private fun RenderClosedItem(
|
private fun RenderClosedItem(
|
||||||
tally: TallyResults,
|
tally: TallyResults,
|
||||||
resultContent: @Composable RowScope.(user: User) -> Unit,
|
resultContent: @Composable RowScope.(user: User) -> Unit,
|
||||||
labelContent: @Composable RowScope.() -> Unit,
|
labelContent: @Composable ColumnScope.() -> Unit,
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
@@ -463,7 +475,12 @@ private fun RenderClosedItem(
|
|||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
labelContent()
|
Column(
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
content = labelContent,
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(StdHorzSpacer)
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
@@ -475,6 +492,7 @@ private fun RenderClosedItem(
|
|||||||
text = "${(tally.percent * 100).toInt()}%",
|
text = "${(tally.percent * 100).toInt()}%",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
|
maxLines = 1,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -486,6 +504,7 @@ fun UserGallery(
|
|||||||
tally: TallyResults,
|
tally: TallyResults,
|
||||||
galleryUser: @Composable RowScope.(user: User) -> Unit,
|
galleryUser: @Composable RowScope.(user: User) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
if (tally.users.isNotEmpty()) {
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy((-10).dp),
|
horizontalArrangement = Arrangement.spacedBy((-10).dp),
|
||||||
@@ -514,6 +533,7 @@ fun UserGallery(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
@@ -557,7 +577,6 @@ fun RenderPollManualPreview() {
|
|||||||
RenderPollCard(poll, {}, {}) { _, label ->
|
RenderPollCard(poll, {}, {}) { _, label ->
|
||||||
Text(
|
Text(
|
||||||
text = label,
|
text = label,
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user