From f2a8e51b207d626eeaaa1c606d50e8fe72baceac Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Wed, 20 Mar 2024 15:18:00 -0400 Subject: [PATCH] Refactors horizontal dividers --- .../amethyst/ui/actions/EditPostView.kt | 5 + .../ui/actions/JoinUserOrChannelView.kt | 47 ++-- .../ui/actions/RelayInformationDialog.kt | 1 - .../amethyst/ui/note/ChannelCardCompose.kt | 7 +- .../amethyst/ui/note/NoteCompose.kt | 3 - .../amethyst/ui/note/RelayCompose.kt | 67 +++--- .../amethyst/ui/note/UserCompose.kt | 31 +-- .../amethyst/ui/note/types/CommunityHeader.kt | 9 - .../amethyst/ui/note/types/PeopleList.kt | 10 +- .../ui/note/types/RenderPostApproval.kt | 1 - .../amethyst/ui/screen/RelayFeedView.kt | 5 + .../amethyst/ui/screen/StringFeedView.kt | 19 +- .../amethyst/ui/screen/ThreadFeedView.kt | 201 ++++++++---------- .../amethyst/ui/screen/UserFeedView.kt | 5 + .../ui/screen/loggedIn/ChannelScreen.kt | 14 +- .../ui/screen/loggedIn/ChatroomScreen.kt | 6 + .../ui/screen/loggedIn/HashtagScreen.kt | 31 +-- .../ui/screen/loggedIn/HiddenUsersScreen.kt | 4 - .../ui/screen/loggedIn/NotificationScreen.kt | 8 +- .../ui/screen/loggedIn/ProfileScreen.kt | 23 +- .../ui/screen/loggedIn/SearchScreen.kt | 82 ++++--- .../ui/screen/loggedIn/ThreadScreen.kt | 7 +- 22 files changed, 255 insertions(+), 331 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostView.kt index 48e094605..dd0df3768 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostView.kt @@ -46,6 +46,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.CurrencyBitcoin import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LocalTextStyle @@ -98,6 +99,7 @@ import com.vitorpamplona.amethyst.ui.note.NoteCompose import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.UserLine import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange +import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.QuoteBorder import com.vitorpamplona.amethyst.ui.theme.Size10dp import com.vitorpamplona.amethyst.ui.theme.Size5dp @@ -448,6 +450,9 @@ fun ShowUserSuggestionListForEdit( key = { _, item -> item.pubkeyHex }, ) { _, item -> UserLine(item, accountViewModel) { editPostViewModel.autocompleteWithUser(item) } + HorizontalDivider( + thickness = DividerThickness, + ) } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/JoinUserOrChannelView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/JoinUserOrChannelView.kt index d6bf6f367..4cda055f4 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/JoinUserOrChannelView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/JoinUserOrChannelView.kt @@ -357,6 +357,10 @@ private fun RenderSearchResults( searchBarViewModel.clear() } + + HorizontalDivider( + thickness = DividerThickness, + ) } itemsIndexed( @@ -367,6 +371,10 @@ private fun RenderSearchResults( nav("Channel/${item.idHex}") searchBarViewModel.clear() } + + HorizontalDivider( + thickness = DividerThickness, + ) } } } @@ -404,39 +412,30 @@ fun UserComposeForChat( accountViewModel: AccountViewModel, onClick: () -> Unit, ) { - Column( + Row( modifier = Modifier.clickable( onClick = onClick, + ).padding( + start = 12.dp, + end = 12.dp, + top = 10.dp, + bottom = 10.dp, ), + verticalAlignment = Alignment.CenterVertically, ) { - Row( + ClickableUserPicture(baseUser, Size55dp, accountViewModel) + + Column( modifier = - Modifier.padding( - start = 12.dp, - end = 12.dp, - top = 10.dp, - ), - verticalAlignment = Alignment.CenterVertically, + Modifier + .padding(start = 10.dp) + .weight(1f), ) { - ClickableUserPicture(baseUser, Size55dp, accountViewModel) + Row(verticalAlignment = Alignment.CenterVertically) { UsernameDisplay(baseUser) } - Column( - modifier = - Modifier - .padding(start = 10.dp) - .weight(1f), - ) { - Row(verticalAlignment = Alignment.CenterVertically) { UsernameDisplay(baseUser) } - - DisplayUserAboutInfo(baseUser) - } + DisplayUserAboutInfo(baseUser) } - - HorizontalDivider( - modifier = Modifier.padding(top = 10.dp), - thickness = DividerThickness, - ) } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/RelayInformationDialog.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/RelayInformationDialog.kt index 464d7ec82..c8c44970e 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/RelayInformationDialog.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/RelayInformationDialog.kt @@ -294,7 +294,6 @@ private fun DisplayOwnerInformation( UserCompose( baseUser = it, accountViewModel = accountViewModel, - showDiviser = false, nav = nav, ) } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChannelCardCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChannelCardCompose.kt index 8b31f6994..785a92a64 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChannelCardCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChannelCardCompose.kt @@ -197,7 +197,7 @@ fun InnerChannelCardWithReactions( accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { - when (remember { baseNote.event }) { + when (baseNote.event) { is LiveActivitiesEvent -> { InnerCardRow(baseNote, accountViewModel, nav) } @@ -496,12 +496,11 @@ fun RenderLiveActivityThumb( Spacer(modifier = DoubleVertSpacer) ChannelHeader( - channelHex = remember { baseNote.idHex }, + channelHex = baseNote.idHex, showVideo = false, - showBottomDiviser = false, showFlag = false, sendToChannel = true, - modifier = remember { Modifier.padding(start = 0.dp, end = 0.dp, top = 5.dp, bottom = 5.dp) }, + modifier = Modifier, accountViewModel = accountViewModel, nav = nav, ) 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 bbf0f7ecf..b8544aae3 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 @@ -233,7 +233,6 @@ fun AcceptableNote( ChannelHeader( channelNote = baseNote, showVideo = !makeItShort, - showBottomDiviser = true, sendToChannel = true, accountViewModel = accountViewModel, nav = nav, @@ -267,7 +266,6 @@ fun AcceptableNote( ChannelHeader( channelNote = baseNote, showVideo = !makeItShort, - showBottomDiviser = true, sendToChannel = true, accountViewModel = accountViewModel, nav = nav, @@ -742,7 +740,6 @@ private fun ReplyRow( ChannelHeader( channelHex = it, showVideo = false, - showBottomDiviser = false, sendToChannel = true, modifier = MaterialTheme.colorScheme.replyModifier.padding(10.dp), accountViewModel = accountViewModel, diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayCompose.kt index a39aa5c26..572700fac 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayCompose.kt @@ -20,13 +20,13 @@ */ package com.vitorpamplona.amethyst.ui.note +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -47,7 +47,7 @@ import com.vitorpamplona.amethyst.model.RelayInfo import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.theme.ButtonBorder import com.vitorpamplona.amethyst.ui.theme.ButtonPadding -import com.vitorpamplona.amethyst.ui.theme.DividerThickness +import com.vitorpamplona.amethyst.ui.theme.StdPadding import com.vitorpamplona.amethyst.ui.theme.placeholderText import java.time.Instant import java.time.ZoneId @@ -62,49 +62,44 @@ fun RelayCompose( ) { val context = LocalContext.current - Column { - Row( - modifier = Modifier.padding(start = 12.dp, end = 12.dp, top = 10.dp), + Row( + modifier = StdPadding, + verticalAlignment = Alignment.CenterVertically, + ) { + Column( + modifier = Modifier.weight(1f), + verticalArrangement = Arrangement.Center, ) { - Column( - modifier = Modifier.padding(start = 10.dp).weight(1f), - ) { - Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { - Text( - relay.url.trim().removePrefix("wss://"), - fontWeight = FontWeight.Bold, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - - val lastTime by - remember(relay.lastEvent) { - derivedStateOf { timeAgo(relay.lastEvent, context = context) } - } - - Text( - text = lastTime, - maxLines = 1, - ) - } - + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { Text( - "${relay.counter} ${stringResource(R.string.posts_received)}", - color = MaterialTheme.colorScheme.placeholderText, + relay.url.trim().removePrefix("wss://"), + fontWeight = FontWeight.Bold, maxLines = 1, overflow = TextOverflow.Ellipsis, ) + + val lastTime by + remember(relay.lastEvent) { + derivedStateOf { timeAgo(relay.lastEvent, context = context) } + } + + Text( + text = lastTime, + maxLines = 1, + ) } - Column(modifier = Modifier.padding(start = 10.dp)) { - RelayOptions(accountViewModel, relay, onAddRelay, onRemoveRelay) - } + Text( + "${relay.counter} ${stringResource(R.string.posts_received)}", + color = MaterialTheme.colorScheme.placeholderText, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) } - HorizontalDivider( - modifier = Modifier.padding(top = 10.dp), - thickness = DividerThickness, - ) + Column(modifier = Modifier.padding(start = 10.dp)) { + RelayOptions(accountViewModel, relay, onAddRelay, onRemoveRelay) + } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt index 6026fb233..89ef9551f 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.padding -import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment @@ -32,7 +31,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel -import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.Size55dp import com.vitorpamplona.amethyst.ui.theme.StdPadding @@ -40,37 +38,26 @@ import com.vitorpamplona.amethyst.ui.theme.StdPadding fun UserCompose( baseUser: User, overallModifier: Modifier = StdPadding, - showDiviser: Boolean = true, accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { - Column( + Row( modifier = - Modifier.clickable( + overallModifier.clickable( onClick = { nav("User/${baseUser.pubkeyHex}") }, ), + verticalAlignment = Alignment.CenterVertically, ) { - Row( - modifier = overallModifier, - verticalAlignment = Alignment.CenterVertically, - ) { - UserPicture(baseUser, Size55dp, accountViewModel = accountViewModel, nav = nav) + UserPicture(baseUser, Size55dp, accountViewModel = accountViewModel, nav = nav) - Column(modifier = remember { Modifier.padding(start = 10.dp).weight(1f) }) { - Row(verticalAlignment = Alignment.CenterVertically) { UsernameDisplay(baseUser) } + Column(modifier = remember { Modifier.padding(start = 10.dp).weight(1f) }) { + Row(verticalAlignment = Alignment.CenterVertically) { UsernameDisplay(baseUser) } - AboutDisplay(baseUser) - } - - Column(modifier = remember { Modifier.padding(start = 10.dp) }) { - UserActionOptions(baseUser, accountViewModel) - } + AboutDisplay(baseUser) } - if (showDiviser) { - HorizontalDivider( - thickness = DividerThickness, - ) + Column(modifier = remember { Modifier.padding(start = 10.dp) }) { + UserActionOptions(baseUser, accountViewModel) } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt index 5d4dc7884..b38464f8d 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt @@ -31,7 +31,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -68,7 +67,6 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.JoinCommunityButton import com.vitorpamplona.amethyst.ui.screen.loggedIn.LeaveCommunityButton import com.vitorpamplona.amethyst.ui.screen.loggedIn.NormalTimeAgo -import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer import com.vitorpamplona.amethyst.ui.theme.HeaderPictureModifier import com.vitorpamplona.amethyst.ui.theme.Size10dp @@ -88,7 +86,6 @@ import java.util.Locale @Composable fun CommunityHeader( baseNote: AddressableNote, - showBottomDiviser: Boolean, sendToCommunity: Boolean, modifier: Modifier = StdPadding, accountViewModel: AccountViewModel, @@ -125,12 +122,6 @@ fun CommunityHeader( } } } - - if (showBottomDiviser) { - HorizontalDivider( - thickness = DividerThickness, - ) - } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PeopleList.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PeopleList.kt index a5d6c2ae0..59d146f47 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PeopleList.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PeopleList.kt @@ -23,11 +23,13 @@ package com.vitorpamplona.amethyst.ui.note.types import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement 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.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -50,6 +52,7 @@ import com.vitorpamplona.amethyst.ui.components.ShowMoreButton import com.vitorpamplona.amethyst.ui.note.UserCompose import com.vitorpamplona.amethyst.ui.note.getGradient import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel +import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.quartz.events.PeopleListEvent import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf @@ -98,13 +101,16 @@ fun DisplayPeopleList( Box { FlowRow(modifier = Modifier.padding(top = 5.dp)) { toMembersShow.forEach { user -> - Row(modifier = Modifier.fillMaxWidth()) { + Column(modifier = Modifier.fillMaxWidth()) { UserCompose( user, - overallModifier = Modifier, accountViewModel = accountViewModel, nav = nav, ) + + HorizontalDivider( + thickness = DividerThickness, + ) } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/RenderPostApproval.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/RenderPostApproval.kt index dfa972402..335ca8f7d 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/RenderPostApproval.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/RenderPostApproval.kt @@ -60,7 +60,6 @@ fun RenderPostApproval( baseNote?.let { CommunityHeader( baseNote = it, - showBottomDiviser = false, sendToCommunity = true, accountViewModel = accountViewModel, nav = nav, diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/RelayFeedView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/RelayFeedView.kt index 5203b1b8b..2b80040b3 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/RelayFeedView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/RelayFeedView.kt @@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.pullrefresh.PullRefreshIndicator import androidx.compose.material3.pullrefresh.pullRefresh import androidx.compose.material3.pullrefresh.rememberPullRefreshState @@ -47,6 +48,7 @@ import com.vitorpamplona.amethyst.ui.actions.NewRelayListView import com.vitorpamplona.amethyst.ui.components.BundledUpdate import com.vitorpamplona.amethyst.ui.note.RelayCompose import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel +import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.FeedPadding import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow @@ -169,6 +171,9 @@ fun RelayFeedView( onAddRelay = { wantsToAddRelay = item.url }, onRemoveRelay = { wantsToAddRelay = item.url }, ) + HorizontalDivider( + thickness = DividerThickness, + ) } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/StringFeedView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/StringFeedView.kt index e1f3a41d6..c3561e544 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/StringFeedView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/StringFeedView.kt @@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -37,17 +38,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vitorpamplona.amethyst.R +import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.FeedPadding -@Composable -fun RefreshingFeedStringFeedView( - viewModel: StringFeedViewModel, - enablePullRefresh: Boolean = true, - inner: @Composable (String) -> Unit, -) { - RefresheableBox(viewModel, enablePullRefresh) { StringFeedView(viewModel, inner = inner) } -} - @Composable fun StringFeedView( viewModel: StringFeedViewModel, @@ -112,7 +105,13 @@ private fun FeedLoaded( ) { item { pre?.let { it() } } - itemsIndexed(state.feed.value, key = { _, item -> item }) { _, item -> inner(item) } + itemsIndexed(state.feed.value, key = { _, item -> item }) { _, item -> + inner(item) + + HorizontalDivider( + thickness = DividerThickness, + ) + } item { post?.let { it() } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt index 5324ec45c..ac8f8125c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt @@ -20,13 +20,10 @@ */ package com.vitorpamplona.amethyst.ui.screen -import androidx.compose.animation.Crossfade -import androidx.compose.animation.core.tween import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.clickable import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -35,6 +32,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.text.KeyboardOptions @@ -49,9 +47,6 @@ import androidx.compose.material3.ProvideTextStyle import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.material3.TextFieldDefaults -import androidx.compose.material3.pullrefresh.PullRefreshIndicator -import androidx.compose.material3.pullrefresh.pullRefresh -import androidx.compose.material3.pullrefresh.rememberPullRefreshState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.derivedStateOf @@ -80,7 +75,6 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.em import androidx.compose.ui.unit.sp -import androidx.lifecycle.compose.collectAsStateWithLifecycle import coil.compose.AsyncImage import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.LocalCache @@ -147,7 +141,6 @@ import com.vitorpamplona.amethyst.ui.theme.FeedPadding import com.vitorpamplona.amethyst.ui.theme.Size15Modifier import com.vitorpamplona.amethyst.ui.theme.Size24Modifier import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer -import com.vitorpamplona.amethyst.ui.theme.StdTopPadding import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn import com.vitorpamplona.amethyst.ui.theme.lessImportantLink import com.vitorpamplona.amethyst.ui.theme.placeholderText @@ -195,117 +188,100 @@ fun ThreadFeedView( accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { - val feedState by viewModel.feedContent.collectAsStateWithLifecycle() - val listState = rememberLazyListState() - var refreshing by remember { mutableStateOf(false) } - val refresh = { - refreshing = true - viewModel.invalidateData() - refreshing = false + RefresheableBox(viewModel) { + RenderFeedState( + viewModel = viewModel, + accountViewModel = accountViewModel, + listState = listState, + nav = nav, + routeForLastRead = null, + onLoaded = { + RenderThreadFeed(noteId, it, listState, accountViewModel, nav) + }, + ) } - val pullRefreshState = rememberPullRefreshState(refreshing, onRefresh = refresh) +} - Box(Modifier.pullRefresh(pullRefreshState)) { - Column { - Crossfade( - targetState = feedState, - animationSpec = tween(durationMillis = 100), - label = "ThreadViewMainState", - ) { state -> - when (state) { - is FeedState.Empty -> { - FeedEmpty { refreshing = true } - } - is FeedState.FeedError -> { - FeedError(state.errorMessage) { refreshing = true } - } - is FeedState.Loaded -> { - refreshing = false - LaunchedEffect(noteId) { - launch(Dispatchers.IO) { - // waits to load the thread to scroll to item. - delay(100) - val noteForPosition = state.feed.value.filter { it.idHex == noteId }.firstOrNull() - var position = state.feed.value.indexOf(noteForPosition) +@Composable +fun RenderThreadFeed( + noteId: String, + state: FeedState.Loaded, + listState: LazyListState, + accountViewModel: AccountViewModel, + nav: (String) -> Unit, +) { + LaunchedEffect(noteId) { + // waits to load the thread to scroll to item. + delay(100) + val noteForPosition = state.feed.value.filter { it.idHex == noteId }.firstOrNull() + var position = state.feed.value.indexOf(noteForPosition) - if (position >= 0) { - if (position >= 1 && position < state.feed.value.size - 1) { - position-- // show the replying note - } - - withContext(Dispatchers.Main) { listState.scrollToItem(position) } - } - } - } - - LazyColumn( - contentPadding = FeedPadding, - state = listState, - ) { - itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { index, item -> - if (index == 0) { - ProvideTextStyle(TextStyle(fontSize = 18.sp, lineHeight = 1.20.em)) { - NoteMaster( - item, - modifier = - Modifier.drawReplyLevel( - item.replyLevel(), - MaterialTheme.colorScheme.placeholderText, - if (item.idHex == noteId) { - MaterialTheme.colorScheme.lessImportantLink - } else { - MaterialTheme.colorScheme.placeholderText - }, - ), - accountViewModel = accountViewModel, - nav = nav, - ) - } - } else { - val selectedNoteColor = MaterialTheme.colorScheme.selectedNote - val background = - remember { - if (item.idHex == noteId) mutableStateOf(selectedNoteColor) else null - } - - NoteCompose( - item, - modifier = - Modifier.drawReplyLevel( - item.replyLevel(), - MaterialTheme.colorScheme.placeholderText, - if (item.idHex == noteId) { - MaterialTheme.colorScheme.lessImportantLink - } else { - MaterialTheme.colorScheme.placeholderText - }, - ), - parentBackgroundColor = background, - isBoostedNote = false, - unPackReply = false, - quotesLeft = 3, - accountViewModel = accountViewModel, - nav = nav, - ) - } - - HorizontalDivider( - modifier = StdTopPadding, - thickness = DividerThickness, - ) - } - } - } - FeedState.Loading -> { - LoadingFeed() - } - } + if (position >= 0) { + if (position >= 1 && position < state.feed.value.size - 1) { + position-- // show the replying note } - } - PullRefreshIndicator(refreshing, pullRefreshState, Modifier.align(Alignment.TopCenter)) + listState.scrollToItem(position) + } + } + + LazyColumn( + contentPadding = FeedPadding, + state = listState, + ) { + itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { index, item -> + if (index == 0) { + ProvideTextStyle(TextStyle(fontSize = 18.sp, lineHeight = 1.20.em)) { + NoteMaster( + item, + modifier = + Modifier.drawReplyLevel( + item.replyLevel(), + MaterialTheme.colorScheme.placeholderText, + if (item.idHex == noteId) { + MaterialTheme.colorScheme.lessImportantLink + } else { + MaterialTheme.colorScheme.placeholderText + }, + ), + accountViewModel = accountViewModel, + nav = nav, + ) + } + } else { + val selectedNoteColor = MaterialTheme.colorScheme.selectedNote + val background = + remember { + if (item.idHex == noteId) mutableStateOf(selectedNoteColor) else null + } + + NoteCompose( + item, + modifier = + Modifier.drawReplyLevel( + item.replyLevel(), + MaterialTheme.colorScheme.placeholderText, + if (item.idHex == noteId) { + MaterialTheme.colorScheme.lessImportantLink + } else { + MaterialTheme.colorScheme.placeholderText + }, + ), + parentBackgroundColor = background, + isBoostedNote = false, + unPackReply = false, + quotesLeft = 3, + accountViewModel = accountViewModel, + nav = nav, + ) + } + + HorizontalDivider( + thickness = DividerThickness, + ) + } } } @@ -504,7 +480,6 @@ fun NoteMaster( ChannelHeader( channelHex = note.channelHex()!!, showVideo = true, - showBottomDiviser = false, sendToChannel = true, accountViewModel = accountViewModel, nav = nav, diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedView.kt index bc52f5c4a..bc1ee84fe 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedView.kt @@ -25,11 +25,13 @@ import androidx.compose.animation.core.tween import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vitorpamplona.amethyst.ui.note.UserCompose import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel +import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.FeedPadding @Composable @@ -82,6 +84,9 @@ private fun FeedLoaded( ) { itemsIndexed(state.feed.value, key = { _, item -> item.pubkeyHex }) { _, item -> UserCompose(item, accountViewModel = accountViewModel, nav = nav) + HorizontalDivider( + thickness = DividerThickness, + ) } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt index 4bd0fc4a2..774a2c432 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt @@ -53,7 +53,6 @@ import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LocalTextStyle @@ -139,7 +138,6 @@ import com.vitorpamplona.amethyst.ui.screen.RefreshingChatroomFeedView import com.vitorpamplona.amethyst.ui.screen.equalImmutableLists import com.vitorpamplona.amethyst.ui.theme.ButtonBorder import com.vitorpamplona.amethyst.ui.theme.ButtonPadding -import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer import com.vitorpamplona.amethyst.ui.theme.EditFieldBorder @@ -557,7 +555,6 @@ fun MyTextField( fun ChannelHeader( channelNote: Note, showVideo: Boolean, - showBottomDiviser: Boolean, sendToChannel: Boolean, modifier: Modifier = StdPadding, accountViewModel: AccountViewModel, @@ -568,8 +565,8 @@ fun ChannelHeader( ChannelHeader( channelHex = it, showVideo = showVideo, - showBottomDiviser = showBottomDiviser, sendToChannel = sendToChannel, + modifier = modifier, accountViewModel = accountViewModel, nav = nav, ) @@ -580,7 +577,6 @@ fun ChannelHeader( fun ChannelHeader( channelHex: String, showVideo: Boolean, - showBottomDiviser: Boolean, showFlag: Boolean = true, sendToChannel: Boolean = false, modifier: Modifier = StdPadding, @@ -591,7 +587,6 @@ fun ChannelHeader( ChannelHeader( it, showVideo, - showBottomDiviser, showFlag, sendToChannel, modifier, @@ -605,7 +600,6 @@ fun ChannelHeader( fun ChannelHeader( baseChannel: Channel, showVideo: Boolean, - showBottomDiviser: Boolean, showFlag: Boolean = true, sendToChannel: Boolean = false, modifier: Modifier = StdPadding, @@ -641,12 +635,6 @@ fun ChannelHeader( LongChannelHeader(baseChannel = baseChannel, accountViewModel = accountViewModel, nav = nav) } } - - if (showBottomDiviser) { - HorizontalDivider( - thickness = DividerThickness, - ) - } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChatroomScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChatroomScreen.kt index 048738d96..2e378f268 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChatroomScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChatroomScreen.kt @@ -491,6 +491,9 @@ fun ShowUserSuggestionList( key = { _, item -> item.pubkeyHex }, ) { _, item -> UserLine(item, accountViewModel) { channelScreenModel.autocompleteWithUser(item) } + HorizontalDivider( + thickness = DividerThickness, + ) } } } @@ -807,6 +810,9 @@ fun LongRoomHeader( accountViewModel = accountViewModel, nav = nav, ) + HorizontalDivider( + thickness = DividerThickness, + ) } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HashtagScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HashtagScreen.kt index 2132d88ae..bce5dd76b 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HashtagScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HashtagScreen.kt @@ -27,7 +27,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect @@ -47,7 +46,6 @@ import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.service.NostrHashtagDataSource import com.vitorpamplona.amethyst.ui.screen.NostrHashtagFeedViewModel import com.vitorpamplona.amethyst.ui.screen.RefresheableFeedView -import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.StdPadding @Composable @@ -142,27 +140,18 @@ fun HashtagHeader( account: AccountViewModel, onClick: () -> Unit = {}, ) { - Column( - Modifier.fillMaxWidth().clickable { onClick() }, + Row( + modifier = Modifier.fillMaxWidth().clickable { onClick() }.then(modifier), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center, ) { - Column(modifier = modifier) { - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.Center, - ) { - Text( - "#$tag", - fontWeight = FontWeight.Bold, - modifier = Modifier.weight(1f), - ) - - HashtagActionOptions(tag, account) - } - } - - HorizontalDivider( - thickness = DividerThickness, + Text( + "#$tag", + fontWeight = FontWeight.Bold, + modifier = Modifier.weight(1f), ) + + HashtagActionOptions(tag, account) } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HiddenUsersScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HiddenUsersScreen.kt index a2ff9649a..37ee700b9 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HiddenUsersScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HiddenUsersScreen.kt @@ -312,10 +312,6 @@ fun MutedWordHeader( MutedWordActionOptions(tag, account) } } - - HorizontalDivider( - thickness = DividerThickness, - ) } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/NotificationScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/NotificationScreen.kt index 2ba1c7532..d607f0ba5 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/NotificationScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/NotificationScreen.kt @@ -120,7 +120,9 @@ fun NotificationScreen( SummaryBar( model = userReactionsStatsModel, ) - + HorizontalDivider( + thickness = DividerThickness, + ) RefreshableCardView( viewModel = notifFeedViewModel, accountViewModel = accountViewModel, @@ -229,10 +231,6 @@ fun SummaryBar(model: UserReactionsViewModel) { } } } - - HorizontalDivider( - thickness = DividerThickness, - ) } @Composable diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt index ef2cda5e0..b6995fe4f 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt @@ -1547,18 +1547,17 @@ fun TabFollowedTags( account: AccountViewModel, nav: (String) -> Unit, ) { - Column(Modifier.fillMaxHeight()) { - Column( - modifier = Modifier.padding(vertical = 0.dp), - ) { - baseUser.latestContactList?.let { - it.unverifiedFollowTagSet().forEach { hashtag -> - HashtagHeader( - tag = hashtag, - account = account, - onClick = { nav("Hashtag/$hashtag") }, - ) - } + Column(Modifier.fillMaxHeight().padding(vertical = 0.dp)) { + baseUser.latestContactList?.let { + it.unverifiedFollowTagSet().forEach { hashtag -> + HashtagHeader( + tag = hashtag, + account = account, + onClick = { nav("Hashtag/$hashtag") }, + ) + HorizontalDivider( + thickness = DividerThickness, + ) } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/SearchScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/SearchScreen.kt index 026a81072..426131ee0 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/SearchScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/SearchScreen.kt @@ -374,6 +374,11 @@ private fun DisplaySearchResults( key = { _, item -> "#$item" }, ) { _, item -> HashtagLine(item) { nav("Hashtag/$item") } + + HorizontalDivider( + modifier = Modifier.padding(top = 10.dp), + thickness = DividerThickness, + ) } itemsIndexed( @@ -381,6 +386,10 @@ private fun DisplaySearchResults( key = { _, item -> "u" + item.pubkeyHex }, ) { _, item -> UserCompose(item, accountViewModel = accountViewModel, nav = nav) + + HorizontalDivider( + thickness = DividerThickness, + ) } itemsIndexed( @@ -432,33 +441,24 @@ fun HashtagLine( tag: String, onClick: () -> Unit, ) { - Column( - modifier = Modifier.fillMaxWidth().clickable(onClick = onClick), + Row( + modifier = + Modifier.fillMaxWidth().clickable(onClick = onClick).padding( + start = 12.dp, + end = 12.dp, + top = 10.dp, + ), ) { Row( - modifier = - Modifier.padding( - start = 12.dp, - end = 12.dp, - top = 10.dp, - ), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center, + modifier = Modifier.fillMaxWidth(), ) { - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.Center, - modifier = Modifier.fillMaxWidth(), - ) { - Text( - "Search hashtag: #$tag", - fontWeight = FontWeight.Bold, - ) - } + Text( + "Search hashtag: #$tag", + fontWeight = FontWeight.Bold, + ) } - - HorizontalDivider( - modifier = Modifier.padding(top = 10.dp), - thickness = DividerThickness, - ) } } @@ -468,31 +468,23 @@ fun UserLine( accountViewModel: AccountViewModel, onClick: () -> Unit, ) { - Column( - modifier = Modifier.fillMaxWidth().clickable(onClick = onClick), + Row( + modifier = + Modifier.fillMaxWidth().clickable(onClick = onClick).padding( + start = 12.dp, + end = 12.dp, + top = 10.dp, + bottom = 10.dp, + ), ) { - Row( - modifier = - Modifier.padding( - start = 12.dp, - end = 12.dp, - top = 10.dp, - ), + ClickableUserPicture(baseUser, 55.dp, accountViewModel, Modifier, null) + + Column( + modifier = Modifier.padding(start = 10.dp).weight(1f), ) { - ClickableUserPicture(baseUser, 55.dp, accountViewModel, Modifier, null) + Row(verticalAlignment = Alignment.CenterVertically) { UsernameDisplay(baseUser) } - Column( - modifier = Modifier.padding(start = 10.dp).weight(1f), - ) { - Row(verticalAlignment = Alignment.CenterVertically) { UsernameDisplay(baseUser) } - - AboutDisplay(baseUser) - } + AboutDisplay(baseUser) } - - HorizontalDivider( - modifier = Modifier.padding(top = 10.dp), - thickness = DividerThickness, - ) } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ThreadScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ThreadScreen.kt index 78219e9b0..9ac6ed716 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ThreadScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ThreadScreen.kt @@ -20,11 +20,8 @@ */ package com.vitorpamplona.amethyst.ui.screen.loggedIn -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect -import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver @@ -79,7 +76,5 @@ fun ThreadScreen( onDispose { lifeCycleOwner.lifecycle.removeObserver(observer) } } - Column(Modifier.fillMaxHeight()) { - Column { ThreadFeedView(noteId, feedViewModel, accountViewModel, nav) } - } + ThreadFeedView(noteId, feedViewModel, accountViewModel, nav) }