Fixes the need to specify route in the check if navigation is going to the same route or not
This commit is contained in:
@@ -334,11 +334,11 @@ private fun NavigateIfIntentRequested(
|
||||
accountViewModel: AccountViewModel,
|
||||
accountStateViewModel: AccountStateViewModel,
|
||||
) {
|
||||
accountViewModel.firstRoute?.let {
|
||||
accountViewModel.firstRoute?.let { newRoute ->
|
||||
accountViewModel.firstRoute = null
|
||||
val currentRoute = getRouteWithArguments(nav.controller)
|
||||
if (!isSameRoute(currentRoute, it)) {
|
||||
nav.newStack(it)
|
||||
val currentRoute = getRouteWithArguments(newRoute::class, nav.controller)
|
||||
if (!isSameRoute(currentRoute, newRoute)) {
|
||||
nav.newStack(newRoute)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ private fun NavigateIfIntentRequested(
|
||||
if (npub != null && accountStateViewModel.currentAccountNPub() != npub) {
|
||||
accountStateViewModel.checkAndSwitchUserSync(npub, nextRoute)
|
||||
} else {
|
||||
val currentRoute = getRouteWithArguments(nav.controller)
|
||||
val currentRoute = getRouteWithArguments(nextRoute::class, nav.controller)
|
||||
if (!isSameRoute(currentRoute, nextRoute)) {
|
||||
nav.newStack(nextRoute)
|
||||
}
|
||||
@@ -445,7 +445,7 @@ private fun NavigateIfIntentRequested(
|
||||
if (npub != null && accountStateViewModel.currentAccountNPub() != npub) {
|
||||
accountStateViewModel.checkAndSwitchUserSync(npub, newPage)
|
||||
} else {
|
||||
val currentRoute = getRouteWithArguments(nav.controller)
|
||||
val currentRoute = getRouteWithArguments(newPage::class, nav.controller)
|
||||
if (!isSameRoute(currentRoute, newPage)) {
|
||||
nav.newStack(newPage)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class Nav(
|
||||
|
||||
override fun nav(route: Route) {
|
||||
navigationScope.launch {
|
||||
if (getRouteWithArguments(controller) != route) {
|
||||
if (getRouteWithArguments(route::class, controller) != route) {
|
||||
controller.navigate(route)
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class Nav(
|
||||
override fun nav(computeRoute: suspend () -> Route?) {
|
||||
navigationScope.launch {
|
||||
val route = computeRoute()
|
||||
if (route != null && getRouteWithArguments(controller) != route) {
|
||||
if (route != null && getRouteWithArguments(route::class, controller) != route) {
|
||||
controller.navigate(route)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.vitorpamplona.quartz.nip01Core.core.Address
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKey
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
sealed class Route {
|
||||
@Serializable object Home : Route()
|
||||
@@ -322,65 +323,17 @@ sealed class Route {
|
||||
|
||||
inline fun <reified T : Route> isBaseRoute(navController: NavHostController): Boolean = navController.currentBackStackEntry?.destination?.hasRoute<T>() == true
|
||||
|
||||
fun getRouteWithArguments(navController: NavHostController): Route? {
|
||||
fun <T : Route> getRouteWithArguments(
|
||||
klazz: KClass<T>,
|
||||
navController: NavHostController,
|
||||
): Route? {
|
||||
val entry = navController.currentBackStackEntry ?: return null
|
||||
val dest = entry.destination
|
||||
|
||||
return when {
|
||||
dest.hasRoute<Route.Home>() -> entry.toRoute<Route.Home>()
|
||||
dest.hasRoute<Route.Message>() -> entry.toRoute<Route.Message>()
|
||||
dest.hasRoute<Route.Video>() -> entry.toRoute<Route.Video>()
|
||||
dest.hasRoute<Route.Discover>() -> entry.toRoute<Route.Discover>()
|
||||
dest.hasRoute<Route.Notification>() -> entry.toRoute<Route.Notification>()
|
||||
dest.hasRoute<Route.Chess>() -> entry.toRoute<Route.Chess>()
|
||||
dest.hasRoute<Route.Search>() -> entry.toRoute<Route.Search>()
|
||||
dest.hasRoute<Route.SecurityFilters>() -> entry.toRoute<Route.SecurityFilters>()
|
||||
dest.hasRoute<Route.PrivacyOptions>() -> entry.toRoute<Route.PrivacyOptions>()
|
||||
dest.hasRoute<Route.Bookmarks>() -> entry.toRoute<Route.Bookmarks>()
|
||||
dest.hasRoute<Route.ContentDiscovery>() -> entry.toRoute<Route.ContentDiscovery>()
|
||||
dest.hasRoute<Route.Drafts>() -> entry.toRoute<Route.Drafts>()
|
||||
dest.hasRoute<Route.AllSettings>() -> entry.toRoute<Route.AllSettings>()
|
||||
dest.hasRoute<Route.AccountBackup>() -> entry.toRoute<Route.AccountBackup>()
|
||||
dest.hasRoute<Route.Settings>() -> entry.toRoute<Route.Settings>()
|
||||
dest.hasRoute<Route.EditProfile>() -> entry.toRoute<Route.EditProfile>()
|
||||
dest.hasRoute<Route.Profile>() -> entry.toRoute<Route.Profile>()
|
||||
dest.hasRoute<Route.Note>() -> entry.toRoute<Route.Note>()
|
||||
dest.hasRoute<Route.Hashtag>() -> entry.toRoute<Route.Hashtag>()
|
||||
dest.hasRoute<Route.Geohash>() -> entry.toRoute<Route.Geohash>()
|
||||
dest.hasRoute<Route.Community>() -> entry.toRoute<Route.Community>()
|
||||
dest.hasRoute<Route.QRDisplay>() -> entry.toRoute<Route.QRDisplay>()
|
||||
dest.hasRoute<Route.RelayInfo>() -> entry.toRoute<Route.RelayInfo>()
|
||||
dest.hasRoute<Route.RelayFeed>() -> entry.toRoute<Route.RelayFeed>()
|
||||
dest.hasRoute<Route.RoomByAuthor>() -> entry.toRoute<Route.RoomByAuthor>()
|
||||
dest.hasRoute<Route.PublicChatChannel>() -> entry.toRoute<Route.PublicChatChannel>()
|
||||
dest.hasRoute<Route.LiveActivityChannel>() -> entry.toRoute<Route.LiveActivityChannel>()
|
||||
dest.hasRoute<Route.ChannelMetadataEdit>() -> entry.toRoute<Route.ChannelMetadataEdit>()
|
||||
dest.hasRoute<Route.EphemeralChat>() -> entry.toRoute<Route.EphemeralChat>()
|
||||
dest.hasRoute<Route.NewEphemeralChat>() -> entry.toRoute<Route.NewEphemeralChat>()
|
||||
dest.hasRoute<Route.EventRedirect>() -> entry.toRoute<Route.EventRedirect>()
|
||||
dest.hasRoute<Route.EditRelays>() -> entry.toRoute<Route.EditRelays>()
|
||||
dest.hasRoute<Route.EditMediaServers>() -> entry.toRoute<Route.EditMediaServers>()
|
||||
dest.hasRoute<Route.UpdateReactionType>() -> entry.toRoute<Route.UpdateReactionType>()
|
||||
dest.hasRoute<Route.Nip47NWCSetup>() -> entry.toRoute<Route.Nip47NWCSetup>()
|
||||
dest.hasRoute<Route.UpdateZapAmount>() -> entry.toRoute<Route.UpdateZapAmount>()
|
||||
dest.hasRoute<Route.Room>() -> entry.toRoute<Route.Room>()
|
||||
dest.hasRoute<Route.NewShortNote>() -> entry.toRoute<Route.NewShortNote>()
|
||||
dest.hasRoute<Route.VoiceReply>() -> entry.toRoute<Route.VoiceReply>()
|
||||
dest.hasRoute<Route.NewProduct>() -> entry.toRoute<Route.NewProduct>()
|
||||
dest.hasRoute<Route.GeoPost>() -> entry.toRoute<Route.GeoPost>()
|
||||
dest.hasRoute<Route.HashtagPost>() -> entry.toRoute<Route.HashtagPost>()
|
||||
dest.hasRoute<Route.GenericCommentPost>() -> entry.toRoute<Route.GenericCommentPost>()
|
||||
dest.hasRoute<Route.NewPublicMessage>() -> entry.toRoute<Route.NewPublicMessage>()
|
||||
dest.hasRoute<Route.Lists>() -> entry.toRoute<Route.Lists>()
|
||||
dest.hasRoute<Route.MyPeopleListView>() -> entry.toRoute<Route.MyPeopleListView>()
|
||||
dest.hasRoute<Route.MyFollowPackView>() -> entry.toRoute<Route.MyFollowPackView>()
|
||||
dest.hasRoute<Route.PeopleListMetadataEdit>() -> entry.toRoute<Route.PeopleListMetadataEdit>()
|
||||
dest.hasRoute<Route.FollowPackMetadataEdit>() -> entry.toRoute<Route.FollowPackMetadataEdit>()
|
||||
dest.hasRoute<Route.PeopleListManagement>() -> entry.toRoute<Route.PeopleListManagement>()
|
||||
dest.hasRoute<Route.NewGroupDM>() -> entry.toRoute<Route.NewGroupDM>()
|
||||
dest.hasRoute<Route.UserSettings>() -> entry.toRoute<Route.UserSettings>()
|
||||
dest.hasRoute<Route.ManualZapSplitPayment>() -> entry.toRoute<Route.ManualZapSplitPayment>()
|
||||
else -> null
|
||||
return if (dest.hasRoute(klazz)) {
|
||||
entry.toRoute(klazz)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user