mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-12 01:07:46 +00:00
Merge pull request #2161 from vitorpamplona/claude/add-relay-drag-drop-uFrmj
Add drag-to-reorder functionality for relay lists
This commit is contained in:
+83
-15
@@ -47,7 +47,6 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.vitorpamplona.amethyst.R
|
||||
@@ -68,6 +67,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayExporter
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayListCollection
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayZipExporter
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.connected.ConnectedRelayListViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.connected.renderConnectedItems
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.dm.DMRelayListViewModel
|
||||
@@ -201,6 +201,67 @@ fun MappedAllRelayListView(
|
||||
val indexerCounts by indexerViewModel.countResults.collectAsStateWithLifecycle()
|
||||
val searchCounts by searchViewModel.countResults.collectAsStateWithLifecycle()
|
||||
|
||||
val homeDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> nip65ViewModel.moveHomeRelay(from, to) },
|
||||
itemCount = { homeFeedState.size },
|
||||
)
|
||||
val notifDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> nip65ViewModel.moveNotifRelay(from, to) },
|
||||
itemCount = { notifFeedState.size },
|
||||
)
|
||||
val dmDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> dmViewModel.moveRelay(from, to) },
|
||||
itemCount = { dmFeedState.size },
|
||||
)
|
||||
val privateOutboxDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> privateOutboxViewModel.moveRelay(from, to) },
|
||||
itemCount = { privateOutboxFeedState.size },
|
||||
)
|
||||
val proxyDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> proxyViewModel.moveRelay(from, to) },
|
||||
itemCount = { proxyRelays.size },
|
||||
)
|
||||
val broadcastDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> broadcastViewModel.moveRelay(from, to) },
|
||||
itemCount = { broadcastRelays.size },
|
||||
)
|
||||
val indexerDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> indexerViewModel.moveRelay(from, to) },
|
||||
itemCount = { indexerRelays.size },
|
||||
)
|
||||
val searchDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> searchViewModel.moveRelay(from, to) },
|
||||
itemCount = { searchFeedState.size },
|
||||
)
|
||||
val localDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> localViewModel.moveRelay(from, to) },
|
||||
itemCount = { localFeedState.size },
|
||||
)
|
||||
val trustedDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> trustedViewModel.moveRelay(from, to) },
|
||||
itemCount = { trustedFeedState.size },
|
||||
)
|
||||
val feedsDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> relayFeedsViewModel.moveRelay(from, to) },
|
||||
itemCount = { relayFeedsFeedState.size },
|
||||
)
|
||||
val blockedDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> blockedViewModel.moveRelay(from, to) },
|
||||
itemCount = { blockedFeedState.size },
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
SavingTopBar(
|
||||
@@ -254,14 +315,21 @@ fun MappedAllRelayListView(
|
||||
)
|
||||
},
|
||||
) { pad ->
|
||||
val anyDragging =
|
||||
homeDragState.isDragging || notifDragState.isDragging ||
|
||||
dmDragState.isDragging || privateOutboxDragState.isDragging ||
|
||||
proxyDragState.isDragging || broadcastDragState.isDragging ||
|
||||
indexerDragState.isDragging || searchDragState.isDragging ||
|
||||
localDragState.isDragging || trustedDragState.isDragging ||
|
||||
feedsDragState.isDragging || blockedDragState.isDragging
|
||||
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !anyDragging,
|
||||
modifier =
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.padding(
|
||||
start = 10.dp,
|
||||
end = 10.dp,
|
||||
top = pad.calculateTopPadding(),
|
||||
bottom = pad.calculateBottomPadding(),
|
||||
).consumeWindowInsets(pad)
|
||||
@@ -274,7 +342,7 @@ fun MappedAllRelayListView(
|
||||
SettingsCategoryFirstModifier,
|
||||
)
|
||||
}
|
||||
renderNip65HomeItems(homeFeedState, nip65ViewModel, accountViewModel, nav, outboxCounts)
|
||||
renderNip65HomeItems(homeFeedState, nip65ViewModel, accountViewModel, nav, outboxCounts, homeDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
@@ -283,7 +351,7 @@ fun MappedAllRelayListView(
|
||||
SettingsCategorySpacingModifier,
|
||||
)
|
||||
}
|
||||
renderNip65NotifItems(notifFeedState, nip65ViewModel, accountViewModel, nav, inboxCounts)
|
||||
renderNip65NotifItems(notifFeedState, nip65ViewModel, accountViewModel, nav, inboxCounts, notifDragState)
|
||||
|
||||
item {
|
||||
SettingsCategoryWithButton(
|
||||
@@ -295,7 +363,7 @@ fun MappedAllRelayListView(
|
||||
},
|
||||
)
|
||||
}
|
||||
renderDMItems(dmFeedState, dmViewModel, accountViewModel, nav, dmCounts)
|
||||
renderDMItems(dmFeedState, dmViewModel, accountViewModel, nav, dmCounts, dmDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
@@ -304,7 +372,7 @@ fun MappedAllRelayListView(
|
||||
SettingsCategorySpacingModifier,
|
||||
)
|
||||
}
|
||||
renderPrivateOutboxItems(privateOutboxFeedState, privateOutboxViewModel, accountViewModel, nav, privateHomeCounts)
|
||||
renderPrivateOutboxItems(privateOutboxFeedState, privateOutboxViewModel, accountViewModel, nav, privateHomeCounts, privateOutboxDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
@@ -313,7 +381,7 @@ fun MappedAllRelayListView(
|
||||
SettingsCategorySpacingModifier,
|
||||
)
|
||||
}
|
||||
renderProxyItems(proxyRelays, proxyViewModel, accountViewModel, nav, proxyCounts)
|
||||
renderProxyItems(proxyRelays, proxyViewModel, accountViewModel, nav, proxyCounts, proxyDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
@@ -322,7 +390,7 @@ fun MappedAllRelayListView(
|
||||
SettingsCategorySpacingModifier,
|
||||
)
|
||||
}
|
||||
renderBroadcastItems(broadcastRelays, broadcastViewModel, accountViewModel, nav)
|
||||
renderBroadcastItems(broadcastRelays, broadcastViewModel, accountViewModel, nav, broadcastDragState)
|
||||
|
||||
item {
|
||||
SettingsCategoryWithButton(
|
||||
@@ -333,7 +401,7 @@ fun MappedAllRelayListView(
|
||||
ResetIndexerRelays(indexerViewModel)
|
||||
}
|
||||
}
|
||||
renderIndexerItems(indexerRelays, indexerViewModel, accountViewModel, nav, indexerCounts)
|
||||
renderIndexerItems(indexerRelays, indexerViewModel, accountViewModel, nav, indexerCounts, indexerDragState)
|
||||
|
||||
item {
|
||||
SettingsCategoryWithButton(
|
||||
@@ -344,7 +412,7 @@ fun MappedAllRelayListView(
|
||||
ResetSearchRelays(searchViewModel)
|
||||
}
|
||||
}
|
||||
renderSearchItems(searchFeedState, searchViewModel, accountViewModel, nav, searchCounts)
|
||||
renderSearchItems(searchFeedState, searchViewModel, accountViewModel, nav, searchCounts, searchDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
@@ -371,7 +439,7 @@ fun MappedAllRelayListView(
|
||||
)
|
||||
}
|
||||
}
|
||||
renderLocalItems(localFeedState, localViewModel, accountViewModel, nav)
|
||||
renderLocalItems(localFeedState, localViewModel, accountViewModel, nav, localDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
@@ -380,7 +448,7 @@ fun MappedAllRelayListView(
|
||||
SettingsCategorySpacingModifier,
|
||||
)
|
||||
}
|
||||
renderTrustedItems(trustedFeedState, trustedViewModel, accountViewModel, nav)
|
||||
renderTrustedItems(trustedFeedState, trustedViewModel, accountViewModel, nav, trustedDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
@@ -389,7 +457,7 @@ fun MappedAllRelayListView(
|
||||
SettingsCategorySpacingModifier,
|
||||
)
|
||||
}
|
||||
renderRelayFeedsItems(relayFeedsFeedState, relayFeedsViewModel, accountViewModel, nav)
|
||||
renderRelayFeedsItems(relayFeedsFeedState, relayFeedsViewModel, accountViewModel, nav, feedsDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
@@ -398,7 +466,7 @@ fun MappedAllRelayListView(
|
||||
SettingsCategorySpacingModifier,
|
||||
)
|
||||
}
|
||||
renderBlockedItems(blockedFeedState, blockedViewModel, accountViewModel, nav)
|
||||
renderBlockedItems(blockedFeedState, blockedViewModel, accountViewModel, nav, blockedDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
|
||||
+12
-2
@@ -35,8 +35,10 @@ import com.vitorpamplona.amethyst.ui.navigation.navs.rememberExtendedNav
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
|
||||
@@ -48,14 +50,19 @@ fun BlockedRelayList(
|
||||
nav: INav,
|
||||
) {
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderBlockedItems(feedState, postViewModel, accountViewModel, newNav)
|
||||
renderBlockedItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,12 +72,15 @@ fun LazyListScope.renderBlockedItems(
|
||||
postViewModel: BlockedRelayListViewModel,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "Blocked" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
item,
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
+13
-3
@@ -35,8 +35,10 @@ import com.vitorpamplona.amethyst.ui.navigation.navs.rememberExtendedNav
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
|
||||
@@ -48,14 +50,19 @@ fun BroadcastRelayList(
|
||||
nav: INav,
|
||||
) {
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderBroadcastItems(feedState, postViewModel, accountViewModel, newNav)
|
||||
renderBroadcastItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,13 +72,16 @@ fun LazyListScope.renderBroadcastItems(
|
||||
postViewModel: BroadcastRelayListViewModel,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "Broadcast" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
item,
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
accountViewModel = accountViewModel,
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
}
|
||||
|
||||
+47
-12
@@ -28,7 +28,13 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.DragIndicator
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -36,6 +42,7 @@ import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboard
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.model.nip11RelayInfo.Nip11CachedRetriever
|
||||
import com.vitorpamplona.amethyst.model.nip11RelayInfo.loadRelayInfo
|
||||
@@ -65,28 +72,56 @@ fun BasicRelaySetupInfoClickableRow(
|
||||
onClick: () -> Unit,
|
||||
nip11CachedRetriever: Nip11CachedRetriever,
|
||||
modifier: Modifier = Modifier,
|
||||
index: Int = -1,
|
||||
dragState: RelayDragState? = null,
|
||||
countResult: RelayCountResult? = null,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
) {
|
||||
val clipboardManager = LocalClipboard.current
|
||||
val scope = rememberCoroutineScope()
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.combinedClickable(
|
||||
onClick = onClick,
|
||||
onLongClick = {
|
||||
scope.launch {
|
||||
clipboardManager.setText(item.relay.url)
|
||||
}
|
||||
},
|
||||
),
|
||||
) {
|
||||
|
||||
val itemModifier =
|
||||
if (dragState != null && index >= 0) {
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.draggableRelayItem(index, dragState)
|
||||
.combinedClickable(
|
||||
onClick = onClick,
|
||||
onLongClick = {
|
||||
scope.launch {
|
||||
clipboardManager.setText(item.relay.url)
|
||||
}
|
||||
},
|
||||
)
|
||||
} else {
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.combinedClickable(
|
||||
onClick = onClick,
|
||||
onLongClick = {
|
||||
scope.launch {
|
||||
clipboardManager.setText(item.relay.url)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Column(itemModifier) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = modifier,
|
||||
) {
|
||||
if (dragState != null && index >= 0) {
|
||||
val handleModifier = Modifier.height(24.dp).relayDragHandle(index, dragState)
|
||||
Icon(
|
||||
Icons.Default.DragIndicator,
|
||||
contentDescription = stringRes(R.string.relay_reorder),
|
||||
modifier = handleModifier,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
|
||||
val iconUrlFromRelayInfoDoc by loadRelayInfo(item.relay, nip11CachedRetriever)
|
||||
|
||||
RenderRelayIcon(
|
||||
|
||||
+6
-2
@@ -25,7 +25,7 @@ import com.vitorpamplona.amethyst.model.nip11RelayInfo.Nip11CachedRetriever
|
||||
import com.vitorpamplona.amethyst.ui.navigation.navs.INav
|
||||
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.theme.HalfVertPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.HorzHalfVertPadding
|
||||
|
||||
@Composable
|
||||
fun BasicRelaySetupInfoDialog(
|
||||
@@ -33,6 +33,8 @@ fun BasicRelaySetupInfoDialog(
|
||||
nip11CachedRetriever: Nip11CachedRetriever,
|
||||
onDelete: ((BasicRelaySetupInfo) -> Unit)?,
|
||||
countResult: RelayCountResult? = null,
|
||||
index: Int = -1,
|
||||
dragState: RelayDragState? = null,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
) {
|
||||
@@ -43,7 +45,9 @@ fun BasicRelaySetupInfoDialog(
|
||||
onDelete = onDelete,
|
||||
onClick = { nav.nav(Route.RelayInfo(item.relay.url)) },
|
||||
nip11CachedRetriever = nip11CachedRetriever,
|
||||
modifier = HalfVertPadding,
|
||||
modifier = HorzHalfVertPadding,
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
countResult = countResult,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
|
||||
+12
-2
@@ -132,8 +132,6 @@ abstract class BasicRelaySetupInfoModel : ViewModel() {
|
||||
.useTor(it),
|
||||
)
|
||||
}.distinctBy { it.relay }
|
||||
.sortedBy { it.relayStat.receivedBytes }
|
||||
.reversed()
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
@@ -152,6 +150,18 @@ abstract class BasicRelaySetupInfoModel : ViewModel() {
|
||||
hasModified = true
|
||||
}
|
||||
|
||||
fun moveRelay(
|
||||
from: Int,
|
||||
to: Int,
|
||||
) {
|
||||
_relays.update { list ->
|
||||
list.toMutableList().apply {
|
||||
add(to, removeAt(from))
|
||||
}
|
||||
}
|
||||
hasModified = true
|
||||
}
|
||||
|
||||
fun deleteAll() {
|
||||
_relays.update { relays -> emptyList() }
|
||||
hasModified = true
|
||||
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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.ui.screen.loggedIn.relays.common
|
||||
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.gestures.detectDragGestures
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.zIndex
|
||||
|
||||
@Stable
|
||||
class RelayDragState(
|
||||
val onMove: (from: Int, to: Int) -> Unit,
|
||||
val itemCount: () -> Int,
|
||||
) {
|
||||
var draggedItemIndex by mutableIntStateOf(-1)
|
||||
var dragOffset by mutableFloatStateOf(0f)
|
||||
val itemHeights = mutableStateMapOf<Int, Float>()
|
||||
val isDragging: Boolean get() = draggedItemIndex >= 0
|
||||
|
||||
fun onDragStart(index: Int) {
|
||||
draggedItemIndex = index
|
||||
dragOffset = 0f
|
||||
}
|
||||
|
||||
fun onDrag(dragAmount: Float) {
|
||||
dragOffset += dragAmount
|
||||
|
||||
val currentIndex = draggedItemIndex
|
||||
if (currentIndex < 0) return
|
||||
|
||||
// Check if we should swap with the item above
|
||||
if (dragOffset < 0 && currentIndex > 0) {
|
||||
val aboveHeight = itemHeights[currentIndex - 1] ?: 0f
|
||||
if (-dragOffset > aboveHeight / 2f) {
|
||||
onMove(currentIndex, currentIndex - 1)
|
||||
|
||||
val h1 = itemHeights[currentIndex]
|
||||
val h2 = itemHeights[currentIndex - 1]
|
||||
if (h1 != null) itemHeights[currentIndex - 1] = h1
|
||||
if (h2 != null) itemHeights[currentIndex] = h2
|
||||
|
||||
dragOffset += aboveHeight
|
||||
draggedItemIndex = currentIndex - 1
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we should swap with the item below
|
||||
if (dragOffset > 0 && currentIndex < itemCount() - 1) {
|
||||
val belowHeight = itemHeights[currentIndex + 1] ?: 0f
|
||||
if (dragOffset > belowHeight / 2f) {
|
||||
onMove(currentIndex, currentIndex + 1)
|
||||
|
||||
val h1 = itemHeights[currentIndex]
|
||||
val h2 = itemHeights[currentIndex + 1]
|
||||
if (h1 != null) itemHeights[currentIndex + 1] = h1
|
||||
if (h2 != null) itemHeights[currentIndex] = h2
|
||||
|
||||
dragOffset -= belowHeight
|
||||
draggedItemIndex = currentIndex + 1
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onDragEnd() {
|
||||
draggedItemIndex = -1
|
||||
dragOffset = 0f
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberRelayDragState(
|
||||
onMove: (from: Int, to: Int) -> Unit,
|
||||
itemCount: () -> Int,
|
||||
): RelayDragState =
|
||||
remember(onMove, itemCount) {
|
||||
RelayDragState(onMove, itemCount)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Modifier.draggableRelayItem(
|
||||
index: Int,
|
||||
dragState: RelayDragState,
|
||||
): Modifier {
|
||||
val isDragging = dragState.draggedItemIndex == index
|
||||
val targetElevation = if (isDragging) 8f else 0f
|
||||
val animatedElevation by animateFloatAsState(
|
||||
targetValue = targetElevation,
|
||||
label = "dragElevation",
|
||||
)
|
||||
|
||||
return this
|
||||
.zIndex(if (isDragging) 1f else 0f)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
dragState.itemHeights[index] = coordinates.size.height.toFloat()
|
||||
}.graphicsLayer {
|
||||
translationY = if (isDragging) dragState.dragOffset else 0f
|
||||
shadowElevation = animatedElevation
|
||||
if (isDragging) {
|
||||
scaleX = 1.02f
|
||||
scaleY = 1.02f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Modifier.relayDragHandle(
|
||||
index: Int,
|
||||
dragState: RelayDragState,
|
||||
): Modifier {
|
||||
// rememberUpdatedState keeps the index current without restarting
|
||||
// the pointerInput scope (which would cancel the in-progress gesture)
|
||||
val currentIndex by rememberUpdatedState(index)
|
||||
return this.pointerInput(dragState) {
|
||||
detectDragGestures(
|
||||
onDragStart = { dragState.onDragStart(currentIndex) },
|
||||
onDrag = { change, dragAmount ->
|
||||
change.consume()
|
||||
dragState.onDrag(dragAmount.y)
|
||||
},
|
||||
onDragEnd = { dragState.onDragEnd() },
|
||||
onDragCancel = { dragState.onDragEnd() },
|
||||
)
|
||||
}
|
||||
}
|
||||
+12
-1
@@ -36,8 +36,10 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
@@ -51,12 +53,18 @@ fun DMRelayList(
|
||||
) {
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderDMItems(feedState, postViewModel, accountViewModel, newNav)
|
||||
renderDMItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +75,7 @@ fun LazyListScope.renderDMItems(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
countResults: Map<NormalizedRelayUrl, RelayCountResult> = emptyMap(),
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "DM" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
@@ -74,6 +83,8 @@ fun LazyListScope.renderDMItems(
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
countResult = countResults[item.relay],
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
+12
-2
@@ -35,8 +35,10 @@ import com.vitorpamplona.amethyst.ui.navigation.navs.rememberExtendedNav
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
|
||||
@@ -48,14 +50,19 @@ fun RelayFeedsList(
|
||||
nav: INav,
|
||||
) {
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderRelayFeedsItems(feedState, postViewModel, accountViewModel, newNav)
|
||||
renderRelayFeedsItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,12 +72,15 @@ fun LazyListScope.renderRelayFeedsItems(
|
||||
postViewModel: RelayFeedsListViewModel,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "RelayFeeds" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
item,
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
+12
-2
@@ -36,8 +36,10 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
@@ -50,14 +52,19 @@ fun IndexerRelayList(
|
||||
nav: INav,
|
||||
) {
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderIndexerItems(feedState, postViewModel, accountViewModel, newNav)
|
||||
renderIndexerItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +75,7 @@ fun LazyListScope.renderIndexerItems(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
countResults: Map<NormalizedRelayUrl, RelayCountResult> = emptyMap(),
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "Indexer" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
@@ -75,6 +83,8 @@ fun LazyListScope.renderIndexerItems(
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
countResult = countResults[item.relay],
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
+12
-1
@@ -35,8 +35,10 @@ import com.vitorpamplona.amethyst.ui.navigation.navs.rememberExtendedNav
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
|
||||
@@ -49,12 +51,18 @@ fun LocalRelayList(
|
||||
) {
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderLocalItems(feedState, postViewModel, accountViewModel, newNav)
|
||||
renderLocalItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,12 +72,15 @@ fun LazyListScope.renderLocalItems(
|
||||
postViewModel: LocalRelayListViewModel,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "Local" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
item,
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
+12
-1
@@ -36,8 +36,10 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
@@ -51,12 +53,18 @@ fun PrivateOutboxRelayList(
|
||||
) {
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderPrivateOutboxItems(feedState, postViewModel, accountViewModel, newNav)
|
||||
renderPrivateOutboxItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +75,7 @@ fun LazyListScope.renderPrivateOutboxItems(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
countResults: Map<NormalizedRelayUrl, RelayCountResult> = emptyMap(),
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "Outbox" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
@@ -74,6 +83,8 @@ fun LazyListScope.renderPrivateOutboxItems(
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
countResult = countResults[item.relay],
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
+36
-6
@@ -36,8 +36,10 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
@@ -54,12 +56,24 @@ fun Nip65RelayList(
|
||||
val homeFeedState by postViewModel.homeRelays.collectAsStateWithLifecycle()
|
||||
val notifFeedState by postViewModel.notificationRelays.collectAsStateWithLifecycle()
|
||||
|
||||
val homeDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveHomeRelay(from, to) },
|
||||
itemCount = { homeFeedState.size },
|
||||
)
|
||||
val notifDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveNotifRelay(from, to) },
|
||||
itemCount = { notifFeedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !homeDragState.isDragging && !notifDragState.isDragging,
|
||||
) {
|
||||
renderNip65HomeItems(homeFeedState, postViewModel, accountViewModel, newNav)
|
||||
renderNip65NotifItems(notifFeedState, postViewModel, accountViewModel, newNav)
|
||||
renderNip65HomeItems(homeFeedState, postViewModel, accountViewModel, newNav, dragState = homeDragState)
|
||||
renderNip65NotifItems(notifFeedState, postViewModel, accountViewModel, newNav, dragState = notifDragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,14 +86,19 @@ fun Nip65InboxRelayList(
|
||||
nav: INav,
|
||||
) {
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
|
||||
val notifFeedState by postViewModel.notificationRelays.collectAsStateWithLifecycle()
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveNotifRelay(from, to) },
|
||||
itemCount = { notifFeedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderNip65NotifItems(notifFeedState, postViewModel, accountViewModel, newNav)
|
||||
renderNip65NotifItems(notifFeedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,14 +111,19 @@ fun Nip65OutboxRelayList(
|
||||
nav: INav,
|
||||
) {
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
|
||||
val homeFeedState by postViewModel.homeRelays.collectAsStateWithLifecycle()
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveHomeRelay(from, to) },
|
||||
itemCount = { homeFeedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderNip65HomeItems(homeFeedState, postViewModel, accountViewModel, newNav)
|
||||
renderNip65HomeItems(homeFeedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,6 +134,7 @@ fun LazyListScope.renderNip65HomeItems(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
countResults: Map<NormalizedRelayUrl, RelayCountResult> = emptyMap(),
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "Nip65Home" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
@@ -117,6 +142,8 @@ fun LazyListScope.renderNip65HomeItems(
|
||||
onDelete = { postViewModel.deleteHomeRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
countResult = countResults[item.relay],
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
@@ -138,6 +165,7 @@ fun LazyListScope.renderNip65NotifItems(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
countResults: Map<NormalizedRelayUrl, RelayCountResult> = emptyMap(),
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "Nip65Notif" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
@@ -145,6 +173,8 @@ fun LazyListScope.renderNip65NotifItems(
|
||||
onDelete = { postViewModel.deleteNotifRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
countResult = countResults[item.relay],
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
+24
-4
@@ -176,8 +176,6 @@ class Nip65RelayListViewModel : ViewModel() {
|
||||
relayList
|
||||
.map { relaySetupInfoBuilder(it) }
|
||||
.distinctBy { it.relay }
|
||||
.sortedBy { it.relayStat.receivedBytes }
|
||||
.reversed()
|
||||
}
|
||||
|
||||
_notificationRelays.update {
|
||||
@@ -186,8 +184,6 @@ class Nip65RelayListViewModel : ViewModel() {
|
||||
relayList
|
||||
.map { relaySetupInfoBuilder(it) }
|
||||
.distinctBy { it.relay }
|
||||
.sortedBy { it.relayStat.receivedBytes }
|
||||
.reversed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,6 +211,18 @@ class Nip65RelayListViewModel : ViewModel() {
|
||||
_homeRelays.update { it.replace(relay, relay.copy(paidRelay = paid)) }
|
||||
}
|
||||
|
||||
fun moveHomeRelay(
|
||||
from: Int,
|
||||
to: Int,
|
||||
) {
|
||||
_homeRelays.update { list ->
|
||||
list.toMutableList().apply {
|
||||
add(to, removeAt(from))
|
||||
}
|
||||
}
|
||||
hasModified = true
|
||||
}
|
||||
|
||||
fun addNotifRelay(relay: BasicRelaySetupInfo) {
|
||||
if (_notificationRelays.value.any { it.relay == relay.relay }) return
|
||||
|
||||
@@ -232,6 +240,18 @@ class Nip65RelayListViewModel : ViewModel() {
|
||||
hasModified = true
|
||||
}
|
||||
|
||||
fun moveNotifRelay(
|
||||
from: Int,
|
||||
to: Int,
|
||||
) {
|
||||
_notificationRelays.update { list ->
|
||||
list.toMutableList().apply {
|
||||
add(to, removeAt(from))
|
||||
}
|
||||
}
|
||||
hasModified = true
|
||||
}
|
||||
|
||||
fun toggleNotifPaidRelay(
|
||||
relay: BasicRelaySetupInfo,
|
||||
paid: Boolean,
|
||||
|
||||
+12
-2
@@ -36,8 +36,10 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
@@ -50,14 +52,19 @@ fun ProxyRelayList(
|
||||
nav: INav,
|
||||
) {
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderProxyItems(feedState, postViewModel, accountViewModel, newNav)
|
||||
renderProxyItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +75,7 @@ fun LazyListScope.renderProxyItems(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
countResults: Map<NormalizedRelayUrl, RelayCountResult> = emptyMap(),
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "Proxy" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
@@ -75,6 +83,8 @@ fun LazyListScope.renderProxyItems(
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
countResult = countResults[item.relay],
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
+12
-2
@@ -36,8 +36,10 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
@@ -50,14 +52,19 @@ fun SearchRelayList(
|
||||
nav: INav,
|
||||
) {
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderSearchItems(feedState, postViewModel, accountViewModel, newNav)
|
||||
renderSearchItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +75,7 @@ fun LazyListScope.renderSearchItems(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
countResults: Map<NormalizedRelayUrl, RelayCountResult> = emptyMap(),
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "Search" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
@@ -75,6 +83,8 @@ fun LazyListScope.renderSearchItems(
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
countResult = countResults[item.relay],
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
+12
-2
@@ -35,8 +35,10 @@ import com.vitorpamplona.amethyst.ui.navigation.navs.rememberExtendedNav
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
|
||||
@@ -48,14 +50,19 @@ fun TrustedRelayList(
|
||||
nav: INav,
|
||||
) {
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderTrustedItems(feedState, postViewModel, accountViewModel, newNav)
|
||||
renderTrustedItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,12 +72,15 @@ fun LazyListScope.renderTrustedItems(
|
||||
postViewModel: TrustedRelayListViewModel,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "Trusted" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
item,
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
@@ -155,6 +155,8 @@ val HalfVertPadding = Modifier.padding(vertical = 5.dp)
|
||||
val HorzPadding = Modifier.padding(horizontal = 10.dp)
|
||||
val VertPadding = Modifier.padding(vertical = 10.dp)
|
||||
|
||||
val HorzHalfVertPadding = Modifier.padding(horizontal = 10.dp, vertical = 5.dp)
|
||||
|
||||
val DoubleHorzPadding = Modifier.padding(horizontal = 20.dp)
|
||||
val DoubleVertPadding = Modifier.padding(vertical = 20.dp)
|
||||
|
||||
|
||||
@@ -1507,6 +1507,7 @@
|
||||
|
||||
<string name="dm_upload">DM Upload</string>
|
||||
<string name="relay_settings">Relay Settings</string>
|
||||
<string name="relay_reorder">Reorder relay</string>
|
||||
<string name="public_home_section">Public Outbox/Home Relays</string>
|
||||
<string name="public_home_section_explainer_profile">User is posting his content to these relays</string>
|
||||
<string name="public_home_section_explainer">This relay type stores all your content. Amethyst will send your posts here and others will use these relays to find your content. Insert between 1–3 relays. They can be personal relays, paid relays or public relays.</string>
|
||||
|
||||
Reference in New Issue
Block a user