From 5b6b6f19e5797edd077fd51507b48107db382e9b Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 5 May 2023 10:01:37 -0400 Subject: [PATCH] Reverting background refactoring due to color being stuck in recompositions. --- .../amethyst/ui/note/NoteCompose.kt | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt index eff2915bd..ad71c37ae 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt @@ -114,9 +114,6 @@ fun NoteComposeInner( accountViewModel: AccountViewModel, navController: NavController ) { - val defaultBackgroundColor = MaterialTheme.colors.background - val defaultPrimaryColor = MaterialTheme.colors.primary - val accountState by accountViewModel.accountLiveData.observeAsState() val account = accountState?.account ?: return val loggedIn = account.userProfile() @@ -178,7 +175,7 @@ fun NoteComposeInner( } else if (noteEvent is FileStorageHeaderEvent) { FileStorageHeaderDisplay(note) } else { - var backgroundColor by remember { mutableStateOf(defaultBackgroundColor) } + var isNew by remember { mutableStateOf(false) } LaunchedEffect(key1 = routeForLastRead) { withContext(Dispatchers.IO) { @@ -186,27 +183,25 @@ fun NoteComposeInner( val lastTime = NotificationCache.load(it) val createdAt = note.createdAt() - val isNew = if (createdAt != null) { + if (createdAt != null) { NotificationCache.markAsRead(it, createdAt) - createdAt > lastTime - } else { - false - } - - backgroundColor = if (isNew) { - val newColor = defaultPrimaryColor.copy(0.12f) - if (parentBackgroundColor != null) { - newColor.compositeOver(parentBackgroundColor) - } else { - newColor.compositeOver(defaultBackgroundColor) - } - } else { - parentBackgroundColor ?: defaultBackgroundColor + isNew = createdAt > lastTime } } } } + val backgroundColor = if (isNew) { + val newColor = MaterialTheme.colors.primary.copy(0.12f) + if (parentBackgroundColor != null) { + newColor.compositeOver(parentBackgroundColor) + } else { + newColor.compositeOver(MaterialTheme.colors.background) + } + } else { + parentBackgroundColor ?: MaterialTheme.colors.background + } + Column( modifier = modifier.combinedClickable( onClick = { @@ -234,8 +229,7 @@ fun NoteComposeInner( } }, onLongClick = { popupExpanded = true } - ) - .background(backgroundColor) + ).background(backgroundColor) ) { Row( modifier = Modifier