Adds Zap amounts to Notification bubbles.
This commit is contained in:
@@ -31,8 +31,10 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.compositeOver
|
import androidx.compose.ui.graphics.compositeOver
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.google.accompanist.flowlayout.FlowRow
|
import com.google.accompanist.flowlayout.FlowRow
|
||||||
import com.vitorpamplona.amethyst.NotificationCache
|
import com.vitorpamplona.amethyst.NotificationCache
|
||||||
@@ -42,13 +44,16 @@ import com.vitorpamplona.amethyst.model.LocalCache
|
|||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.model.UserState
|
import com.vitorpamplona.amethyst.model.UserState
|
||||||
|
import com.vitorpamplona.amethyst.service.model.LnZapEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.LnZapRequestEvent
|
import com.vitorpamplona.amethyst.service.model.LnZapRequestEvent
|
||||||
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
||||||
import com.vitorpamplona.amethyst.ui.screen.MultiSetCard
|
import com.vitorpamplona.amethyst.ui.screen.MultiSetCard
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.showAmountAxis
|
||||||
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import java.math.BigDecimal
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -253,14 +258,10 @@ fun AuthorGalleryZaps(
|
|||||||
) {
|
) {
|
||||||
val accountState = account.userProfile().live().follows.observeAsState()
|
val accountState = account.userProfile().live().follows.observeAsState()
|
||||||
|
|
||||||
val listToRender = remember {
|
|
||||||
authorNotes.keys.take(50)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(modifier = Modifier.padding(start = 10.dp)) {
|
Column(modifier = Modifier.padding(start = 10.dp)) {
|
||||||
FlowRow() {
|
FlowRow() {
|
||||||
listToRender.forEach {
|
authorNotes.forEach {
|
||||||
AuthorPictureAndComment(it, navController, accountState, accountViewModel)
|
AuthorPictureAndComment(it.key, it.value, navController, accountState, accountViewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,38 +270,48 @@ fun AuthorGalleryZaps(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun AuthorPictureAndComment(
|
private fun AuthorPictureAndComment(
|
||||||
zapRequest: Note,
|
zapRequest: Note,
|
||||||
|
zapEvent: Note?,
|
||||||
navController: NavController,
|
navController: NavController,
|
||||||
accountUser: State<UserState?>,
|
accountUser: State<UserState?>,
|
||||||
accountViewModel: AccountViewModel
|
accountViewModel: AccountViewModel
|
||||||
) {
|
) {
|
||||||
val author = zapRequest.author ?: return
|
val author = zapRequest.author ?: return
|
||||||
|
|
||||||
var content by remember { mutableStateOf<Pair<User, String?>>(Pair(author, null)) }
|
var content by remember { mutableStateOf<Triple<User, String?, BigDecimal?>>(Triple(author, null, null)) }
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
LaunchedEffect(key1 = zapRequest.idHex) {
|
LaunchedEffect(key1 = zapRequest.idHex, key2 = zapEvent?.idHex) {
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
(zapRequest.event as? LnZapRequestEvent)?.let {
|
(zapRequest.event as? LnZapRequestEvent)?.let {
|
||||||
val decryptedContent = accountViewModel.decryptZap(zapRequest)
|
val decryptedContent = accountViewModel.decryptZap(zapRequest)
|
||||||
|
val amount = (zapEvent?.event as? LnZapEvent)?.amount
|
||||||
if (decryptedContent != null) {
|
if (decryptedContent != null) {
|
||||||
val newAuthor = LocalCache.getOrCreateUser(decryptedContent.pubKey)
|
val newAuthor = LocalCache.getOrCreateUser(decryptedContent.pubKey)
|
||||||
content = Pair(newAuthor, decryptedContent.content)
|
content = Triple(newAuthor, decryptedContent.content, amount)
|
||||||
} else {
|
} else {
|
||||||
if (!zapRequest.event?.content().isNullOrBlank()) {
|
if (!zapRequest.event?.content().isNullOrBlank() || amount != null) {
|
||||||
content = Pair(author, zapRequest.event?.content())
|
content = Triple(author, zapRequest.event?.content(), amount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthorPictureAndComment(content.first, content.second, navController, accountUser, accountViewModel)
|
AuthorPictureAndComment(
|
||||||
|
author = content.first,
|
||||||
|
comment = content.second,
|
||||||
|
amount = showAmountAxis(content.third),
|
||||||
|
navController = navController,
|
||||||
|
accountUser = accountUser,
|
||||||
|
accountViewModel = accountViewModel
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun AuthorPictureAndComment(
|
private fun AuthorPictureAndComment(
|
||||||
author: User,
|
author: User,
|
||||||
comment: String?,
|
comment: String?,
|
||||||
|
amount: String?,
|
||||||
navController: NavController,
|
navController: NavController,
|
||||||
accountUser: State<UserState?>,
|
accountUser: State<UserState?>,
|
||||||
accountViewModel: AccountViewModel
|
accountViewModel: AccountViewModel
|
||||||
@@ -323,11 +334,29 @@ private fun AuthorPictureAndComment(
|
|||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
FastNoteAuthorPicture(
|
Box(modifier = remember { Modifier.size(35.dp) }, contentAlignment = Alignment.BottomCenter) {
|
||||||
author = author,
|
FastNoteAuthorPicture(
|
||||||
userAccount = accountUser,
|
author = author,
|
||||||
size = 35.dp
|
userAccount = accountUser,
|
||||||
)
|
size = 35.dp
|
||||||
|
)
|
||||||
|
|
||||||
|
amount?.let {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(MaterialTheme.colors.background.copy(0.52f)),
|
||||||
|
contentAlignment = Alignment.BottomCenter
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = it,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = BitcoinOrange,
|
||||||
|
fontSize = 12.sp
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!comment.isNullOrBlank()) {
|
if (!comment.isNullOrBlank()) {
|
||||||
Spacer(modifier = Modifier.width(5.dp))
|
Spacer(modifier = Modifier.width(5.dp))
|
||||||
@@ -362,7 +391,7 @@ fun AuthorGallery(
|
|||||||
Column(modifier = Modifier.padding(start = 10.dp)) {
|
Column(modifier = Modifier.padding(start = 10.dp)) {
|
||||||
FlowRow() {
|
FlowRow() {
|
||||||
listToRender.first.forEach { author ->
|
listToRender.first.forEach { author ->
|
||||||
AuthorPictureAndComment(author, null, navController, accountState, accountViewModel)
|
AuthorPictureAndComment(author, null, null, navController, accountState, accountViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listToRender.second > 50) {
|
if (listToRender.second > 50) {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import com.vitorpamplona.amethyst.service.model.ReactionEvent
|
|||||||
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.TextNoteEvent
|
import com.vitorpamplona.amethyst.service.model.TextNoteEvent
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.showAmountAxis
|
||||||
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@@ -345,7 +346,7 @@ fun UserZapReaction(
|
|||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
showAmount(amount),
|
showAmountAxis(amount),
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
fontSize = 18.sp
|
fontSize = 18.sp
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user