- Breaks down the Note Composition stack further

- Fixes some border issues between multiple note types
- Aligns Quick Actions to the center of the note.
This commit is contained in:
Vitor Pamplona
2023-06-09 10:02:56 -04:00
parent 5d8aa7bb58
commit f9cfe1479b
3 changed files with 282 additions and 163 deletions
@@ -57,7 +57,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Alignment.Companion.CenterVertically import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Alignment.Companion.TopEnd import androidx.compose.ui.Alignment.Companion.TopEnd
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@@ -159,6 +158,8 @@ import java.io.File
import java.math.BigDecimal import java.math.BigDecimal
import java.net.URL import java.net.URL
import java.util.Locale import java.util.Locale
import kotlin.time.ExperimentalTime
import kotlin.time.measureTimedValue
@OptIn(ExperimentalFoundationApi::class) @OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
@@ -385,6 +386,39 @@ fun NormalNote(
} else if (noteEvent is FileStorageHeaderEvent) { } else if (noteEvent is FileStorageHeaderEvent) {
FileStorageHeaderDisplay(baseNote) FileStorageHeaderDisplay(baseNote)
} else { } else {
NoteWithReactions(
baseNote,
routeForLastRead,
modifier,
isBoostedNote,
isQuotedNote,
unPackReply,
makeItShort,
addMarginTop,
canPreview,
parentBackgroundColor,
accountViewModel,
nav
)
}
}
@Composable
@OptIn(ExperimentalFoundationApi::class)
private fun NoteWithReactions(
baseNote: Note,
routeForLastRead: String? = null,
modifier: Modifier = Modifier,
isBoostedNote: Boolean = false,
isQuotedNote: Boolean = false,
unPackReply: Boolean = true,
makeItShort: Boolean = false,
addMarginTop: Boolean = true,
canPreview: Boolean = true,
parentBackgroundColor: Color? = null,
accountViewModel: AccountViewModel,
nav: (String) -> Unit
) {
var isNew by remember { mutableStateOf<Boolean>(false) } var isNew by remember { mutableStateOf<Boolean>(false) }
var popupExpanded by remember { mutableStateOf(false) } var popupExpanded by remember { mutableStateOf(false) }
@@ -438,6 +472,18 @@ fun NormalNote(
.background(backgroundColor) .background(backgroundColor)
} }
val notBoostedNorQuote by remember {
derivedStateOf {
!isBoostedNote && !isQuotedNote
}
}
val showSecondRow by remember {
derivedStateOf {
baseNote.event !is RepostEvent && !isBoostedNote && !isQuotedNote
}
}
Column(modifier = columnModifier) { Column(modifier = columnModifier) {
Row( Row(
modifier = remember { modifier = remember {
@@ -449,24 +495,75 @@ fun NormalNote(
) )
} }
) { ) {
if (!isBoostedNote && !isQuotedNote) { if (notBoostedNorQuote) {
DrawAuthorImages(baseNote, accountViewModel, nav) DrawAuthorImages(baseNote, accountViewModel, nav)
} }
Column( NoteBody(
baseNote,
modifier = remember { modifier = remember {
Modifier Modifier
.padding(start = if (!isBoostedNote && !isQuotedNote) 10.dp else 0.dp) .padding(start = if (notBoostedNorQuote) 10.dp else 0.dp)
},
isQuotedNote,
unPackReply,
makeItShort,
canPreview,
showSecondRow,
backgroundColor,
accountViewModel,
nav
)
NoteQuickActionMenu(
baseNote,
popupExpanded,
{ popupExpanded = false },
accountViewModel
)
} }
if (!makeItShort && baseNote.event !is RepostEvent) {
ReactionsRow(
baseNote,
notBoostedNorQuote,
accountViewModel,
nav
)
}
if (!isQuotedNote && !isBoostedNote) {
Divider(
thickness = 0.25.dp
)
}
}
}
@Composable
private fun NoteBody(
baseNote: Note,
modifier: Modifier,
showAuthorPicture: Boolean = false,
unPackReply: Boolean = true,
makeItShort: Boolean = false,
canPreview: Boolean = true,
showSecondRow: Boolean,
backgroundColor: Color,
accountViewModel: AccountViewModel,
nav: (String) -> Unit
) {
Column(
modifier = modifier
) { ) {
FirstUserInfoRow( FirstUserInfoRow(
baseNote = baseNote, baseNote = baseNote,
showAuthorPicture = isQuotedNote, showAuthorPicture = showAuthorPicture,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav nav = nav
) )
if (noteEvent !is RepostEvent && !makeItShort && !isQuotedNote) { if (showSecondRow) {
SecondUserInfoRow( SecondUserInfoRow(
baseNote, baseNote,
accountViewModel, accountViewModel,
@@ -486,6 +583,27 @@ fun NormalNote(
) )
} }
RenderNoteRow(
baseNote,
backgroundColor,
makeItShort,
canPreview,
accountViewModel,
nav
)
}
}
@Composable
private fun RenderNoteRow(
baseNote: Note,
backgroundColor: Color,
makeItShort: Boolean,
canPreview: Boolean,
accountViewModel: AccountViewModel,
nav: (String) -> Unit
) {
val noteEvent = remember { baseNote.event }
when (noteEvent) { when (noteEvent) {
is AppDefinitionEvent -> { is AppDefinitionEvent -> {
RenderAppDefinition(baseNote, accountViewModel, nav) RenderAppDefinition(baseNote, accountViewModel, nav)
@@ -528,11 +646,25 @@ fun NormalNote(
} }
is PrivateDmEvent -> { is PrivateDmEvent -> {
RenderPrivateMessage(baseNote, makeItShort, canPreview, backgroundColor, accountViewModel, nav) RenderPrivateMessage(
baseNote,
makeItShort,
canPreview,
backgroundColor,
accountViewModel,
nav
)
} }
is HighlightEvent -> { is HighlightEvent -> {
RenderHighlight(baseNote, makeItShort, canPreview, backgroundColor, accountViewModel, nav) RenderHighlight(
baseNote,
makeItShort,
canPreview,
backgroundColor,
accountViewModel,
nav
)
} }
is PollNoteEvent -> { is PollNoteEvent -> {
@@ -557,21 +689,6 @@ fun NormalNote(
) )
} }
} }
NoteQuickActionMenu(baseNote, popupExpanded, { popupExpanded = false }, accountViewModel)
}
}
if (!makeItShort) {
ReactionsRow(baseNote, !isBoostedNote && !isQuotedNote, accountViewModel, nav)
}
Divider(
modifier = Modifier.padding(top = 10.dp),
thickness = 0.25.dp
)
}
}
} }
fun routeFor(note: Note, loggedIn: User): String? { fun routeFor(note: Note, loggedIn: User): String? {
@@ -143,7 +143,7 @@ fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Uni
val isOwnNote = accountViewModel.isLoggedUser(note.author) val isOwnNote = accountViewModel.isLoggedUser(note.author)
val isFollowingUser = !isOwnNote && accountViewModel.isFollowing(note.author) val isFollowingUser = !isOwnNote && accountViewModel.isFollowing(note.author)
Popup(onDismissRequest = onDismiss) { Popup(onDismissRequest = onDismiss, alignment = Alignment.Center) {
Card( Card(
modifier = Modifier.shadow(elevation = 6.dp, shape = cardShape), modifier = Modifier.shadow(elevation = 6.dp, shape = cardShape),
shape = cardShape, shape = cardShape,
@@ -119,6 +119,8 @@ fun ReactionsRow(baseNote: Note, showReactionDetail: Boolean, accountViewModel:
if (showReactionDetail && wantsToSeeReactions.value) { if (showReactionDetail && wantsToSeeReactions.value) {
ReactionDetailGallery(baseNote, nav, accountViewModel) ReactionDetailGallery(baseNote, nav, accountViewModel)
} }
Spacer(modifier = Modifier.height(8.dp))
} }
@Composable @Composable