Support reloading main page

This commit is contained in:
Damontecres 2025-10-02 18:21:35 -04:00
parent 9e876a85d4
commit 1411859b7f
No known key found for this signature in database
6 changed files with 22 additions and 7 deletions

View file

@ -92,7 +92,7 @@ class MainActivity : AppCompatActivity() {
remember(appPreferences) {
createDeviceProfile(this@MainActivity, preferences, false)
}
val backStack = rememberNavBackStack(Destination.Main)
val backStack = rememberNavBackStack(Destination.Main())
val navigationManager = NavigationManager(backStack)
if (server != null && user != null) {

View file

@ -24,7 +24,7 @@ fun ApplicationContent(
) {
NavDisplay(
backStack = navigationManager.backStack,
onBack = { navigationManager.goBack() },
onBack = { repeat(it) { navigationManager.goBack() } },
entryDecorators =
listOf(
rememberSceneSetupNavEntryDecorator(),

View file

@ -26,7 +26,9 @@ sealed class Destination(
data object UserList : Destination(true)
@Serializable
data object Main : Destination()
data class Main(
val id: Long = 0L,
) : Destination()
@Serializable
data object Settings : Destination(true)

View file

@ -29,7 +29,7 @@ fun DestinationContent(
modifier: Modifier = Modifier,
) {
when (destination) {
Destination.Main ->
is Destination.Main ->
MainPage(
preferences = preferences,
navigationManager = navigationManager,

View file

@ -136,7 +136,13 @@ fun NavDrawer(
IconNavItem(
text = "Home",
icon = Icons.Default.Home,
onClick = { navigationManager.goToHome() },
onClick = {
if (destination is Destination.Main) {
navigationManager.reloadHome()
} else {
navigationManager.goToHome()
}
},
)
LazyColumn(
state = listState,

View file

@ -15,7 +15,14 @@ class NavigationManager(
}
fun goToHome() {
backStack.clear()
backStack.add(Destination.Main)
while (backStack.size > 1) {
backStack.removeLastOrNull()
}
}
fun reloadHome() {
goToHome()
val id = (backStack[0] as Destination.Main).id + 1
backStack[0] = Destination.Main(id)
}
}