-
Notifications
You must be signed in to change notification settings - Fork 1
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 #14 from LookUpGroup27/feature/general-navigation
feat: add navigation setup and actions
- Loading branch information
Showing
9 changed files
with
339 additions
and
138 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
100 changes: 100 additions & 0 deletions
100
app/src/main/java/com/github/lookupgroup27/lookup/ui/navigation/NavigationActions.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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.github.lookupgroup27.lookup.ui.navigation | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.DateRange | ||
import androidx.compose.material.icons.outlined.Place | ||
import androidx.compose.material.icons.outlined.PlayArrow | ||
import androidx.compose.material.icons.outlined.Star | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.navigation.NavGraph.Companion.findStartDestination | ||
import androidx.navigation.NavHostController | ||
|
||
object Route { | ||
const val MAP = "Map" | ||
const val CALENDAR = "Calendar" | ||
const val SKY_TRACKER = "SkyTracker" | ||
const val QUIZ = "Quiz" | ||
const val PROFILE = "Profile" | ||
const val MENU = "Menu" | ||
const val COLLECTION = "Collection" | ||
} | ||
|
||
object Screen { | ||
const val MAP = "Map Screen" | ||
const val CALENDAR = "Calendar Screen" | ||
const val SKY_TRACKER = "Sky Tracker Screen" | ||
const val QUIZ = "Quiz Screen" | ||
const val PROFILE = "Profile Screen" | ||
const val MENU = "Menu Screen" | ||
const val COLLECTION = "Collection Screen" | ||
} | ||
|
||
data class TopLevelDestination(val route: String, val icon: ImageVector, val textId: String) | ||
|
||
object TopLevelDestinations { | ||
val MAP = TopLevelDestination(route = Route.MAP, icon = Icons.Outlined.Place, textId = "Map") | ||
val CALENDAR = | ||
TopLevelDestination( | ||
route = Route.CALENDAR, icon = Icons.Outlined.DateRange, textId = "Calendar") | ||
val SKY_TRACKER = | ||
TopLevelDestination( | ||
route = Route.SKY_TRACKER, icon = Icons.Outlined.Star, textId = "Sky Tracker") | ||
val QUIZ = | ||
TopLevelDestination(route = Route.QUIZ, icon = Icons.Outlined.PlayArrow, textId = "Quiz") | ||
} | ||
|
||
val LIST_TOP_LEVEL_DESTINATION = | ||
listOf( | ||
TopLevelDestinations.MAP, | ||
TopLevelDestinations.CALENDAR, | ||
TopLevelDestinations.SKY_TRACKER, | ||
TopLevelDestinations.QUIZ) | ||
|
||
open class NavigationActions( | ||
private val navController: NavHostController, | ||
) { | ||
/** | ||
* Navigate to the specified [TopLevelDestination]. | ||
* | ||
* @param destination The top-level destination to navigate to. Clear the back stack when | ||
* navigating to a new destination. | ||
*/ | ||
open fun navigateTo(destination: TopLevelDestination) { | ||
navController.navigate(destination.route) { | ||
// Pop up to the start destination of the graph to avoid stacking destinations. | ||
popUpTo(navController.graph.findStartDestination().id) { | ||
saveState = true | ||
inclusive = true | ||
} | ||
|
||
// Avoid multiple copies of the same destination. | ||
launchSingleTop = true | ||
|
||
// Restore state when reselecting a previously selected item. | ||
restoreState = true | ||
} | ||
} | ||
|
||
/** | ||
* Navigate to the specified screen. | ||
* | ||
* @param screen The screen to navigate to. | ||
*/ | ||
open fun navigateTo(screen: String) { | ||
navController.navigate(screen) | ||
} | ||
|
||
/** Navigate back to the previous screen. */ | ||
open fun goBack() { | ||
navController.popBackStack() | ||
} | ||
|
||
/** | ||
* Get the current route of the navigation controller. | ||
* | ||
* @return The current route. | ||
*/ | ||
open fun currentRoute(): String { | ||
return navController.currentDestination?.route ?: "" | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
app/src/test/java/com/github/lookupgroup27/lookup/ExampleRobolectricTest.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
app/src/test/java/com/github/lookupgroup27/lookup/ExampleUnitTest.kt
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
app/src/test/java/com/github/lookupgroup27/lookup/PointTest.kt
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
app/src/test/java/com/github/lookupgroup27/lookup/screen/SecondScreen.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.