mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-20 18:21:12 +02:00
fix isPollOptionZappedBy fun,
option zap widgets layout improvements
This commit is contained in:
@@ -203,6 +203,20 @@ open class Note(val idHex: String) {
|
|||||||
return zaps.any { it.key.author == user }
|
return zaps.any { it.key.author == user }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isPollOptionZappedBy(option: Int, user: User): Boolean {
|
||||||
|
if (zaps.any { it.key.author == user }) {
|
||||||
|
zaps.mapNotNull { it.value?.event }
|
||||||
|
.filterIsInstance<LnZapEvent>()
|
||||||
|
.map {
|
||||||
|
val zappedOption = it.zappedPollOption()
|
||||||
|
if (zappedOption == option) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fun isReactedBy(user: User): Boolean {
|
fun isReactedBy(user: User): Boolean {
|
||||||
return reactions.any { it.author == user }
|
return reactions.any { it.author == user }
|
||||||
}
|
}
|
||||||
@@ -248,10 +262,6 @@ open class Note(val idHex: String) {
|
|||||||
}.sumOf { it }
|
}.sumOf { it }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isPollOptionZapped(option: Int): Boolean {
|
|
||||||
return zappedPollOptionAmount(option).toInt() > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hasAnyReports(): Boolean {
|
fun hasAnyReports(): Boolean {
|
||||||
val dayAgo = Date().time / 1000 - 24 * 60 * 60
|
val dayAgo = Date().time / 1000 - 24 * 60 * 60
|
||||||
return reports.isNotEmpty() ||
|
return reports.isNotEmpty() ||
|
||||||
|
@@ -14,6 +14,7 @@ import androidx.compose.material.ripple.rememberRipple
|
|||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
@@ -47,16 +48,17 @@ fun PollNote(
|
|||||||
val consensusThreshold = pollEvent.consensusThreshold()
|
val consensusThreshold = pollEvent.consensusThreshold()
|
||||||
|
|
||||||
pollEvent.pollOptions().forEach { poll_op ->
|
pollEvent.pollOptions().forEach { poll_op ->
|
||||||
Row(Modifier.fillMaxWidth()) {
|
Row(
|
||||||
val modifier = Modifier
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
.weight(1f)
|
modifier = Modifier.fillMaxWidth()
|
||||||
.border(BorderStroke(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.32f)))
|
) {
|
||||||
.padding(4.dp)
|
|
||||||
|
|
||||||
TranslateableRichTextViewer(
|
TranslateableRichTextViewer(
|
||||||
poll_op.value,
|
poll_op.value,
|
||||||
canPreview,
|
canPreview,
|
||||||
modifier,
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.border(BorderStroke(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.32f)))
|
||||||
|
.padding(4.dp),
|
||||||
pollEvent.tags(),
|
pollEvent.tags(),
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
@@ -97,6 +99,7 @@ fun ZapVote(
|
|||||||
val isVoteAmountAtomic = valueMaximum != null && valueMinimum != null && valueMinimum == valueMaximum
|
val isVoteAmountAtomic = valueMaximum != null && valueMinimum != null && valueMinimum == valueMaximum
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.then(Modifier.size(20.dp))
|
.then(Modifier.size(20.dp))
|
||||||
.combinedClickable(
|
.combinedClickable(
|
||||||
@@ -163,7 +166,7 @@ fun ZapVote(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zappedNote?.isPollOptionZapped(pollOption) == true) {
|
if (zappedNote?.isPollOptionZappedBy(pollOption, account.userProfile()) == true) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.Bolt,
|
imageVector = Icons.Default.Bolt,
|
||||||
contentDescription = stringResource(R.string.zaps),
|
contentDescription = stringResource(R.string.zaps),
|
||||||
@@ -188,7 +191,7 @@ fun ZapVote(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ZapVoteAmountChoicePopup(
|
fun ZapVoteAmountChoicePopup(
|
||||||
baseNote: Note,
|
baseNote: Note,
|
||||||
@@ -259,8 +262,8 @@ fun ZapVoteAmountChoicePopup(
|
|||||||
Surface {
|
Surface {
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(MaterialTheme.colors.primary)
|
|
||||||
.padding(10.dp)
|
.padding(10.dp)
|
||||||
) {
|
) {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
@@ -283,10 +286,11 @@ fun ZapVoteAmountChoicePopup(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (amount != null && isValidAmount) {
|
Button(
|
||||||
Button(
|
modifier = Modifier.padding(horizontal = 3.dp),
|
||||||
modifier = Modifier.padding(horizontal = 3.dp),
|
enabled = isValidAmount,
|
||||||
onClick = {
|
onClick = {
|
||||||
|
if (amount != null) {
|
||||||
accountViewModel.zap(
|
accountViewModel.zap(
|
||||||
baseNote,
|
baseNote,
|
||||||
amount * 1000,
|
amount * 1000,
|
||||||
@@ -295,20 +299,22 @@ fun ZapVoteAmountChoicePopup(
|
|||||||
context,
|
context,
|
||||||
onError
|
onError
|
||||||
)
|
)
|
||||||
onDismiss()
|
}
|
||||||
},
|
onDismiss()
|
||||||
shape = RoundedCornerShape(20.dp),
|
},
|
||||||
colors = ButtonDefaults
|
shape = RoundedCornerShape(20.dp),
|
||||||
.buttonColors(
|
colors = ButtonDefaults
|
||||||
backgroundColor = MaterialTheme.colors.primary
|
.buttonColors(
|
||||||
)
|
backgroundColor = MaterialTheme.colors.primary
|
||||||
) {
|
)
|
||||||
Text(
|
) {
|
||||||
"⚡ ${showAmount(amount.toBigDecimal().setScale(1))}",
|
Text(
|
||||||
color = Color.White,
|
"⚡ ${showAmount(amount?.toBigDecimal()?.setScale(1))}",
|
||||||
textAlign = TextAlign.Center,
|
color = Color.White,
|
||||||
modifier = Modifier.combinedClickable(
|
textAlign = TextAlign.Center,
|
||||||
onClick = {
|
modifier = Modifier.combinedClickable(
|
||||||
|
onClick = {
|
||||||
|
if (amount != null) {
|
||||||
accountViewModel.zap(
|
accountViewModel.zap(
|
||||||
baseNote,
|
baseNote,
|
||||||
amount * 1000,
|
amount * 1000,
|
||||||
@@ -317,12 +323,12 @@ fun ZapVoteAmountChoicePopup(
|
|||||||
context,
|
context,
|
||||||
onError
|
onError
|
||||||
)
|
)
|
||||||
onDismiss()
|
}
|
||||||
},
|
onDismiss()
|
||||||
onLongClick = {}
|
},
|
||||||
)
|
onLongClick = {}
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user