diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/BoostSetCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/BoostSetCompose.kt deleted file mode 100644 index 56f860a07..000000000 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/BoostSetCompose.kt +++ /dev/null @@ -1,139 +0,0 @@ -package com.vitorpamplona.amethyst.ui.note - -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.background -import androidx.compose.foundation.combinedClickable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.FlowRow -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width -import androidx.compose.material.Icon -import androidx.compose.material.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.compositeOver -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.unit.dp -import com.vitorpamplona.amethyst.NotificationCache -import com.vitorpamplona.amethyst.R -import com.vitorpamplona.amethyst.ui.screen.BoostSetCard -import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel -import com.vitorpamplona.amethyst.ui.theme.newItemBackgroundColor -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext - -@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class) -@Composable -fun BoostSetCompose(boostSetCard: BoostSetCard, isInnerNote: Boolean = false, routeForLastRead: String, accountViewModel: AccountViewModel, nav: (String) -> Unit) { - val noteState by boostSetCard.note.live().metadata.observeAsState() - val note = noteState?.note - - val accountState by accountViewModel.accountLiveData.observeAsState() - val account = accountState?.account ?: return - - var popupExpanded by remember { mutableStateOf(false) } - - val scope = rememberCoroutineScope() - - if (note == null) { - BlankNote(Modifier, isInnerNote) - } else { - var isNew by remember { mutableStateOf(false) } - - LaunchedEffect(key1 = boostSetCard) { - withContext(Dispatchers.IO) { - isNew = boostSetCard.createdAt > NotificationCache.load(routeForLastRead) - - NotificationCache.markAsRead(routeForLastRead, boostSetCard.createdAt) - } - } - - val backgroundColor = if (isNew) { - MaterialTheme.colors.newItemBackgroundColor.compositeOver(MaterialTheme.colors.background) - } else { - MaterialTheme.colors.background - } - - Column( - modifier = Modifier - .background(backgroundColor) - .combinedClickable( - onClick = { - scope.launch { - routeFor( - note, - account.userProfile() - )?.let { nav(it) } - } - }, - onLongClick = { popupExpanded = true } - ) - ) { - Row( - modifier = Modifier - .padding( - start = if (!isInnerNote) 12.dp else 0.dp, - end = if (!isInnerNote) 12.dp else 0.dp, - top = 10.dp - ) - ) { - // Draws the like picture outside the boosted card. - if (!isInnerNote) { - Box( - modifier = Modifier - .width(55.dp) - .padding(0.dp) - ) { - Icon( - painter = painterResource(R.drawable.ic_retweeted), - null, - modifier = Modifier - .size(16.dp) - .align(Alignment.TopEnd), - tint = Color.Unspecified - ) - } - } - - Column(modifier = Modifier.padding(start = if (!isInnerNote) 10.dp else 0.dp)) { - FlowRow() { - boostSetCard.boostEvents.forEach { - NoteAuthorPicture( - baseNote = it, - nav = nav, - accountViewModel = accountViewModel, - size = 35.dp - ) - } - } - - NoteCompose( - baseNote = note, - routeForLastRead = null, - modifier = Modifier.padding(top = 5.dp), - isBoostedNote = true, - parentBackgroundColor = backgroundColor, - accountViewModel = accountViewModel, - nav = nav - ) - - NoteDropDownMenu(note, popupExpanded, { popupExpanded = false }, accountViewModel) - } - } - } - } -} diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/LikeSetCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/LikeSetCompose.kt deleted file mode 100644 index 38cd514ed..000000000 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/LikeSetCompose.kt +++ /dev/null @@ -1,139 +0,0 @@ -package com.vitorpamplona.amethyst.ui.note - -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.background -import androidx.compose.foundation.combinedClickable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.FlowRow -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width -import androidx.compose.material.Icon -import androidx.compose.material.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.compositeOver -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.unit.dp -import com.vitorpamplona.amethyst.NotificationCache -import com.vitorpamplona.amethyst.R -import com.vitorpamplona.amethyst.ui.screen.LikeSetCard -import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel -import com.vitorpamplona.amethyst.ui.theme.newItemBackgroundColor -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext - -@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class) -@Composable -fun LikeSetCompose(likeSetCard: LikeSetCard, isInnerNote: Boolean = false, routeForLastRead: String, accountViewModel: AccountViewModel, nav: (String) -> Unit) { - val noteState by likeSetCard.note.live().metadata.observeAsState() - val note = noteState?.note - - val accountState by accountViewModel.accountLiveData.observeAsState() - val account = accountState?.account ?: return - - val noteEvent = note?.event - var popupExpanded by remember { mutableStateOf(false) } - val scope = rememberCoroutineScope() - - if (note == null) { - BlankNote(Modifier, isInnerNote) - } else { - var isNew by remember { mutableStateOf(false) } - - LaunchedEffect(key1 = likeSetCard) { - withContext(Dispatchers.IO) { - isNew = likeSetCard.createdAt > NotificationCache.load(routeForLastRead) - - NotificationCache.markAsRead(routeForLastRead, likeSetCard.createdAt) - } - } - - val backgroundColor = if (isNew) { - MaterialTheme.colors.newItemBackgroundColor.compositeOver(MaterialTheme.colors.background) - } else { - MaterialTheme.colors.background - } - - Column( - modifier = Modifier - .background(backgroundColor) - .combinedClickable( - onClick = { - scope.launch { - routeFor( - note, - account.userProfile() - )?.let { nav(it) } - } - }, - onLongClick = { popupExpanded = true } - ) - ) { - Row( - modifier = Modifier - .padding( - start = if (!isInnerNote) 12.dp else 0.dp, - end = if (!isInnerNote) 12.dp else 0.dp, - top = 10.dp - ) - ) { - // Draws the like picture outside the boosted card. - if (!isInnerNote) { - Box( - modifier = Modifier - .width(55.dp) - .padding(0.dp) - ) { - Icon( - painter = painterResource(R.drawable.ic_liked), - null, - modifier = Modifier - .size(16.dp) - .align(Alignment.TopEnd), - tint = Color.Unspecified - ) - } - } - - Column(modifier = Modifier.padding(start = if (!isInnerNote) 10.dp else 0.dp)) { - FlowRow() { - likeSetCard.likeEvents.forEach { - NoteAuthorPicture( - baseNote = it, - nav = nav, - accountViewModel = accountViewModel, - size = 35.dp - ) - } - } - - NoteCompose( - baseNote = note, - routeForLastRead = null, - modifier = Modifier.padding(top = 5.dp), - isBoostedNote = true, - parentBackgroundColor = backgroundColor, - accountViewModel = accountViewModel, - nav = nav - ) - - NoteDropDownMenu(note, popupExpanded, { popupExpanded = false }, accountViewModel) - } - } - } - } -} diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapSetCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapSetCompose.kt deleted file mode 100644 index 6cdaed920..000000000 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapSetCompose.kt +++ /dev/null @@ -1,137 +0,0 @@ -package com.vitorpamplona.amethyst.ui.note - -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.background -import androidx.compose.foundation.combinedClickable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.FlowRow -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width -import androidx.compose.material.Icon -import androidx.compose.material.MaterialTheme -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Bolt -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.compositeOver -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp -import com.vitorpamplona.amethyst.NotificationCache -import com.vitorpamplona.amethyst.R -import com.vitorpamplona.amethyst.ui.screen.ZapSetCard -import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel -import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange -import com.vitorpamplona.amethyst.ui.theme.newItemBackgroundColor -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext - -@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class) -@Composable -fun ZapSetCompose(zapSetCard: ZapSetCard, isInnerNote: Boolean = false, routeForLastRead: String, accountViewModel: AccountViewModel, nav: (String) -> Unit) { - val noteState by zapSetCard.note.live().metadata.observeAsState() - val note = noteState?.note - - var popupExpanded by remember { mutableStateOf(false) } - val scope = rememberCoroutineScope() - - if (note == null) { - BlankNote(Modifier, isInnerNote) - } else { - var isNew by remember { mutableStateOf(false) } - - LaunchedEffect(key1 = zapSetCard) { - withContext(Dispatchers.IO) { - isNew = zapSetCard.createdAt > NotificationCache.load(routeForLastRead) - - NotificationCache.markAsRead(routeForLastRead, zapSetCard.createdAt) - } - } - - var backgroundColor = if (isNew) { - MaterialTheme.colors.newItemBackgroundColor.compositeOver(MaterialTheme.colors.background) - } else { - MaterialTheme.colors.background - } - - Column( - modifier = Modifier - .background(backgroundColor) - .combinedClickable( - onClick = { - scope.launch { - routeFor( - note, - accountViewModel.userProfile() - )?.let { nav(it) } - } - }, - onLongClick = { popupExpanded = true } - ) - ) { - Row( - modifier = Modifier - .padding( - start = if (!isInnerNote) 12.dp else 0.dp, - end = if (!isInnerNote) 12.dp else 0.dp, - top = 10.dp - ) - ) { - // Draws the like picture outside the boosted card. - if (!isInnerNote) { - Box( - modifier = Modifier - .width(55.dp) - .padding(0.dp) - ) { - Icon( - imageVector = Icons.Default.Bolt, - contentDescription = stringResource(id = R.string.zaps), - tint = BitcoinOrange, - modifier = Modifier - .size(25.dp) - .align(Alignment.TopEnd) - ) - } - } - - Column(modifier = Modifier.padding(start = if (!isInnerNote) 10.dp else 0.dp)) { - FlowRow() { - zapSetCard.zapEvents.forEach { - NoteAuthorPicture( - baseNote = it.key, - nav = nav, - accountViewModel = accountViewModel, - size = 35.dp - ) - } - } - - NoteCompose( - baseNote = note, - routeForLastRead = null, - modifier = Modifier.padding(top = 5.dp), - isBoostedNote = true, - parentBackgroundColor = backgroundColor, - accountViewModel = accountViewModel, - nav = nav - ) - - NoteDropDownMenu(note, popupExpanded, { popupExpanded = false }, accountViewModel) - } - } - } - } -} diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedState.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedState.kt index 405ecd54c..4b32446a1 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedState.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedState.kt @@ -32,24 +32,6 @@ class NoteCard(val note: Note) : Card() { override fun id() = note.idHex } -@Immutable -class LikeSetCard(val note: Note, val likeEvents: List) : Card() { - val createdAt = likeEvents.maxOf { it.createdAt() ?: 0 } - override fun createdAt(): Long { - return createdAt - } - override fun id() = note.idHex + "L" + createdAt -} - -@Immutable -class ZapSetCard(val note: Note, val zapEvents: Map) : Card() { - val createdAt = zapEvents.maxOf { it.value.createdAt() ?: 0 } - override fun createdAt(): Long { - return createdAt - } - override fun id() = note.idHex + "Z" + createdAt -} - @Immutable class ZapUserSetCard(val user: User, val zapEvents: ImmutableMap) : Card() { val createdAt = zapEvents.maxOf { it.value.createdAt() ?: 0 } @@ -79,17 +61,6 @@ class MultiSetCard(val note: Note, val boostEvents: ImmutableList, val lik override fun id() = note.idHex + "X" + maxCreatedAt + "X" + minCreatedAt } -@Immutable -class BoostSetCard(val note: Note, val boostEvents: List) : Card() { - val createdAt = boostEvents.maxOf { it.createdAt() ?: 0 } - - override fun createdAt(): Long { - return createdAt - } - - override fun id() = note.idHex + "B" + createdAt -} - @Immutable class MessageSetCard(val note: Note) : Card() { override fun createdAt(): Long { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedView.kt index 1727648ec..8c9d37f6d 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedView.kt @@ -28,12 +28,9 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.vitorpamplona.amethyst.ui.note.BadgeCompose -import com.vitorpamplona.amethyst.ui.note.BoostSetCompose -import com.vitorpamplona.amethyst.ui.note.LikeSetCompose import com.vitorpamplona.amethyst.ui.note.MessageSetCompose import com.vitorpamplona.amethyst.ui.note.MultiSetCompose import com.vitorpamplona.amethyst.ui.note.NoteCompose -import com.vitorpamplona.amethyst.ui.note.ZapSetCompose import com.vitorpamplona.amethyst.ui.note.ZapUserSetCompose import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel @@ -178,14 +175,6 @@ private fun FeedLoaded( routeForLastRead = routeForLastRead ) - is ZapSetCard -> ZapSetCompose( - item, - isInnerNote = false, - accountViewModel = accountViewModel, - nav = nav, - routeForLastRead = routeForLastRead - ) - is ZapUserSetCard -> ZapUserSetCompose( item, isInnerNote = false, @@ -194,22 +183,6 @@ private fun FeedLoaded( routeForLastRead = routeForLastRead ) - is LikeSetCard -> LikeSetCompose( - item, - isInnerNote = false, - accountViewModel = accountViewModel, - nav = nav, - routeForLastRead = routeForLastRead - ) - - is BoostSetCard -> BoostSetCompose( - item, - isInnerNote = false, - accountViewModel = accountViewModel, - nav = nav, - routeForLastRead = routeForLastRead - ) - is MultiSetCard -> MultiSetCompose( item, accountViewModel = accountViewModel,