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) { remember(appPreferences) {
createDeviceProfile(this@MainActivity, preferences, false) createDeviceProfile(this@MainActivity, preferences, false)
} }
val backStack = rememberNavBackStack(Destination.Main) val backStack = rememberNavBackStack(Destination.Main())
val navigationManager = NavigationManager(backStack) val navigationManager = NavigationManager(backStack)
if (server != null && user != null) { if (server != null && user != null) {

View file

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

View file

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

View file

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

View file

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

View file

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