color option progress bar green when consensus achieved,
add padding to option text
This commit is contained in:
@@ -47,6 +47,8 @@ fun PollNote(
|
||||
pollViewModel.load(note)
|
||||
|
||||
pollViewModel.pollEvent?.pollOptions()?.forEach { poll_op ->
|
||||
val optionTally = pollViewModel.optionVoteTally(poll_op.key)
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
@@ -55,7 +57,9 @@ fun PollNote(
|
||||
canPreview,
|
||||
modifier = Modifier
|
||||
.width(250.dp)
|
||||
.border(BorderStroke(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.32f))),
|
||||
.padding(0.dp) // padding outside border
|
||||
.border(BorderStroke(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.32f)))
|
||||
.padding(4.dp), // padding between border and text
|
||||
pollViewModel.pollEvent?.tags(),
|
||||
backgroundColor,
|
||||
accountViewModel,
|
||||
@@ -72,7 +76,13 @@ fun PollNote(
|
||||
if (note.isZappedBy(accountViewModel.userProfile())) {
|
||||
LinearProgressIndicator(
|
||||
modifier = Modifier.width(250.dp),
|
||||
progress = pollViewModel.optionVoteTally(poll_op.key)
|
||||
color = if (
|
||||
pollViewModel.consensusThreshold != null &&
|
||||
optionTally >= pollViewModel.consensusThreshold!!
|
||||
) {
|
||||
Color.Green
|
||||
} else { MaterialTheme.colors.primary },
|
||||
progress = optionTally
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -128,7 +138,7 @@ fun ZapVote(
|
||||
)
|
||||
.show()
|
||||
}
|
||||
} else if (pollViewModel.isVoteAmountAtomic()) {
|
||||
} else if (pollViewModel.isVoteAmountAtomic) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
pollViewModel.valueMaximum!!.toLong() * 1000,
|
||||
@@ -231,14 +241,14 @@ fun ZapVoteAmountChoicePopup(
|
||||
modifier = Modifier
|
||||
.padding(10.dp)
|
||||
) {
|
||||
val amount = pollViewModel.inputAmountLong(inputAmountText)
|
||||
val amount = pollViewModel.inputVoteAmountLong(inputAmountText)
|
||||
|
||||
OutlinedTextField(
|
||||
value = inputAmountText,
|
||||
onValueChange = { inputAmountText = it },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
||||
modifier = Modifier.width(150.dp),
|
||||
colors = if (pollViewModel.isValidInputAmount(amount)) colorValid else colorInValid,
|
||||
colors = if (pollViewModel.isValidInputVoteAmount(amount)) colorValid else colorInValid,
|
||||
label = {
|
||||
Text(
|
||||
text = stringResource(R.string.poll_zap_amount),
|
||||
@@ -255,7 +265,7 @@ fun ZapVoteAmountChoicePopup(
|
||||
|
||||
Button(
|
||||
modifier = Modifier.padding(horizontal = 3.dp),
|
||||
enabled = pollViewModel.isValidInputAmount(amount),
|
||||
enabled = pollViewModel.isValidInputVoteAmount(amount),
|
||||
onClick = {
|
||||
if (amount != null) {
|
||||
accountViewModel.zap(
|
||||
|
||||
@@ -16,7 +16,7 @@ class PollNoteViewModel {
|
||||
var valueMaximum: Int? = null
|
||||
private var valueMinimum: Int? = null
|
||||
private var closedAt: Int? = null
|
||||
private var consensusThreshold: Int? = null
|
||||
var consensusThreshold: Float? = null
|
||||
|
||||
fun load(note: Note?) {
|
||||
pollNote = note
|
||||
@@ -24,7 +24,7 @@ class PollNoteViewModel {
|
||||
pollOptions = pollEvent?.pollOptions()
|
||||
valueMaximum = pollEvent?.getTagInt(VALUE_MAXIMUM)
|
||||
valueMinimum = pollEvent?.getTagInt(VALUE_MINIMUM)
|
||||
consensusThreshold = pollEvent?.getTagInt(CONSENSUS_THRESHOLD)
|
||||
consensusThreshold = pollEvent?.getTagInt(CONSENSUS_THRESHOLD)?.toFloat()?.div(100)
|
||||
closedAt = pollEvent?.getTagInt(CLOSED_AT)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class PollNoteViewModel {
|
||||
pollNote?.createdAt()?.plus(it * (86400 + 120))!! > Date().time / 1000
|
||||
} == true
|
||||
|
||||
fun isVoteAmountAtomic(): Boolean = valueMaximum != null && valueMinimum != null && valueMinimum == valueMaximum
|
||||
val isVoteAmountAtomic = valueMaximum != null && valueMinimum != null && valueMinimum == valueMaximum
|
||||
|
||||
fun voteAmountPlaceHolderText(sats: String): String = if (valueMinimum == null && valueMaximum == null) {
|
||||
sats
|
||||
@@ -44,13 +44,13 @@ class PollNoteViewModel {
|
||||
"$valueMinimum—$valueMaximum $sats"
|
||||
}
|
||||
|
||||
fun inputAmountLong(textAmount: String) = if (textAmount.isEmpty()) { null } else {
|
||||
fun inputVoteAmountLong(textAmount: String) = if (textAmount.isEmpty()) { null } else {
|
||||
try {
|
||||
textAmount.toLong()
|
||||
} catch (e: Exception) { null }
|
||||
}
|
||||
|
||||
fun isValidInputAmount(amount: Long?): Boolean {
|
||||
fun isValidInputVoteAmount(amount: Long?): Boolean {
|
||||
if (amount == null) {
|
||||
return false
|
||||
} else if (valueMinimum == null && valueMaximum == null) {
|
||||
@@ -83,7 +83,7 @@ class PollNoteViewModel {
|
||||
private fun zappedVoteTotal(): Float {
|
||||
var total = 0f
|
||||
pollOptions?.keys?.forEach {
|
||||
total += zappedPollOptionAmount(it).toFloat() ?: 0f
|
||||
total += zappedPollOptionAmount(it).toFloat()
|
||||
}
|
||||
return total
|
||||
}
|
||||
@@ -103,8 +103,8 @@ class PollNoteViewModel {
|
||||
}
|
||||
|
||||
fun zappedPollOptionAmount(option: Int): BigDecimal {
|
||||
if (pollNote != null) {
|
||||
return pollNote!!.zaps.mapNotNull { it.value?.event }
|
||||
return if (pollNote != null) {
|
||||
pollNote!!.zaps.mapNotNull { it.value?.event }
|
||||
.filterIsInstance<LnZapEvent>()
|
||||
.mapNotNull {
|
||||
val zappedOption = it.zappedPollOption()
|
||||
@@ -112,6 +112,8 @@ class PollNoteViewModel {
|
||||
it.amount
|
||||
} else { null }
|
||||
}.sumOf { it }
|
||||
} else { return BigDecimal(0) }
|
||||
} else {
|
||||
BigDecimal(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user