mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-05 21:52:52 +02:00
Move relay dialog to a route
This commit is contained in:
@@ -37,6 +37,7 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.setValue
|
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.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
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.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.vitorpamplona.amethyst.R
|
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.Constants
|
||||||
import com.vitorpamplona.ammolite.relays.RelayStat
|
import com.vitorpamplona.ammolite.relays.RelayStat
|
||||||
|
|
||||||
|
object RelayToAdd {
|
||||||
|
var relayToAdd: String = ""
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AllRelayListView(
|
fun AllRelayListView(
|
||||||
onClose: () -> Unit,
|
|
||||||
relayToAdd: String = "",
|
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: INav,
|
nav: INav,
|
||||||
) {
|
) {
|
||||||
MappedAllRelayListView(onClose, relayToAdd, accountViewModel, rememberExtendedNav(nav, onClose))
|
DisposableEffect(Unit) {
|
||||||
|
onDispose { RelayToAdd.relayToAdd = "" }
|
||||||
|
}
|
||||||
|
|
||||||
|
MappedAllRelayListView(RelayToAdd.relayToAdd, accountViewModel, rememberExtendedNav(nav, {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun MappedAllRelayListView(
|
fun MappedAllRelayListView(
|
||||||
onClose: () -> Unit,
|
|
||||||
relayToAdd: String = "",
|
relayToAdd: String = "",
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
newNav: INav,
|
newNav: INav,
|
||||||
@@ -113,10 +117,6 @@ fun MappedAllRelayListView(
|
|||||||
privateOutboxViewModel.load(accountViewModel.account)
|
privateOutboxViewModel.load(accountViewModel.account)
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog(
|
|
||||||
onDismissRequest = onClose,
|
|
||||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
|
||||||
) {
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
@@ -145,7 +145,7 @@ fun MappedAllRelayListView(
|
|||||||
searchViewModel.create()
|
searchViewModel.create()
|
||||||
localViewModel.create()
|
localViewModel.create()
|
||||||
privateOutboxViewModel.create()
|
privateOutboxViewModel.create()
|
||||||
onClose()
|
newNav.popBack()
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
@@ -162,7 +162,7 @@ fun MappedAllRelayListView(
|
|||||||
searchViewModel.clear()
|
searchViewModel.clear()
|
||||||
localViewModel.clear()
|
localViewModel.clear()
|
||||||
privateOutboxViewModel.clear()
|
privateOutboxViewModel.clear()
|
||||||
onClose()
|
newNav.popBack()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,6 @@ fun MappedAllRelayListView(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@@ -49,6 +49,7 @@ import androidx.navigation.compose.NavHost
|
|||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ui.MainActivity
|
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.DisplayErrorMessages
|
||||||
import com.vitorpamplona.amethyst.ui.components.DisplayNotifyMessages
|
import com.vitorpamplona.amethyst.ui.components.DisplayNotifyMessages
|
||||||
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
|
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
|
||||||
@@ -320,6 +321,16 @@ fun AppNavigation(
|
|||||||
nav = nav,
|
nav = nav,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
Route.EditRelays.route,
|
||||||
|
content = {
|
||||||
|
AllRelayListView(
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
nav = nav,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -89,7 +89,6 @@ import com.vitorpamplona.amethyst.model.Account
|
|||||||
import com.vitorpamplona.amethyst.model.FeatureSetType
|
import com.vitorpamplona.amethyst.model.FeatureSetType
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.ui.actions.mediaServers.MediaServersListView
|
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.ClickableText
|
||||||
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
|
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
|
||||||
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
||||||
@@ -437,7 +436,6 @@ fun ListContent(
|
|||||||
) {
|
) {
|
||||||
val route = remember(accountViewModel) { "User/${accountViewModel.userProfile().pubkeyHex}" }
|
val route = remember(accountViewModel) { "User/${accountViewModel.userProfile().pubkeyHex}" }
|
||||||
|
|
||||||
var wantsToEditRelays by remember { mutableStateOf(false) }
|
|
||||||
var editMediaServers by remember { mutableStateOf(false) }
|
var editMediaServers by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
var backupDialogOpen by remember { mutableStateOf(false) }
|
var backupDialogOpen by remember { mutableStateOf(false) }
|
||||||
@@ -475,7 +473,7 @@ fun ListContent(
|
|||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
onClick = {
|
onClick = {
|
||||||
nav.closeDrawer()
|
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) {
|
if (editMediaServers) {
|
||||||
MediaServersListView({ editMediaServers = false }, accountViewModel = accountViewModel, nav = nav)
|
MediaServersListView({ editMediaServers = false }, accountViewModel = accountViewModel, nav = nav)
|
||||||
}
|
}
|
||||||
|
@@ -68,6 +68,13 @@ sealed class Route(
|
|||||||
contentDescriptor = R.string.route_global,
|
contentDescriptor = R.string.route_global,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
object EditRelays :
|
||||||
|
Route(
|
||||||
|
route = "EditRelays",
|
||||||
|
icon = R.drawable.ic_globe,
|
||||||
|
contentDescriptor = R.string.relays,
|
||||||
|
)
|
||||||
|
|
||||||
object Search :
|
object Search :
|
||||||
Route(
|
Route(
|
||||||
route = "Search",
|
route = "Search",
|
||||||
|
@@ -45,9 +45,10 @@ import androidx.compose.ui.text.style.TextOverflow
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
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.components.ShowMoreButton
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.INav
|
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.AddRelayButton
|
||||||
import com.vitorpamplona.amethyst.ui.note.RemoveRelayButton
|
import com.vitorpamplona.amethyst.ui.note.RemoveRelayButton
|
||||||
import com.vitorpamplona.amethyst.ui.note.getGradient
|
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) {
|
if (isCurrentlyOnTheUsersList) {
|
||||||
AddRelayButton { wantsToAddRelay = relay }
|
AddRelayButton {
|
||||||
|
RelayToAdd.relayToAdd = relay
|
||||||
|
nav.nav(Route.EditRelays.route)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
RemoveRelayButton { wantsToAddRelay = relay }
|
RemoveRelayButton {
|
||||||
|
RelayToAdd.relayToAdd = relay
|
||||||
|
nav.nav(Route.EditRelays.route)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,13 +26,12 @@ import androidx.compose.foundation.lazy.rememberLazyListState
|
|||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
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.feeds.RefresheableBox
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.INav
|
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.note.RelayCompose
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
|
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
|
||||||
@@ -47,12 +46,6 @@ fun RelayFeedView(
|
|||||||
) {
|
) {
|
||||||
val feedState by viewModel.feedContent.collectAsStateWithLifecycle()
|
val feedState by viewModel.feedContent.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
var wantsToAddRelay by remember { mutableStateOf("") }
|
|
||||||
|
|
||||||
if (wantsToAddRelay.isNotEmpty()) {
|
|
||||||
AllRelayListView({ wantsToAddRelay = "" }, wantsToAddRelay, accountViewModel, nav = nav)
|
|
||||||
}
|
|
||||||
|
|
||||||
RefresheableBox(viewModel, enablePullRefresh) {
|
RefresheableBox(viewModel, enablePullRefresh) {
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
|
|
||||||
@@ -64,8 +57,14 @@ fun RelayFeedView(
|
|||||||
RelayCompose(
|
RelayCompose(
|
||||||
item,
|
item,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
onAddRelay = { wantsToAddRelay = item.url },
|
onAddRelay = {
|
||||||
onRemoveRelay = { wantsToAddRelay = item.url },
|
RelayToAdd.relayToAdd = item.url
|
||||||
|
nav.nav(Route.EditRelays.route)
|
||||||
|
},
|
||||||
|
onRemoveRelay = {
|
||||||
|
RelayToAdd.relayToAdd = item.url
|
||||||
|
nav.nav(Route.EditRelays.route)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
HorizontalDivider(
|
HorizontalDivider(
|
||||||
thickness = DividerThickness,
|
thickness = DividerThickness,
|
||||||
|
Reference in New Issue
Block a user