mirror of
https://github.com/owenlejeune/TVTime.git
synced 2025-11-08 12:42:44 -05:00
refactor auth navigation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.owenlejeune.tvtime
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.animation.rememberSplineBasedDecay
|
||||
import androidx.compose.foundation.layout.*
|
||||
@@ -39,6 +40,7 @@ import com.owenlejeune.tvtime.ui.screens.SearchScreen
|
||||
import com.owenlejeune.tvtime.ui.screens.main.*
|
||||
import com.owenlejeune.tvtime.ui.theme.TVTimeTheme
|
||||
import com.owenlejeune.tvtime.utils.KeyboardManager
|
||||
import com.owenlejeune.tvtime.utils.NavConstants
|
||||
import com.owenlejeune.tvtime.utils.SessionManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -55,12 +57,7 @@ class MainActivity : MonetCompatActivity() {
|
||||
SessionManager.initialize()
|
||||
}
|
||||
|
||||
var mainNavStartRoute = BottomNavItem.SortedItems[0].route
|
||||
intent.data?.let {
|
||||
when (it.host) {
|
||||
getString(R.string.intent_route_auth_return) -> mainNavStartRoute = BottomNavItem.SIGN_IN_PART_2_ROUTE
|
||||
}
|
||||
}
|
||||
val mainNavStartRoute = BottomNavItem.SortedItems[0].route
|
||||
|
||||
lifecycleScope.launchWhenCreated {
|
||||
monet.awaitMonetReady()
|
||||
@@ -179,7 +176,7 @@ class MainActivity : MonetCompatActivity() {
|
||||
|
||||
NavigationBar {
|
||||
BottomNavItem.SortedItems.forEach { item ->
|
||||
val isSelected = currentRoute == item.route || item.alternateRoutes.contains(currentRoute ?: "")
|
||||
val isSelected = currentRoute == item.route
|
||||
NavigationBarItem(
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
@@ -215,11 +212,7 @@ class MainActivity : MonetCompatActivity() {
|
||||
|
||||
private fun navigateToRoute(navController: NavController, route: String) {
|
||||
navController.navigate(route) {
|
||||
navController.graph.startDestinationRoute?.let { screenRoute ->
|
||||
popUpTo(screenRoute) {
|
||||
saveState = true
|
||||
}
|
||||
}
|
||||
popUpTo(route)
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
@@ -295,7 +288,7 @@ class MainActivity : MonetCompatActivity() {
|
||||
NavigationRail {
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
BottomNavItem.SortedItems.forEachIndexed { index, item ->
|
||||
val isSelected = currentRoute == item.route || item.alternateRoutes.contains(currentRoute ?: "")
|
||||
val isSelected = currentRoute == item.route
|
||||
NavigationRailItem(
|
||||
icon = { Icon(painter = painterResource(id = item.icon), contentDescription = null) },
|
||||
label = { if (preferences.showBottomTabLabels) Text(item.name) },
|
||||
@@ -360,14 +353,6 @@ class MainActivity : MonetCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private object NavConstants {
|
||||
const val ID_KEY = "id_key"
|
||||
const val TYPE_KEY = "type_key"
|
||||
const val SETTINGS_KEY = "settings_key"
|
||||
const val SEARCH_ID_KEY = "search_key"
|
||||
const val SEARCH_TITLE_KEY = "search_title_key"
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MainNavigationRoutes(
|
||||
startDestination: String = MainNavItem.MainView.route,
|
||||
|
||||
@@ -11,8 +11,7 @@ sealed class BottomNavItem(
|
||||
val icon: Int,
|
||||
val route: String,
|
||||
private val orderGetter: (AppPreferences) -> Int,
|
||||
private val orderSetter: (AppPreferences, Int) -> Unit,
|
||||
val alternateRoutes: List<String> = emptyList()
|
||||
private val orderSetter: (AppPreferences, Int) -> Unit
|
||||
): KoinComponent {
|
||||
|
||||
private val appPreferences: AppPreferences by inject()
|
||||
@@ -25,8 +24,6 @@ sealed class BottomNavItem(
|
||||
|
||||
companion object {
|
||||
|
||||
const val SIGN_IN_PART_2_ROUTE = "sign_in_part_two_route"
|
||||
|
||||
val SortedItems
|
||||
get() = Items.filter { it.order > -1 }.sortedBy { it.order }.ifEmpty { Items }
|
||||
|
||||
@@ -46,7 +43,7 @@ sealed class BottomNavItem(
|
||||
|
||||
object Movies: BottomNavItem(R.string.nav_movies_title, R.drawable.ic_movie, "movies_route", { it.moviesTabPosition }, { p, i -> p.moviesTabPosition = i } )
|
||||
object TV: BottomNavItem(R.string.nav_tv_title, R.drawable.ic_tv, "tv_route", { it.tvTabPosition }, { p, i -> p.tvTabPosition = i } )
|
||||
object Account: BottomNavItem(R.string.nav_account_title, R.drawable.ic_person, "account_route", { it.accountTabPosition }, { p, i -> p.accountTabPosition = i }, listOf(SIGN_IN_PART_2_ROUTE) )
|
||||
object Account: BottomNavItem(R.string.nav_account_title, R.drawable.ic_person, "account_route", { it.accountTabPosition }, { p, i -> p.accountTabPosition = i } )
|
||||
object People: BottomNavItem(R.string.nav_people_title, R.drawable.ic_face, "people_route", { it.peopleTabPosition }, { p, i -> p.peopleTabPosition = i } )
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.owenlejeune.tvtime.ui.navigation
|
||||
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -10,13 +11,10 @@ import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navArgument
|
||||
import androidx.navigation.navDeepLink
|
||||
import com.owenlejeune.tvtime.ui.screens.main.MediaViewType
|
||||
import com.owenlejeune.tvtime.ui.screens.main.*
|
||||
|
||||
object NavConstants {
|
||||
const val ID_KEY = "id_key"
|
||||
const val TYPE_KEY = "type_key"
|
||||
}
|
||||
import com.owenlejeune.tvtime.utils.NavConstants
|
||||
|
||||
@Composable
|
||||
fun MainNavGraph(
|
||||
@@ -47,20 +45,18 @@ fun MainNavGraph(
|
||||
fab = fab
|
||||
)
|
||||
}
|
||||
composable(BottomNavItem.Account.route) {
|
||||
AccountTab(
|
||||
appBarTitle = appBarTitle,
|
||||
appNavController = appNavController,
|
||||
appBarActions = appBarActions
|
||||
composable(
|
||||
route = BottomNavItem.Account.route,
|
||||
deepLinks = listOf(
|
||||
navDeepLink { uriPattern = "app://tvtime.auth.{${NavConstants.ACCOUNT_KEY}}" }
|
||||
)
|
||||
fab.value = {}
|
||||
}
|
||||
composable(BottomNavItem.SIGN_IN_PART_2_ROUTE) {
|
||||
) {
|
||||
val deepLink = it.arguments?.getString(NavConstants.ACCOUNT_KEY)
|
||||
AccountTab(
|
||||
appBarTitle = appBarTitle,
|
||||
appNavController = appNavController,
|
||||
appBarActions = appBarActions,
|
||||
doSignInPartTwo = true
|
||||
doSignInPartTwo = deepLink == NavConstants.AUTH_REDIRECT_PAGE
|
||||
)
|
||||
fab.value = {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.owenlejeune.tvtime.utils
|
||||
|
||||
object NavConstants {
|
||||
const val ID_KEY = "id_key"
|
||||
const val TYPE_KEY = "type_key"
|
||||
const val SETTINGS_KEY = "settings_key"
|
||||
const val SEARCH_ID_KEY = "search_key"
|
||||
const val SEARCH_TITLE_KEY = "search_title_key"
|
||||
const val ACCOUNT_KEY = "account_key"
|
||||
const val AUTH_REDIRECT_PAGE = "return"
|
||||
}
|
||||
Reference in New Issue
Block a user