-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from samAricha/gemini_chat_navigation_plus
Gemini chat navigation plus
- Loading branch information
Showing
15 changed files
with
230 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 51 additions & 7 deletions
58
app/src/main/java/teka/android/organiks_platform_android/navigation/AppState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,71 @@ | ||
package teka.android.organiks_platform_android.navigation | ||
|
||
import android.content.res.Resources | ||
import androidx.compose.material.ScaffoldState | ||
import androidx.compose.material.rememberScaffoldState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.navigation.NavBackStackEntry | ||
import androidx.navigation.NavDestination | ||
import androidx.navigation.NavGraph | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.currentBackStackEntryAsState | ||
import androidx.navigation.compose.rememberNavController | ||
import kotlinx.coroutines.CoroutineScope | ||
|
||
@Composable | ||
fun rememberAppState( | ||
navHostController: NavHostController = rememberNavController() | ||
) = remember(navHostController) { | ||
AppState(navHostController) | ||
scaffoldState: ScaffoldState = rememberScaffoldState(), | ||
navHostController: NavHostController, | ||
coroutineScope: CoroutineScope = rememberCoroutineScope() | ||
) = remember(scaffoldState, navHostController, coroutineScope) { | ||
AppState(scaffoldState, navHostController, coroutineScope) | ||
} | ||
|
||
@Stable | ||
class AppState( | ||
val navHostController: NavHostController | ||
val scaffoldState: ScaffoldState, | ||
val navHostController: NavHostController, | ||
coroutineScope: CoroutineScope | ||
) { | ||
|
||
private val routes = BottomBarRoutes.values().map { it.routes } | ||
private val bottomBarRoutes = BottomBarRoutes.values().map { it.routes } | ||
|
||
val shouldShowBottomBar: Boolean | ||
@Composable get() = | ||
navHostController.currentBackStackEntryAsState().value?.destination?.route in routes | ||
navHostController.currentBackStackEntryAsState().value?.destination?.route in bottomBarRoutes | ||
|
||
|
||
val currentRoute: String? | ||
get() = navHostController.currentDestination?.route | ||
|
||
fun upPress() { | ||
navHostController.navigateUp() | ||
} | ||
|
||
fun navigateToBottomBarRoute(route: String) { | ||
if (route != currentRoute) { | ||
navHostController.navigate(route) { | ||
launchSingleTop = true | ||
restoreState = true | ||
popUpTo(findStartDestination(navHostController.graph).id) { | ||
saveState = true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
private fun NavBackStackEntry.lifecycleIsResumed() = | ||
this.lifecycle.currentState == Lifecycle.State.RESUMED | ||
|
||
private val NavGraph.startDestination: NavDestination? | ||
get() = findNode(startDestinationId) | ||
|
||
private tailrec fun findStartDestination(graph: NavDestination): NavDestination { | ||
return if (graph is NavGraph) findStartDestination(graph.startDestination!!) else graph | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.