Move relay dialog to a route

This commit is contained in:
greenart7c3
2024-12-07 11:17:38 -03:00
parent 15b527c58d
commit a93910f8cb
6 changed files with 187 additions and 175 deletions

View File

@@ -37,6 +37,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
@@ -45,8 +46,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.vitorpamplona.amethyst.R
@@ -66,20 +65,25 @@ import com.vitorpamplona.amethyst.ui.theme.grayText
import com.vitorpamplona.ammolite.relays.Constants
import com.vitorpamplona.ammolite.relays.RelayStat
object RelayToAdd {
var relayToAdd: String = ""
}
@Composable
fun AllRelayListView(
onClose: () -> Unit,
relayToAdd: String = "",
accountViewModel: AccountViewModel,
nav: INav,
) {
MappedAllRelayListView(onClose, relayToAdd, accountViewModel, rememberExtendedNav(nav, onClose))
DisposableEffect(Unit) {
onDispose { RelayToAdd.relayToAdd = "" }
}
MappedAllRelayListView(RelayToAdd.relayToAdd, accountViewModel, rememberExtendedNav(nav, {}))
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MappedAllRelayListView(
onClose: () -> Unit,
relayToAdd: String = "",
accountViewModel: AccountViewModel,
newNav: INav,
@@ -113,10 +117,6 @@ fun MappedAllRelayListView(
privateOutboxViewModel.load(accountViewModel.account)
}
Dialog(
onDismissRequest = onClose,
properties = DialogProperties(usePlatformDefaultWidth = false),
) {
Scaffold(
topBar = {
TopAppBar(
@@ -145,7 +145,7 @@ fun MappedAllRelayListView(
searchViewModel.create()
localViewModel.create()
privateOutboxViewModel.create()
onClose()
newNav.popBack()
},
true,
)
@@ -162,7 +162,7 @@ fun MappedAllRelayListView(
searchViewModel.clear()
localViewModel.clear()
privateOutboxViewModel.clear()
onClose()
newNav.popBack()
},
)
}
@@ -263,7 +263,6 @@ fun MappedAllRelayListView(
}
}
}
}
}
@Composable

View File

@@ -49,6 +49,7 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ui.MainActivity
import com.vitorpamplona.amethyst.ui.actions.relays.AllRelayListView
import com.vitorpamplona.amethyst.ui.components.DisplayErrorMessages
import com.vitorpamplona.amethyst.ui.components.DisplayNotifyMessages
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
@@ -320,6 +321,16 @@ fun AppNavigation(
nav = nav,
)
}
composable(
Route.EditRelays.route,
content = {
AllRelayListView(
accountViewModel = accountViewModel,
nav = nav,
)
},
)
}
}

View File

@@ -89,7 +89,6 @@ import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.FeatureSetType
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.actions.mediaServers.MediaServersListView
import com.vitorpamplona.amethyst.ui.actions.relays.AllRelayListView
import com.vitorpamplona.amethyst.ui.components.ClickableText
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
@@ -437,7 +436,6 @@ fun ListContent(
) {
val route = remember(accountViewModel) { "User/${accountViewModel.userProfile().pubkeyHex}" }
var wantsToEditRelays by remember { mutableStateOf(false) }
var editMediaServers by remember { mutableStateOf(false) }
var backupDialogOpen by remember { mutableStateOf(false) }
@@ -475,7 +473,7 @@ fun ListContent(
accountViewModel = accountViewModel,
onClick = {
nav.closeDrawer()
wantsToEditRelays = true
nav.nav(Route.EditRelays.route)
},
)
@@ -537,9 +535,6 @@ fun ListContent(
)
}
if (wantsToEditRelays) {
AllRelayListView({ wantsToEditRelays = false }, accountViewModel = accountViewModel, nav = nav)
}
if (editMediaServers) {
MediaServersListView({ editMediaServers = false }, accountViewModel = accountViewModel, nav = nav)
}

View File

@@ -68,6 +68,13 @@ sealed class Route(
contentDescriptor = R.string.route_global,
)
object EditRelays :
Route(
route = "EditRelays",
icon = R.drawable.ic_globe,
contentDescriptor = R.string.relays,
)
object Search :
Route(
route = "Search",

View File

@@ -45,9 +45,10 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.ui.actions.relays.AllRelayListView
import com.vitorpamplona.amethyst.ui.actions.relays.RelayToAdd
import com.vitorpamplona.amethyst.ui.components.ShowMoreButton
import com.vitorpamplona.amethyst.ui.navigation.INav
import com.vitorpamplona.amethyst.ui.navigation.Route
import com.vitorpamplona.amethyst.ui.note.AddRelayButton
import com.vitorpamplona.amethyst.ui.note.RemoveRelayButton
import com.vitorpamplona.amethyst.ui.note.getGradient
@@ -289,15 +290,15 @@ private fun RelayOptionsAction(
}
}
var wantsToAddRelay by remember { mutableStateOf("") }
if (wantsToAddRelay.isNotEmpty()) {
AllRelayListView({ wantsToAddRelay = "" }, wantsToAddRelay, accountViewModel, nav = nav)
}
if (isCurrentlyOnTheUsersList) {
AddRelayButton { wantsToAddRelay = relay }
AddRelayButton {
RelayToAdd.relayToAdd = relay
nav.nav(Route.EditRelays.route)
}
} else {
RemoveRelayButton { wantsToAddRelay = relay }
RemoveRelayButton {
RelayToAdd.relayToAdd = relay
nav.nav(Route.EditRelays.route)
}
}
}

View File

@@ -26,13 +26,12 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.vitorpamplona.amethyst.ui.actions.relays.AllRelayListView
import com.vitorpamplona.amethyst.ui.actions.relays.RelayToAdd
import com.vitorpamplona.amethyst.ui.feeds.RefresheableBox
import com.vitorpamplona.amethyst.ui.navigation.INav
import com.vitorpamplona.amethyst.ui.navigation.Route
import com.vitorpamplona.amethyst.ui.note.RelayCompose
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
@@ -47,12 +46,6 @@ fun RelayFeedView(
) {
val feedState by viewModel.feedContent.collectAsStateWithLifecycle()
var wantsToAddRelay by remember { mutableStateOf("") }
if (wantsToAddRelay.isNotEmpty()) {
AllRelayListView({ wantsToAddRelay = "" }, wantsToAddRelay, accountViewModel, nav = nav)
}
RefresheableBox(viewModel, enablePullRefresh) {
val listState = rememberLazyListState()
@@ -64,8 +57,14 @@ fun RelayFeedView(
RelayCompose(
item,
accountViewModel = accountViewModel,
onAddRelay = { wantsToAddRelay = item.url },
onRemoveRelay = { wantsToAddRelay = item.url },
onAddRelay = {
RelayToAdd.relayToAdd = item.url
nav.nav(Route.EditRelays.route)
},
onRemoveRelay = {
RelayToAdd.relayToAdd = item.url
nav.nav(Route.EditRelays.route)
},
)
HorizontalDivider(
thickness = DividerThickness,