updated ZapCustomDialog
This commit is contained in:
@@ -307,7 +307,7 @@ fun ZapReaction(
|
|||||||
|
|
||||||
var wantsToZap by remember { mutableStateOf(false) }
|
var wantsToZap by remember { mutableStateOf(false) }
|
||||||
var wantsToChangeZapAmount by remember { mutableStateOf(false) }
|
var wantsToChangeZapAmount by remember { mutableStateOf(false) }
|
||||||
var wantsToSetZapOptions by remember { mutableStateOf(false) }
|
var wantsToSetCustomZap by remember { mutableStateOf(false) }
|
||||||
val grayTint = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
|
val grayTint = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
@@ -373,7 +373,7 @@ fun ZapReaction(
|
|||||||
wantsToChangeZapAmount = true
|
wantsToChangeZapAmount = true
|
||||||
},
|
},
|
||||||
onDoubleClick = {
|
onDoubleClick = {
|
||||||
wantsToSetZapOptions = true
|
wantsToSetCustomZap = true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
@@ -406,8 +406,8 @@ fun ZapReaction(
|
|||||||
UpdateZapAmountDialog({ wantsToChangeZapAmount = false }, account = account)
|
UpdateZapAmountDialog({ wantsToChangeZapAmount = false }, account = account)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wantsToSetZapOptions) {
|
if (wantsToSetCustomZap) {
|
||||||
ZapOptionsDialog({ wantsToSetZapOptions = false }, account = account, accountViewModel, baseNote)
|
ZapCustomDialog({ wantsToSetCustomZap = false }, account = account, accountViewModel, baseNote)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zappedNote?.isZappedBy(account.userProfile()) == true) {
|
if (zappedNote?.isZappedBy(account.userProfile()) == true) {
|
||||||
|
|||||||
+46
-32
@@ -1,20 +1,9 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.note
|
package com.vitorpamplona.amethyst.ui.note
|
||||||
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.Button
|
import androidx.compose.material.*
|
||||||
import androidx.compose.material.MaterialTheme
|
|
||||||
import androidx.compose.material.OutlinedTextField
|
|
||||||
import androidx.compose.material.Surface
|
|
||||||
import androidx.compose.material.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@@ -25,10 +14,13 @@ 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
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
@@ -39,24 +31,29 @@ import com.vitorpamplona.amethyst.ui.actions.CloseButton
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class ZapOptionstViewModel : ViewModel() {
|
class ZapOptionstViewModel : ViewModel() {
|
||||||
private var account: Account? = null
|
private var account: Account? = null
|
||||||
|
|
||||||
var CustomAmount by mutableStateOf(TextFieldValue(""))
|
var customAmount by mutableStateOf(TextFieldValue("1000"))
|
||||||
var CustomMessage by mutableStateOf(TextFieldValue(""))
|
var customMessage by mutableStateOf(TextFieldValue(""))
|
||||||
|
|
||||||
fun load(account: Account) {
|
fun load(account: Account) {
|
||||||
this.account = account
|
this.account = account
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cancel() {
|
fun cancel() {
|
||||||
CustomAmount = TextFieldValue("")
|
customAmount = TextFieldValue("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isNumeric(toCheck: String): Boolean {
|
||||||
|
return toCheck.toLongOrNull() != null
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ZapOptionsDialog(onClose: () -> Unit, account: Account, accountViewModel: AccountViewModel, baseNote: Note) {
|
fun ZapCustomDialog(onClose: () -> Unit, account: Account, accountViewModel: AccountViewModel, baseNote: Note) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val postViewModel: ZapOptionstViewModel = viewModel()
|
val postViewModel: ZapOptionstViewModel = viewModel()
|
||||||
@@ -84,6 +81,26 @@ fun ZapOptionsDialog(onClose: () -> Unit, account: Account, accountViewModel: Ac
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(vertical = 5.dp),
|
||||||
|
horizontalArrangement = Arrangement.Start,
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(com.vitorpamplona.amethyst.R.drawable.zap),
|
||||||
|
null,
|
||||||
|
modifier = Modifier.size(20.dp),
|
||||||
|
tint = Color.Unspecified
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "Custom Zap",
|
||||||
|
fontSize = 20.sp,
|
||||||
|
fontWeight = FontWeight.W500,
|
||||||
|
modifier = Modifier.padding(start = 10.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@@ -94,9 +111,11 @@ fun ZapOptionsDialog(onClose: () -> Unit, account: Account, accountViewModel: Ac
|
|||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
// stringResource(R.string.new_amount_in_sats
|
// stringResource(R.string.new_amount_in_sats
|
||||||
label = { Text(text = "Custom Amount") },
|
label = { Text(text = "Custom Amount") },
|
||||||
value = postViewModel.CustomAmount,
|
value = postViewModel.customAmount,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
postViewModel.CustomAmount = it
|
if (isNumeric(it.text)) {
|
||||||
|
postViewModel.customAmount = it
|
||||||
|
}
|
||||||
},
|
},
|
||||||
keyboardOptions = KeyboardOptions.Default.copy(
|
keyboardOptions = KeyboardOptions.Default.copy(
|
||||||
capitalization = KeyboardCapitalization.None,
|
capitalization = KeyboardCapitalization.None,
|
||||||
@@ -104,7 +123,7 @@ fun ZapOptionsDialog(onClose: () -> Unit, account: Account, accountViewModel: Ac
|
|||||||
),
|
),
|
||||||
placeholder = {
|
placeholder = {
|
||||||
Text(
|
Text(
|
||||||
text = postViewModel.CustomAmount.text,
|
text = postViewModel.customAmount.text,
|
||||||
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
|
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -125,9 +144,9 @@ fun ZapOptionsDialog(onClose: () -> Unit, account: Account, accountViewModel: Ac
|
|||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
// stringResource(R.string.new_amount_in_sats
|
// stringResource(R.string.new_amount_in_sats
|
||||||
label = { Text(text = "Message") },
|
label = { Text(text = "Message") },
|
||||||
value = postViewModel.CustomMessage,
|
value = postViewModel.customMessage,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
postViewModel.CustomMessage = it
|
postViewModel.customMessage = it
|
||||||
},
|
},
|
||||||
keyboardOptions = KeyboardOptions.Default.copy(
|
keyboardOptions = KeyboardOptions.Default.copy(
|
||||||
capitalization = KeyboardCapitalization.None,
|
capitalization = KeyboardCapitalization.None,
|
||||||
@@ -135,7 +154,7 @@ fun ZapOptionsDialog(onClose: () -> Unit, account: Account, accountViewModel: Ac
|
|||||||
),
|
),
|
||||||
placeholder = {
|
placeholder = {
|
||||||
Text(
|
Text(
|
||||||
text = postViewModel.CustomMessage.text,
|
text = postViewModel.customMessage.text,
|
||||||
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
|
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -150,20 +169,15 @@ fun ZapOptionsDialog(onClose: () -> Unit, account: Account, accountViewModel: Ac
|
|||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
accountViewModel.zap(
|
accountViewModel.zap(
|
||||||
baseNote,
|
baseNote,
|
||||||
postViewModel.CustomAmount.text.toLong() * 1000,
|
postViewModel.customAmount.text.toLong() * 1000,
|
||||||
postViewModel.CustomMessage.text,
|
postViewModel.customMessage.text,
|
||||||
context,
|
context,
|
||||||
onError = {
|
onError = {
|
||||||
scope.launch {
|
|
||||||
// zappingProgress = 0f
|
|
||||||
Toast
|
Toast
|
||||||
.makeText(context, it, Toast.LENGTH_SHORT)
|
.makeText(context, it, Toast.LENGTH_SHORT).show()
|
||||||
.show()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onProgress = {
|
onProgress = {
|
||||||
scope.launch(Dispatchers.Main) {
|
scope.launch(Dispatchers.Main) {
|
||||||
// zappingProgress = it
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -171,7 +185,7 @@ fun ZapOptionsDialog(onClose: () -> Unit, account: Account, accountViewModel: Ac
|
|||||||
onClose()
|
onClose()
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Text(text = "Zap", color = Color.White)
|
Text(text = "⚡Zap ", color = Color.White)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user