BugFixes for NPE

pull/459/head
Vitor Pamplona 2023-06-18 14:40:46 -04:00
rodzic be4870da1a
commit 58a4fb18ae
4 zmienionych plików z 21 dodań i 18 usunięć

Wyświetl plik

@ -284,9 +284,7 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(vertical = 5.dp)) { Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(vertical = 5.dp)) {
ZapRaiserRequest( ZapRaiserRequest(
stringResource(id = R.string.zapraiser), stringResource(id = R.string.zapraiser),
onSuccess = { postViewModel
postViewModel.zapRaiserAmount = it
}
) )
} }
} }

Wyświetl plik

@ -77,7 +77,7 @@ open class NewPostViewModel() : ViewModel() {
// ZapRaiser // ZapRaiser
var canAddZapRaiser by mutableStateOf(false) var canAddZapRaiser by mutableStateOf(false)
var wantsZapraiser by mutableStateOf(false) var wantsZapraiser by mutableStateOf(false)
var zapRaiserAmount by mutableStateOf(0L) var zapRaiserAmount by mutableStateOf<Long?>(null)
open fun load(account: Account, replyingTo: Note?, quote: Note?) { open fun load(account: Account, replyingTo: Note?, quote: Note?) {
originalNote = replyingTo originalNote = replyingTo
@ -117,6 +117,7 @@ open class NewPostViewModel() : ViewModel() {
wantsForwardZapTo = false wantsForwardZapTo = false
wantsToMarkAsSensitive = false wantsToMarkAsSensitive = false
wantsZapraiser = false wantsZapraiser = false
zapRaiserAmount = null
forwardZapTo = null forwardZapTo = null
forwardZapToEditting = TextFieldValue("") forwardZapToEditting = TextFieldValue("")
@ -137,12 +138,14 @@ open class NewPostViewModel() : ViewModel() {
null null
} }
val localZapRaiserAmount = if (wantsZapraiser) zapRaiserAmount else null
if (wantsPoll) { if (wantsPoll) {
account?.sendPoll(tagger.message, tagger.replyTos, tagger.mentions, pollOptions, valueMaximum, valueMinimum, consensusThreshold, closedAt, zapReceiver, wantsToMarkAsSensitive, zapRaiserAmount) account?.sendPoll(tagger.message, tagger.replyTos, tagger.mentions, pollOptions, valueMaximum, valueMinimum, consensusThreshold, closedAt, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount)
} else if (originalNote?.channelHex() != null) { } else if (originalNote?.channelHex() != null) {
account?.sendChannelMessage(tagger.message, tagger.channelHex!!, tagger.replyTos, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, zapRaiserAmount) account?.sendChannelMessage(tagger.message, tagger.channelHex!!, tagger.replyTos, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount)
} else if (originalNote?.event is PrivateDmEvent) { } else if (originalNote?.event is PrivateDmEvent) {
account?.sendPrivateMessage(tagger.message, originalNote!!.author!!, originalNote!!, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, zapRaiserAmount) account?.sendPrivateMessage(tagger.message, originalNote!!.author!!, originalNote!!, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount)
} else { } else {
// adds markers // adds markers
val rootId = val rootId =
@ -158,7 +161,7 @@ open class NewPostViewModel() : ViewModel() {
tags = null, tags = null,
zapReceiver = zapReceiver, zapReceiver = zapReceiver,
wantsToMarkAsSensitive = wantsToMarkAsSensitive, wantsToMarkAsSensitive = wantsToMarkAsSensitive,
zapRaiserAmount = zapRaiserAmount, zapRaiserAmount = localZapRaiserAmount,
replyingTo = replyId, replyingTo = replyId,
root = rootId, root = rootId,
directMentions = tagger.directMentions directMentions = tagger.directMentions
@ -237,6 +240,7 @@ open class NewPostViewModel() : ViewModel() {
wantsInvoice = false wantsInvoice = false
wantsZapraiser = false wantsZapraiser = false
zapRaiserAmount = null
wantsForwardZapTo = false wantsForwardZapTo = false
wantsToMarkAsSensitive = false wantsToMarkAsSensitive = false
@ -342,8 +346,7 @@ open class NewPostViewModel() : ViewModel() {
} }
fun canPost(): Boolean { fun canPost(): Boolean {
return message.text.isNotBlank() && !isUploadingImage && !wantsInvoice return message.text.isNotBlank() && !isUploadingImage && !wantsInvoice && (!wantsZapraiser || zapRaiserAmount != null) && (!wantsPoll || pollOptions.values.all { it.isNotEmpty() }) && contentToAddUrl == null
(!wantsPoll || pollOptions.values.all { it.isNotEmpty() }) && contentToAddUrl == null
} }
fun includePollHashtagInMessage(include: Boolean, hashtag: String) { fun includePollHashtagInMessage(include: Boolean, hashtag: String) {

Wyświetl plik

@ -26,12 +26,13 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ui.actions.NewPostViewModel
import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.placeholderText
@Composable @Composable
fun ZapRaiserRequest( fun ZapRaiserRequest(
titleText: String? = null, titleText: String? = null,
onSuccess: (Long) -> Unit newPostViewModel: NewPostViewModel
) { ) {
Column( Column(
modifier = Modifier modifier = Modifier
@ -70,20 +71,21 @@ fun ZapRaiserRequest(
modifier = Modifier.padding(vertical = 10.dp) modifier = Modifier.padding(vertical = 10.dp)
) )
var amount by remember { mutableStateOf(10000L) }
OutlinedTextField( OutlinedTextField(
label = { Text(text = stringResource(R.string.zapraiser_target_amount_in_sats)) }, label = { Text(text = stringResource(R.string.zapraiser_target_amount_in_sats)) },
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
value = amount.toString(), value = if (newPostViewModel.zapRaiserAmount != null) {
newPostViewModel.zapRaiserAmount.toString()
} else {
""
},
onValueChange = { onValueChange = {
runCatching { runCatching {
if (it.isEmpty()) { if (it.isEmpty()) {
amount = 0 newPostViewModel.zapRaiserAmount = null
} else { } else {
amount = it.toLong() newPostViewModel.zapRaiserAmount = it.toLongOrNull()
} }
onSuccess(amount)
} }
}, },
placeholder = { placeholder = {

Wyświetl plik

@ -127,7 +127,7 @@ fun ReactionsRow(baseNote: Note, showReactionDetail: Boolean, accountViewModel:
} }
} }
if (zapraiserAmount != null) { if (zapraiserAmount != null && zapraiserAmount > 0) {
Spacer(modifier = Modifier.height(4.dp)) Spacer(modifier = Modifier.height(4.dp))
Row( Row(
verticalAlignment = CenterVertically, verticalAlignment = CenterVertically,