From ce11edc352012ed980d0d710c1ffd1f20a95a0bc Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 6 Apr 2026 15:10:33 +0000 Subject: [PATCH] feat: add drag-and-drop reordering to all relay list settings Add DraggableRelayList composable with gesture-based drag-and-drop, following the same pattern used in ReactionsSettingsScreen. Each relay category (DM, NIP65 home/notif, search, blocked, trusted, local, broadcast, indexer, proxy, private outbox, favorites) now shows a drag handle and supports reordering via drag gestures. https://claude.ai/code/session_01RVM5kEJGrCaJTaP3GmVHDd --- .../relays/blocked/BlockedRelayListView.kt | 24 +-- .../broadcast/BroadcastRelayListView.kt | 24 +-- .../common/BasicRelaySetupInfoClickableRow.kt | 18 +++ .../common/BasicRelaySetupInfoDialog.kt | 3 + .../relays/common/BasicRelaySetupInfoModel.kt | 12 ++ .../relays/common/DraggableRelayList.kt | 143 ++++++++++++++++++ .../loggedIn/relays/dm/DMRelayListView.kt | 26 ++-- .../relays/feeds/RelayFeedsListView.kt | 24 +-- .../relays/indexer/IndexerRelayListView.kt | 26 ++-- .../relays/local/LocalRelayListView.kt | 24 +-- .../nip37/PrivateOutboxRelayListView.kt | 26 ++-- .../relays/nip65/Nip65RelayListView.kt | 50 +++--- .../relays/nip65/Nip65RelayListViewModel.kt | 24 +++ .../relays/proxy/ProxyRelayListView.kt | 26 ++-- .../relays/search/SearchRelayListView.kt | 26 ++-- .../relays/trusted/TrustedRelayListView.kt | 24 +-- amethyst/src/main/res/values/strings.xml | 1 + 17 files changed, 387 insertions(+), 114 deletions(-) create mode 100644 amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/DraggableRelayList.kt diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/blocked/BlockedRelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/blocked/BlockedRelayListView.kt index 3cd574c4b2..95b42d6d72 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/blocked/BlockedRelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/blocked/BlockedRelayListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList 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.theme.FeedPadding @@ -66,14 +66,20 @@ fun LazyListScope.renderBlockedItems( accountViewModel: AccountViewModel, nav: INav, ) { - itemsIndexed(feedState, key = { _, item -> "Blocked" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "Blocked_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/broadcast/BroadcastRelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/broadcast/BroadcastRelayListView.kt index 6f55c5ec91..770adee791 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/broadcast/BroadcastRelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/broadcast/BroadcastRelayListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList 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.theme.FeedPadding @@ -66,14 +66,20 @@ fun LazyListScope.renderBroadcastItems( accountViewModel: AccountViewModel, nav: INav, ) { - itemsIndexed(feedState, key = { _, item -> "Broadcast" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteRelay(item) }, - accountViewModel = accountViewModel, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - nav = nav, - ) + item(key = "Broadcast_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoClickableRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoClickableRow.kt index 567246686e..2446eb56ea 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoClickableRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoClickableRow.kt @@ -28,7 +28,12 @@ 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.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 +41,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,6 +71,7 @@ fun BasicRelaySetupInfoClickableRow( onClick: () -> Unit, nip11CachedRetriever: Nip11CachedRetriever, modifier: Modifier = Modifier, + dragModifier: Modifier = Modifier, countResult: RelayCountResult? = null, accountViewModel: AccountViewModel, nav: INav, @@ -87,6 +94,17 @@ fun BasicRelaySetupInfoClickableRow( verticalAlignment = Alignment.CenterVertically, modifier = modifier, ) { + if (dragModifier != Modifier) { + Icon( + Icons.Default.DragIndicator, + contentDescription = stringRes(R.string.relay_reorder), + modifier = + dragModifier + .size(24.dp), + tint = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + val iconUrlFromRelayInfoDoc by loadRelayInfo(item.relay, nip11CachedRetriever) RenderRelayIcon( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoDialog.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoDialog.kt index 3196a11747..2ecc90a6de 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoDialog.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoDialog.kt @@ -21,6 +21,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier import com.vitorpamplona.amethyst.model.nip11RelayInfo.Nip11CachedRetriever import com.vitorpamplona.amethyst.ui.navigation.navs.INav import com.vitorpamplona.amethyst.ui.navigation.routes.Route @@ -33,6 +34,7 @@ fun BasicRelaySetupInfoDialog( nip11CachedRetriever: Nip11CachedRetriever, onDelete: ((BasicRelaySetupInfo) -> Unit)?, countResult: RelayCountResult? = null, + dragModifier: Modifier = Modifier, accountViewModel: AccountViewModel, nav: INav, ) { @@ -44,6 +46,7 @@ fun BasicRelaySetupInfoDialog( onClick = { nav.nav(Route.RelayInfo(item.relay.url)) }, nip11CachedRetriever = nip11CachedRetriever, modifier = HalfVertPadding, + dragModifier = dragModifier, countResult = countResult, accountViewModel = accountViewModel, nav = nav, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoModel.kt index af9899177d..69ea96b907 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoModel.kt @@ -152,6 +152,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 diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/DraggableRelayList.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/DraggableRelayList.kt new file mode 100644 index 0000000000..ea2d47b204 --- /dev/null +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/DraggableRelayList.kt @@ -0,0 +1,143 @@ +/* + * 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.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.runtime.Composable +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.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 + +@Composable +fun DraggableRelayList( + items: List, + onMove: (from: Int, to: Int) -> Unit, + modifier: Modifier = Modifier, + content: @Composable ( + index: Int, + item: BasicRelaySetupInfo, + dragModifier: Modifier, + ) -> Unit, +) { + var draggedItemIndex by remember { mutableIntStateOf(-1) } + var dragOffset by remember { mutableFloatStateOf(0f) } + val itemHeights = remember { mutableStateMapOf() } + + Column(modifier = modifier.fillMaxWidth()) { + items.forEachIndexed { index, item -> + val isDragging = draggedItemIndex == index + val targetElevation = if (isDragging) 8f else 0f + val animatedElevation by animateFloatAsState( + targetValue = targetElevation, + label = "dragElevation", + ) + + Box( + modifier = + Modifier + .zIndex(if (isDragging) 1f else 0f) + .onGloballyPositioned { coordinates -> + itemHeights[index] = coordinates.size.height.toFloat() + }.graphicsLayer { + translationY = if (isDragging) dragOffset else 0f + shadowElevation = animatedElevation + if (isDragging) { + scaleX = 1.02f + scaleY = 1.02f + } + }, + ) { + val dragModifier = + Modifier.pointerInput(Unit) { + detectDragGestures( + onDragStart = { + draggedItemIndex = index + dragOffset = 0f + }, + onDrag = { change, dragAmount -> + change.consume() + dragOffset += dragAmount.y + + val currentIndex = draggedItemIndex + if (currentIndex < 0) return@detectDragGestures + + // 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) + + // Transfer heights + 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 + } + } + + // Check if we should swap with the item below + if (dragOffset > 0 && currentIndex < items.lastIndex) { + val belowHeight = itemHeights[currentIndex + 1] ?: 0f + if (dragOffset > belowHeight / 2f) { + onMove(currentIndex, currentIndex + 1) + + // Transfer heights + 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 + } + } + }, + onDragEnd = { + draggedItemIndex = -1 + dragOffset = 0f + }, + onDragCancel = { + draggedItemIndex = -1 + dragOffset = 0f + }, + ) + } + + content(index, item, dragModifier) + } + } + } +} diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/dm/DMRelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/dm/DMRelayListView.kt index f6e9395714..b8306a2c5e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/dm/DMRelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/dm/DMRelayListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder @@ -68,15 +68,21 @@ fun LazyListScope.renderDMItems( nav: INav, countResults: Map = emptyMap(), ) { - itemsIndexed(feedState, key = { _, item -> "DM" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - countResult = countResults[item.relay], - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "DM_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + countResult = countResults[item.relay], + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/feeds/RelayFeedsListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/feeds/RelayFeedsListView.kt index e9575fc0d7..62a785bc6a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/feeds/RelayFeedsListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/feeds/RelayFeedsListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList 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.theme.FeedPadding @@ -66,14 +66,20 @@ fun LazyListScope.renderRelayFeedsItems( accountViewModel: AccountViewModel, nav: INav, ) { - itemsIndexed(feedState, key = { _, item -> "RelayFeeds" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "RelayFeeds_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/indexer/IndexerRelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/indexer/IndexerRelayListView.kt index 56dbf8018c..ed728371ae 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/indexer/IndexerRelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/indexer/IndexerRelayListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder @@ -69,15 +69,21 @@ fun LazyListScope.renderIndexerItems( nav: INav, countResults: Map = emptyMap(), ) { - itemsIndexed(feedState, key = { _, item -> "Indexer" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - countResult = countResults[item.relay], - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "Indexer_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + countResult = countResults[item.relay], + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/local/LocalRelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/local/LocalRelayListView.kt index 8733ddbf2d..db8c459e1c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/local/LocalRelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/local/LocalRelayListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList 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.theme.FeedPadding @@ -65,14 +65,20 @@ fun LazyListScope.renderLocalItems( accountViewModel: AccountViewModel, nav: INav, ) { - itemsIndexed(feedState, key = { _, item -> "Local" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "Local_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip37/PrivateOutboxRelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip37/PrivateOutboxRelayListView.kt index a372d7286b..152cbf371b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip37/PrivateOutboxRelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip37/PrivateOutboxRelayListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder @@ -68,15 +68,21 @@ fun LazyListScope.renderPrivateOutboxItems( nav: INav, countResults: Map = emptyMap(), ) { - itemsIndexed(feedState, key = { _, item -> "Outbox" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - countResult = countResults[item.relay], - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "Outbox_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + countResult = countResults[item.relay], + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListView.kt index 73c201b6bd..efa1a3ce6c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder @@ -111,15 +111,21 @@ fun LazyListScope.renderNip65HomeItems( nav: INav, countResults: Map = emptyMap(), ) { - itemsIndexed(feedState, key = { _, item -> "Nip65Home" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteHomeRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - countResult = countResults[item.relay], - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "Nip65Home_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveHomeRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteHomeRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + countResult = countResults[item.relay], + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { @@ -139,15 +145,21 @@ fun LazyListScope.renderNip65NotifItems( nav: INav, countResults: Map = emptyMap(), ) { - itemsIndexed(feedState, key = { _, item -> "Nip65Notif" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteNotifRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - countResult = countResults[item.relay], - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "Nip65Notif_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveNotifRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteNotifRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + countResult = countResults[item.relay], + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListViewModel.kt index 36e7258212..0313bcff5f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListViewModel.kt @@ -215,6 +215,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 +244,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, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/proxy/ProxyRelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/proxy/ProxyRelayListView.kt index a737641f2f..b3e2cbe60c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/proxy/ProxyRelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/proxy/ProxyRelayListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder @@ -69,15 +69,21 @@ fun LazyListScope.renderProxyItems( nav: INav, countResults: Map = emptyMap(), ) { - itemsIndexed(feedState, key = { _, item -> "Proxy" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - countResult = countResults[item.relay], - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "Proxy_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + countResult = countResults[item.relay], + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/search/SearchRelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/search/SearchRelayListView.kt index 1077d42e2d..aa01622f39 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/search/SearchRelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/search/SearchRelayListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder @@ -69,15 +69,21 @@ fun LazyListScope.renderSearchItems( nav: INav, countResults: Map = emptyMap(), ) { - itemsIndexed(feedState, key = { _, item -> "Search" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - countResult = countResults[item.relay], - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "Search_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + countResult = countResults[item.relay], + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/trusted/TrustedRelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/trusted/TrustedRelayListView.kt index f8e0e305e5..e1ec3bad4a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/trusted/TrustedRelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/trusted/TrustedRelayListView.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -35,6 +34,7 @@ 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.DraggableRelayList 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.theme.FeedPadding @@ -66,14 +66,20 @@ fun LazyListScope.renderTrustedItems( accountViewModel: AccountViewModel, nav: INav, ) { - itemsIndexed(feedState, key = { _, item -> "Trusted" + item.relay.url }) { index, item -> - BasicRelaySetupInfoDialog( - item, - onDelete = { postViewModel.deleteRelay(item) }, - nip11CachedRetriever = Amethyst.instance.nip11Cache, - accountViewModel = accountViewModel, - nav = nav, - ) + item(key = "Trusted_draggable_list") { + DraggableRelayList( + items = feedState, + onMove = { from, to -> postViewModel.moveRelay(from, to) }, + ) { _, item, dragModifier -> + BasicRelaySetupInfoDialog( + item, + onDelete = { postViewModel.deleteRelay(item) }, + nip11CachedRetriever = Amethyst.instance.nip11Cache, + dragModifier = dragModifier, + accountViewModel = accountViewModel, + nav = nav, + ) + } } item { diff --git a/amethyst/src/main/res/values/strings.xml b/amethyst/src/main/res/values/strings.xml index 55325cc715..49f9534a7b 100644 --- a/amethyst/src/main/res/values/strings.xml +++ b/amethyst/src/main/res/values/strings.xml @@ -1506,6 +1506,7 @@ DM Upload Relay Settings + Reorder relay Public Outbox/Home Relays User is posting his content to these relays 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.