mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-27 20:26:33 +02:00
Small optimizations: removing animations, avoiding remembers
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.note
|
||||
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -60,34 +59,32 @@ fun WatchBlockAndReport(
|
||||
nav: (String) -> Unit,
|
||||
normalNote: @Composable (canPreview: Boolean) -> Unit,
|
||||
) {
|
||||
val hiddenState by accountViewModel.createIsHiddenFlow(note).collectAsStateWithLifecycle()
|
||||
val isHidden by accountViewModel.createIsHiddenFlow(note).collectAsStateWithLifecycle()
|
||||
|
||||
val showAnyway =
|
||||
remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
Crossfade(targetState = hiddenState, label = "CheckHiddenNoteCompose") { isHidden ->
|
||||
if (showAnyway.value) {
|
||||
normalNote(true)
|
||||
} else if (!isHidden.isPostHidden) {
|
||||
if (isHidden.isAcceptable) {
|
||||
normalNote(isHidden.canPreview)
|
||||
} else {
|
||||
HiddenNote(
|
||||
isHidden.relevantReports,
|
||||
isHidden.isHiddenAuthor,
|
||||
accountViewModel,
|
||||
modifier,
|
||||
nav,
|
||||
onClick = { showAnyway.value = true },
|
||||
)
|
||||
}
|
||||
} else if (showHiddenWarning) {
|
||||
// if it is a quoted or boosted note, how the hidden warning.
|
||||
HiddenNoteByMe {
|
||||
showAnyway.value = true
|
||||
}
|
||||
if (showAnyway.value) {
|
||||
normalNote(true)
|
||||
} else if (!isHidden.isPostHidden) {
|
||||
if (isHidden.isAcceptable) {
|
||||
normalNote(isHidden.canPreview)
|
||||
} else {
|
||||
HiddenNote(
|
||||
isHidden.relevantReports,
|
||||
isHidden.isHiddenAuthor,
|
||||
accountViewModel,
|
||||
modifier,
|
||||
nav,
|
||||
onClick = { showAnyway.value = true },
|
||||
)
|
||||
}
|
||||
} else if (showHiddenWarning) {
|
||||
// if it is a quoted or boosted note, how the hidden warning.
|
||||
HiddenNoteByMe {
|
||||
showAnyway.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -113,13 +113,13 @@ import com.vitorpamplona.amethyst.ui.note.types.RenderWikiContent
|
||||
import com.vitorpamplona.amethyst.ui.note.types.VideoDisplay
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.RenderChannelHeader
|
||||
import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.Font12SP
|
||||
import com.vitorpamplona.amethyst.ui.theme.HalfDoubleVertSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.HalfEndPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.HalfPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.HalfStartPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.RowColSpacing10dp
|
||||
import com.vitorpamplona.amethyst.ui.theme.RowColSpacing5dp
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size25dp
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size30Modifier
|
||||
@@ -458,10 +458,10 @@ fun InnerNoteWithReactions(
|
||||
} else {
|
||||
boostedNoteModifier
|
||||
},
|
||||
horizontalArrangement = RowColSpacing10dp,
|
||||
) {
|
||||
if (notBoostedNorQuote) {
|
||||
AuthorAndRelayInformation(baseNote, accountViewModel, nav)
|
||||
Spacer(modifier = DoubleHorzSpacer)
|
||||
}
|
||||
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
|
@@ -154,12 +154,8 @@ fun ReactionsRow(
|
||||
) {
|
||||
val wantsToSeeReactions = remember(baseNote) { mutableStateOf(false) }
|
||||
|
||||
Spacer(modifier = HalfDoubleVertSpacer)
|
||||
|
||||
InnerReactionRow(baseNote, showReactionDetail, addPadding, wantsToSeeReactions, editState, accountViewModel, nav)
|
||||
|
||||
Spacer(modifier = HalfDoubleVertSpacer)
|
||||
|
||||
LoadAndDisplayZapraiser(baseNote, showReactionDetail, wantsToSeeReactions, accountViewModel)
|
||||
|
||||
if (showReactionDetail && wantsToSeeReactions.value) {
|
||||
|
@@ -248,9 +248,7 @@ private fun FeedLoaded(
|
||||
state = listState,
|
||||
) {
|
||||
itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { _, item ->
|
||||
val defaultModifier = remember { Modifier.fillMaxWidth().animateItemPlacement() }
|
||||
|
||||
Row(defaultModifier) {
|
||||
Row(Modifier.fillMaxWidth().animateItemPlacement()) {
|
||||
NoteCompose(
|
||||
item,
|
||||
routeForLastRead = routeForLastRead,
|
||||
|
@@ -276,10 +276,10 @@ class AccountViewModel(
|
||||
|
||||
return if (isPostHidden) {
|
||||
// Spam + Blocked Users + Hidden Words + Sensitive Content
|
||||
NoteComposeReportState(isPostHidden, false, false, isHiddenAuthor, persistentSetOf())
|
||||
NoteComposeReportState(isPostHidden, false, false, isHiddenAuthor)
|
||||
} else if (isFromLoggedIn || isFromLoggedInFollow) {
|
||||
// No need to process if from trusted people
|
||||
NoteComposeReportState(isPostHidden, true, true, isHiddenAuthor, persistentSetOf())
|
||||
NoteComposeReportState(isPostHidden, true, true, isHiddenAuthor)
|
||||
} else {
|
||||
val newCanPreview = !note.hasAnyReports()
|
||||
|
||||
@@ -287,22 +287,20 @@ class AccountViewModel(
|
||||
|
||||
if (newCanPreview && newIsAcceptable) {
|
||||
// No need to process reports if nothing is wrong
|
||||
NoteComposeReportState(isPostHidden, true, true, false, persistentSetOf())
|
||||
NoteComposeReportState(isPostHidden, true, true, false)
|
||||
} else {
|
||||
val newRelevantReports = account.getRelevantReports(note)
|
||||
|
||||
NoteComposeReportState(
|
||||
isPostHidden,
|
||||
newIsAcceptable,
|
||||
newCanPreview,
|
||||
false,
|
||||
newRelevantReports.toImmutableSet(),
|
||||
account.getRelevantReports(note).toImmutableSet(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val noteIsHiddenFlows = LruCache<Note, StateFlow<NoteComposeReportState>>(300)
|
||||
private val noteIsHiddenFlows = LruCache<Note, StateFlow<NoteComposeReportState>>(300)
|
||||
|
||||
fun createIsHiddenFlow(note: Note): StateFlow<NoteComposeReportState> =
|
||||
noteIsHiddenFlows.get(note)
|
||||
@@ -312,9 +310,7 @@ class AccountViewModel(
|
||||
note.flow().metadata.stateFlow,
|
||||
note.flow().reports.stateFlow,
|
||||
) { hiddenUsers, followingUsers, metadata, reports ->
|
||||
emit(
|
||||
isNoteAcceptable(metadata.note, hiddenUsers, followingUsers.users),
|
||||
)
|
||||
emit(isNoteAcceptable(metadata.note, hiddenUsers, followingUsers.users))
|
||||
}.stateIn(
|
||||
viewModelScope,
|
||||
SharingStarted.Eagerly,
|
||||
@@ -323,7 +319,7 @@ class AccountViewModel(
|
||||
noteIsHiddenFlows.put(note, it)
|
||||
}
|
||||
|
||||
val noteMustShowExpandButtonFlows = LruCache<Note, StateFlow<Boolean>>(300)
|
||||
private val noteMustShowExpandButtonFlows = LruCache<Note, StateFlow<Boolean>>(300)
|
||||
|
||||
fun createMustShowExpandButtonFlows(note: Note): StateFlow<Boolean> =
|
||||
noteMustShowExpandButtonFlows.get(note)
|
||||
|
@@ -112,6 +112,7 @@ val BigPadding = Modifier.padding(15.dp)
|
||||
|
||||
val RowColSpacing = Arrangement.spacedBy(3.dp)
|
||||
val RowColSpacing5dp = Arrangement.spacedBy(5.dp)
|
||||
val RowColSpacing10dp = Arrangement.spacedBy(10.dp)
|
||||
|
||||
val HalfHorzPadding = Modifier.padding(horizontal = 5.dp)
|
||||
val HalfVertPadding = Modifier.padding(vertical = 5.dp)
|
||||
@@ -154,8 +155,8 @@ val VideoReactionColumnPadding = Modifier.padding(bottom = 75.dp)
|
||||
|
||||
val DividerThickness = 0.25.dp
|
||||
|
||||
val ReactionRowHeight = Modifier.height(24.dp)
|
||||
val ReactionRowHeightWithPadding = Modifier.height(24.dp).padding(start = 10.dp)
|
||||
val ReactionRowHeight = Modifier.padding(vertical = 7.dp).height(24.dp)
|
||||
val ReactionRowHeightWithPadding = Modifier.padding(vertical = 7.dp).height(24.dp).padding(start = 10.dp)
|
||||
val ReactionRowHeightChat = Modifier.height(25.dp)
|
||||
val UserNameRowHeight = Modifier.fillMaxWidth()
|
||||
val UserNameMaxRowHeight = Modifier.fillMaxWidth()
|
||||
|
Reference in New Issue
Block a user