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
This commit is contained in:
Claude
2026-04-06 15:10:33 +00:00
parent 2e3de795b6
commit ce11edc352
17 changed files with 387 additions and 114 deletions
@@ -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 {
@@ -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 {
@@ -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(
@@ -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,
@@ -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
@@ -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<BasicRelaySetupInfo>,
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<Int, Float>() }
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)
}
}
}
}
@@ -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<NormalizedRelayUrl, RelayCountResult> = 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 {
@@ -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 {
@@ -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<NormalizedRelayUrl, RelayCountResult> = 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 {
@@ -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 {
@@ -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<NormalizedRelayUrl, RelayCountResult> = 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 {
@@ -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<NormalizedRelayUrl, RelayCountResult> = 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<NormalizedRelayUrl, RelayCountResult> = 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 {
@@ -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,
@@ -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<NormalizedRelayUrl, RelayCountResult> = 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 {
@@ -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<NormalizedRelayUrl, RelayCountResult> = 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 {
@@ -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 {
+1
View File
@@ -1506,6 +1506,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 13 relays. They can be personal relays, paid relays or public relays.</string>