From e01ee18251bc90830875e3551d61e76d92c2b8a8 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 27 Nov 2023 04:46:50 +0100 Subject: [PATCH] add main activity and some screens --- .../memorisationapplication/HomeScreen.kt | 9 +++ .../memorisationapplication/MainActivity.kt | 63 ++++++++++++++++--- .../ModifySetScreen.kt | 9 +++ .../memorisationapplication/PlayScreen.kt | 9 +++ .../memorisationapplication/Routes.kt | 3 + 5 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/HomeScreen.kt create mode 100644 app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ModifySetScreen.kt create mode 100644 app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/PlayScreen.kt create mode 100644 app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/Routes.kt diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/HomeScreen.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/HomeScreen.kt new file mode 100644 index 0000000..08dda8f --- /dev/null +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/HomeScreen.kt @@ -0,0 +1,9 @@ +package fr.uparis.diamantkennel.memorisationapplication + +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.runtime.Composable + +@Composable +fun HomeScreen(padding: PaddingValues) { + +} diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/MainActivity.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/MainActivity.kt index 7d73016..2d71d70 100644 --- a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/MainActivity.kt +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/MainActivity.kt @@ -4,12 +4,27 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material.BottomNavigation +import androidx.compose.material.BottomNavigationItem +import androidx.compose.material.Icon +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Home +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview +import androidx.navigation.NavHostController +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import androidx.navigation.compose.currentBackStackEntryAsState +import androidx.navigation.compose.rememberNavController import fr.uparis.diamantkennel.memorisationapplication.ui.theme.MemorisationApplicationTheme class MainActivity : ComponentActivity() { @@ -22,7 +37,7 @@ class MainActivity : ComponentActivity() { modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background ) { - ScreenMainMainActivity() + MainScreenMainActivity() } } } @@ -30,18 +45,50 @@ class MainActivity : ComponentActivity() { } @Composable -fun ScreenMainMainActivity() { - MainMainActivity() +fun MainScreenMainActivity() { + MainScreen() } @Preview(showBackground = true) @Composable -fun ScreenMainActivityPreview() { - MainMainActivity() +fun MainScreenActivityPreview() { + MainScreen() } +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun MainScreen() { + val navController = rememberNavController() + + Scaffold(topBar = { TopBar() }, + bottomBar = { BottomBar(navController) }) { padding -> + NavHost( + navController = navController, + startDestination = HOME, + modifier = Modifier.padding(padding) + ) { + composable(HOME) { HomeScreen(padding) } + } + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun TopBar() = + TopAppBar(title = { + Text( + "Projet", + style = MaterialTheme.typography.displayMedium + ) + }) @Composable -fun MainMainActivity() { - Text("Hello world!") -} +fun BottomBar(navController: NavHostController) = + BottomNavigation(backgroundColor = MaterialTheme.colorScheme.primaryContainer) { + val navBackStackEntry by navController.currentBackStackEntryAsState() + val currentRoute = navBackStackEntry?.destination?.route + + BottomNavigationItem(selected = currentRoute == HOME, onClick = { + navController.navigate(HOME) { launchSingleTop = true } + }, icon = { Icon(Icons.Default.Home, "Page principale") }) + } diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ModifySetScreen.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ModifySetScreen.kt new file mode 100644 index 0000000..e2a1658 --- /dev/null +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ModifySetScreen.kt @@ -0,0 +1,9 @@ +package fr.uparis.diamantkennel.memorisationapplication + +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.runtime.Composable + +@Composable +fun ModifySetScreen(padding: PaddingValues) { + +} diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/PlayScreen.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/PlayScreen.kt new file mode 100644 index 0000000..3615eb9 --- /dev/null +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/PlayScreen.kt @@ -0,0 +1,9 @@ +package fr.uparis.diamantkennel.memorisationapplication + +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.runtime.Composable + +@Composable +fun PlayScreen(padding: PaddingValues) { + +} diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/Routes.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/Routes.kt new file mode 100644 index 0000000..049ccc9 --- /dev/null +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/Routes.kt @@ -0,0 +1,3 @@ +package fr.uparis.diamantkennel.memorisationapplication + +const val HOME = "home"