mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Support reloading main page
This commit is contained in:
parent
9e876a85d4
commit
1411859b7f
6 changed files with 22 additions and 7 deletions
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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(),
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue