From 346fb615074b4de2c04020440fafad0a23ba7b0f Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 12 Aug 2025 17:55:24 -0400 Subject: [PATCH] Small refactoring --- .../vitorpamplona/amethyst/model/Channel.kt | 2 +- .../amethyst/model/privateChats/Chatroom.kt | 1 + .../amethyst/model/privateChats/ListChange.kt | 39 ------------------- .../amethyst/ui/dal/ChangesFlowFilter.kt | 19 ++++++++- .../privateDM/dal/ChatroomFeedViewModel.kt | 2 +- .../screen/loggedIn/profile/ProfileScreen.kt | 14 +++---- .../vitorpamplona/amethyst/ui/theme/Shape.kt | 1 + 7 files changed, 27 insertions(+), 51 deletions(-) delete mode 100644 amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/ListChange.kt diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt index 60350a848..0af719319 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt @@ -21,8 +21,8 @@ package com.vitorpamplona.amethyst.model import androidx.compose.runtime.Stable -import com.vitorpamplona.amethyst.model.privateChats.ListChange import com.vitorpamplona.amethyst.ui.dal.DefaultFeedOrder +import com.vitorpamplona.amethyst.ui.dal.ListChange import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.utils.LargeCache diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt index a16e5752e..ed669a73a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt @@ -25,6 +25,7 @@ import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.NotesGatherer import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.ui.dal.DefaultFeedOrder +import com.vitorpamplona.amethyst.ui.dal.ListChange import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip04Dm.messages.PrivateDmEvent import com.vitorpamplona.quartz.nip14Subject.subject diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/ListChange.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/ListChange.kt deleted file mode 100644 index d1ae61cb4..000000000 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/ListChange.kt +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) 2025 Vitor Pamplona - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package com.vitorpamplona.amethyst.model.privateChats - -sealed class ListChange { - data class Addition( - val item: T, - ) : ListChange() - - data class Deletion( - val item: T, - ) : ListChange() - - data class SetAddition( - val item: Set, - ) : ListChange() - - data class SetDeletion( - val item: Set, - ) : ListChange() -} diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChangesFlowFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChangesFlowFilter.kt index 53f645ded..792ef828d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChangesFlowFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChangesFlowFilter.kt @@ -20,9 +20,26 @@ */ package com.vitorpamplona.amethyst.ui.dal -import com.vitorpamplona.amethyst.model.privateChats.ListChange import kotlinx.coroutines.flow.MutableSharedFlow interface ChangesFlowFilter : IAdditiveFeedFilter { fun changesFlow(): MutableSharedFlow> } + +sealed class ListChange { + data class Addition( + val item: T, + ) : ListChange() + + data class Deletion( + val item: T, + ) : ListChange() + + data class SetAddition( + val item: Set, + ) : ListChange() + + data class SetDeletion( + val item: Set, + ) : ListChange() +} diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/dal/ChatroomFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/dal/ChatroomFeedViewModel.kt index 0fac088f8..5c277bf08 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/dal/ChatroomFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/dal/ChatroomFeedViewModel.kt @@ -27,8 +27,8 @@ import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Note -import com.vitorpamplona.amethyst.model.privateChats.ListChange import com.vitorpamplona.amethyst.ui.dal.ChangesFlowFilter +import com.vitorpamplona.amethyst.ui.dal.ListChange import com.vitorpamplona.amethyst.ui.feeds.FeedContentState import com.vitorpamplona.amethyst.ui.feeds.InvalidatableContent import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKey diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/ProfileScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/ProfileScreen.kt index f62ec2ac3..71eb5802c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/ProfileScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/ProfileScreen.kt @@ -56,7 +56,6 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.IntSize -import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.LocalCache @@ -97,7 +96,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.zaps.ZapTabHeader import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.zaps.dal.UserProfileZapsFeedViewModel import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.theme.DividerThickness -import kotlinx.coroutines.Dispatchers +import com.vitorpamplona.amethyst.ui.theme.Size8dp import kotlinx.coroutines.launch @Composable @@ -112,12 +111,9 @@ fun ProfileScreen( if (userBase == null) { LaunchedEffect(userId) { - // waits to resolve. - launch(Dispatchers.IO) { - val newUserBase = LocalCache.checkGetOrCreateUser(userId) - if (newUserBase != userBase) { - userBase = newUserBase - } + val newUserBase = LocalCache.checkGetOrCreateUser(userId) + if (newUserBase != userBase) { + userBase = newUserBase } } } @@ -395,7 +391,7 @@ private fun RenderScreen( containerColor = Color.Transparent, contentColor = MaterialTheme.colorScheme.onBackground, selectedTabIndex = pagerState.currentPage, - edgePadding = 8.dp, + edgePadding = Size8dp, modifier = tabRowModifier, divider = { HorizontalDivider(thickness = DividerThickness) }, ) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt index 752cb9ce3..704938d0d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt @@ -90,6 +90,7 @@ val HalfDoubleVertSpacer = Modifier.height(7.dp) val Size0dp = 0.dp val Size5dp = 5.dp val Size6dp = 6.dp +val Size8dp = 8.dp val Size10dp = 10.dp val Size12dp = 12.dp val Size13dp = 13.dp