-
Notifications
You must be signed in to change notification settings - Fork 4
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 #170 from muedsa/migrating-tv-foundation
Compose for tv beta migration
- Loading branch information
Showing
61 changed files
with
979 additions
and
831 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
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 was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
app/src/main/kotlin/com/muedsa/agetv/screens/AppNavigation.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,98 @@ | ||
package com.muedsa.agetv.screens | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.NavType | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.dialog | ||
import androidx.navigation.compose.rememberNavController | ||
import androidx.navigation.navArgument | ||
import com.muedsa.agetv.screens.detail.AnimeDetailScreen | ||
import com.muedsa.agetv.screens.home.HomeNavScreen | ||
import com.muedsa.agetv.screens.setting.AppSettingScreen | ||
import com.muedsa.compose.tv.LocalNavHostControllerProvider | ||
import com.muedsa.compose.tv.LocalRightSideDrawerControllerProvider | ||
import com.muedsa.compose.tv.widget.FullWidthDialogProperties | ||
import com.muedsa.compose.tv.widget.RightSideDrawerWithNavController | ||
import com.muedsa.compose.tv.widget.RightSideDrawerWithNavDrawerContent | ||
|
||
@Composable | ||
fun AppNavigation(navController: NavHostController = rememberNavController()) { | ||
|
||
val viewModelStoreOwner = checkNotNull(LocalViewModelStoreOwner.current) { | ||
"No ViewModelStoreOwner was provided via LocalViewModelStoreOwner" | ||
} | ||
|
||
val drawerController = | ||
RightSideDrawerWithNavController(navController, NavigationItems.RightSideDrawer.path) | ||
|
||
LocalNavHostControllerProvider(navController) { | ||
LocalRightSideDrawerControllerProvider(drawerController) { | ||
NavHost( | ||
navController = navController, | ||
startDestination = buildRoute(NavigationItems.Home, listOf("0")) | ||
) { | ||
|
||
composable( | ||
route = NavigationItems.Home.path, | ||
arguments = listOf(navArgument("tabIndex") { | ||
type = NavType.IntType | ||
}) | ||
) { | ||
HomeNavScreen( | ||
tabIndex = checkNotNull(it.arguments?.getInt("tabIndex")), | ||
mainScreenViewModel = hiltViewModel(viewModelStoreOwner), | ||
) | ||
} | ||
|
||
composable( | ||
route = NavigationItems.Detail.path, | ||
arguments = listOf(navArgument("animeId") { | ||
type = NavType.StringType | ||
}) | ||
) { | ||
AnimeDetailScreen() | ||
} | ||
|
||
dialog( | ||
route = NavigationItems.Setting.path, | ||
dialogProperties = FullWidthDialogProperties() | ||
) { | ||
AppSettingScreen() | ||
} | ||
|
||
dialog( | ||
route = NavigationItems.RightSideDrawer.path, | ||
dialogProperties = FullWidthDialogProperties() | ||
) { | ||
RightSideDrawerWithNavDrawerContent(controller = drawerController) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun buildRoute( | ||
navItem: NavigationItems, | ||
pathParams: List<String>? | ||
): String { | ||
var route = navItem.path | ||
if (!navItem.pathParams.isNullOrEmpty()) { | ||
checkNotNull(pathParams) | ||
check(pathParams.size == navItem.pathParams.size) | ||
for (i in 0 until navItem.pathParams.size) { | ||
route = route.replace(navItem.pathParams[i], pathParams[i]) | ||
} | ||
} | ||
return route | ||
} | ||
|
||
fun NavHostController.navigate( | ||
navItem: NavigationItems, | ||
pathParams: List<String>? | ||
) { | ||
navigate(buildRoute(navItem, pathParams)) | ||
} |
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.