From d580bbbb1f54feb3a9c6eea98ec46ec744812b95 Mon Sep 17 00:00:00 2001 From: Emma Vandewalle Date: Thu, 25 Jul 2024 18:40:04 +0000 Subject: [PATCH] feat: setup of navigation and main screens files --- app/build.gradle | 2 + .../main/java/be/re/writand/MainActivity.kt | 22 ++---- .../main/java/be/re/writand/navigation/.keep | 0 .../re/writand/navigation/WAppDestinations.kt | 21 ++++++ .../be/re/writand/navigation/WNavGraph.kt | 68 +++++++++++++++++++ .../re/writand/screens/editor/EditorScreen.kt | 11 +++ .../projectpicker/ProjectPickerScreen.kt | 23 +++++++ .../re/writand/screens/splash/SplashScreen.kt | 25 +++++++ .../writand/screens/splash/SplashViewModel.kt | 4 ++ .../screens/welcome/WelcomeSettingsScreen.kt | 24 +++++++ .../screens/welcome/WelcomeStartScreen.kt | 24 +++++++ .../screens/welcome/WelcomeTOSScreen.kt | 24 +++++++ 12 files changed, 233 insertions(+), 15 deletions(-) delete mode 100644 app/src/main/java/be/re/writand/navigation/.keep create mode 100644 app/src/main/java/be/re/writand/navigation/WAppDestinations.kt create mode 100644 app/src/main/java/be/re/writand/navigation/WNavGraph.kt create mode 100644 app/src/main/java/be/re/writand/screens/editor/EditorScreen.kt create mode 100644 app/src/main/java/be/re/writand/screens/projectpicker/ProjectPickerScreen.kt create mode 100644 app/src/main/java/be/re/writand/screens/splash/SplashScreen.kt create mode 100644 app/src/main/java/be/re/writand/screens/splash/SplashViewModel.kt create mode 100644 app/src/main/java/be/re/writand/screens/welcome/WelcomeSettingsScreen.kt create mode 100644 app/src/main/java/be/re/writand/screens/welcome/WelcomeStartScreen.kt create mode 100644 app/src/main/java/be/re/writand/screens/welcome/WelcomeTOSScreen.kt diff --git a/app/build.gradle b/app/build.gradle index 27fdae8..8d29d88 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -66,6 +66,8 @@ dependencies { implementation "androidx.compose.material3:material3:1.2.1" implementation 'androidx.test:core-ktx:1.6.1' implementation 'com.google.ar:core:1.44.0' + implementation 'androidx.navigation:navigation-runtime-ktx:2.7.7' + implementation 'androidx.navigation:navigation-compose:2.7.7' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.2.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' diff --git a/app/src/main/java/be/re/writand/MainActivity.kt b/app/src/main/java/be/re/writand/MainActivity.kt index 98f24ac..c185436 100644 --- a/app/src/main/java/be/re/writand/MainActivity.kt +++ b/app/src/main/java/be/re/writand/MainActivity.kt @@ -9,7 +9,9 @@ import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.navigation.compose.rememberNavController +import be.re.writand.navigation.WNavGraph import be.re.writand.ui.theme.WritandTheme class MainActivity : ComponentActivity() { @@ -22,22 +24,12 @@ class MainActivity : ComponentActivity() { modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.primary ) { - Greeting("Android") + WNavGraph( + navHostController = rememberNavController(), + modifier = Modifier.padding(5.dp) + ) } } } } -} - -@Composable -fun Greeting(name: String) { - Text(text = "Hello $name!") -} - -@Preview(showBackground = true) -@Composable -fun DefaultPreview() { - WritandTheme { - Greeting("Android") - } } \ No newline at end of file diff --git a/app/src/main/java/be/re/writand/navigation/.keep b/app/src/main/java/be/re/writand/navigation/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/app/src/main/java/be/re/writand/navigation/WAppDestinations.kt b/app/src/main/java/be/re/writand/navigation/WAppDestinations.kt new file mode 100644 index 0000000..9d0b9bd --- /dev/null +++ b/app/src/main/java/be/re/writand/navigation/WAppDestinations.kt @@ -0,0 +1,21 @@ +package be.re.writand.navigation + +/** + * All the destinations of the different screens the navigator can go to. + * They are categorized, so it's easier to find/add destinations. + */ +object WAppDestinations { + // Start of application + const val SPLASH = "splash" + + // Welcome screens for first time user + const val WELCOME_START = "welcome_start" + const val WELCOME_TOS = "welcome_tos" + const val WELCOME_SETTINGS = "welcome_settings" + + // Project picker + const val PROJECT_PICKER = "project_picker" + + // Editor view + const val MAIN_EDITOR = "main_editor" +} \ No newline at end of file diff --git a/app/src/main/java/be/re/writand/navigation/WNavGraph.kt b/app/src/main/java/be/re/writand/navigation/WNavGraph.kt new file mode 100644 index 0000000..42246b3 --- /dev/null +++ b/app/src/main/java/be/re/writand/navigation/WNavGraph.kt @@ -0,0 +1,68 @@ +package be.re.writand.navigation + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.navigation.compose.NavHost +import androidx.navigation.NavHostController +import androidx.navigation.compose.composable +import be.re.writand.screens.editor.EditorScreen +import be.re.writand.screens.projectpicker.ProjectPickerScreen +import be.re.writand.screens.splash.SplashScreen +import be.re.writand.screens.welcome.WelcomeSettingsScreen +import be.re.writand.screens.welcome.WelcomeStartScreen +import be.re.writand.screens.welcome.WelcomeTOSScreen + +/** + * The navigation controller containing all the different screens a user can go to. + * @param[navHostController] the controller to go from one screen to another and back. + * @param[modifier] the general modifier that should be applied to all screens. + */ +@Composable +fun WNavGraph(navHostController: NavHostController, modifier: Modifier) { + + val onBackArrow: () -> Unit = { navHostController.navigateUp() } + + NavHost( + navController = navHostController, + startDestination = WAppDestinations.SPLASH, + modifier = modifier + ) { + + + // Start of application + + composable(WAppDestinations.SPLASH) { + SplashScreen(navHostController = navHostController) + } + + + // Welcome screens for first time user + + composable(WAppDestinations.WELCOME_START) { + WelcomeStartScreen(navHostController = navHostController) + } + + composable(WAppDestinations.WELCOME_TOS) { + WelcomeTOSScreen(navHostController = navHostController) + } + + composable(WAppDestinations.WELCOME_SETTINGS) { + WelcomeSettingsScreen(navHostController = navHostController) + } + + + // Project picker + + composable(WAppDestinations.PROJECT_PICKER) { + ProjectPickerScreen(navHostController = navHostController) + } + + + // Editor view + + composable(WAppDestinations.MAIN_EDITOR) { + EditorScreen(navHostController = navHostController) + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/be/re/writand/screens/editor/EditorScreen.kt b/app/src/main/java/be/re/writand/screens/editor/EditorScreen.kt new file mode 100644 index 0000000..5944ccd --- /dev/null +++ b/app/src/main/java/be/re/writand/screens/editor/EditorScreen.kt @@ -0,0 +1,11 @@ +package be.re.writand.screens.editor + +import androidx.compose.runtime.Composable +import androidx.navigation.NavHostController + +@Composable +fun EditorScreen( + navHostController: NavHostController +) { + +} \ No newline at end of file diff --git a/app/src/main/java/be/re/writand/screens/projectpicker/ProjectPickerScreen.kt b/app/src/main/java/be/re/writand/screens/projectpicker/ProjectPickerScreen.kt new file mode 100644 index 0000000..919fde4 --- /dev/null +++ b/app/src/main/java/be/re/writand/screens/projectpicker/ProjectPickerScreen.kt @@ -0,0 +1,23 @@ +package be.re.writand.screens.projectpicker + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.navigation.NavHostController +import be.re.writand.navigation.WAppDestinations +import be.re.writand.screens.components.WButton + +@Composable +fun ProjectPickerScreen( + navHostController: NavHostController +) { + + Box(modifier = Modifier.size(20.dp, 20.dp)) { + WButton( + text = "Create new", + onClick = { navHostController.navigate(WAppDestinations.MAIN_EDITOR) } + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/be/re/writand/screens/splash/SplashScreen.kt b/app/src/main/java/be/re/writand/screens/splash/SplashScreen.kt new file mode 100644 index 0000000..5a440b8 --- /dev/null +++ b/app/src/main/java/be/re/writand/screens/splash/SplashScreen.kt @@ -0,0 +1,25 @@ +package be.re.writand.screens.splash + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.navigation.NavHostController +import be.re.writand.navigation.WAppDestinations +import be.re.writand.screens.components.WButton + +@Composable +fun SplashScreen( + navHostController: NavHostController +) { + + Box(modifier = Modifier.size(20.dp, 20.dp)) { + WButton( + text = "Some fancy screen where you click...", + // TODO: find out which screen is next + onClick = { navHostController.navigate(WAppDestinations.WELCOME_START) } + ) + } + +} \ No newline at end of file diff --git a/app/src/main/java/be/re/writand/screens/splash/SplashViewModel.kt b/app/src/main/java/be/re/writand/screens/splash/SplashViewModel.kt new file mode 100644 index 0000000..8c7bf72 --- /dev/null +++ b/app/src/main/java/be/re/writand/screens/splash/SplashViewModel.kt @@ -0,0 +1,4 @@ +package be.re.writand.screens.splash + +class SplashViewModel { +} \ No newline at end of file diff --git a/app/src/main/java/be/re/writand/screens/welcome/WelcomeSettingsScreen.kt b/app/src/main/java/be/re/writand/screens/welcome/WelcomeSettingsScreen.kt new file mode 100644 index 0000000..43f5e14 --- /dev/null +++ b/app/src/main/java/be/re/writand/screens/welcome/WelcomeSettingsScreen.kt @@ -0,0 +1,24 @@ +package be.re.writand.screens.welcome + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.navigation.NavHostController +import be.re.writand.navigation.WAppDestinations +import be.re.writand.screens.components.WButton + +@Composable +fun WelcomeSettingsScreen( + navHostController: NavHostController +) { + + Box(modifier = Modifier.size(20.dp, 20.dp)) { + WButton( + text = "Finish", + onClick = { navHostController.navigate(WAppDestinations.PROJECT_PICKER) } + ) + } + +} \ No newline at end of file diff --git a/app/src/main/java/be/re/writand/screens/welcome/WelcomeStartScreen.kt b/app/src/main/java/be/re/writand/screens/welcome/WelcomeStartScreen.kt new file mode 100644 index 0000000..352c3bf --- /dev/null +++ b/app/src/main/java/be/re/writand/screens/welcome/WelcomeStartScreen.kt @@ -0,0 +1,24 @@ +package be.re.writand.screens.welcome + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.navigation.NavHostController +import be.re.writand.navigation.WAppDestinations +import be.re.writand.screens.components.WButton + +@Composable +fun WelcomeStartScreen( + navHostController: NavHostController +) { + + Box(modifier = Modifier.size(20.dp, 20.dp)) { + WButton( + text = "Next", + onClick = { navHostController.navigate(WAppDestinations.WELCOME_TOS) } + ) + } + +} \ No newline at end of file diff --git a/app/src/main/java/be/re/writand/screens/welcome/WelcomeTOSScreen.kt b/app/src/main/java/be/re/writand/screens/welcome/WelcomeTOSScreen.kt new file mode 100644 index 0000000..df8b933 --- /dev/null +++ b/app/src/main/java/be/re/writand/screens/welcome/WelcomeTOSScreen.kt @@ -0,0 +1,24 @@ +package be.re.writand.screens.welcome + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.navigation.NavHostController +import be.re.writand.navigation.WAppDestinations +import be.re.writand.screens.components.WButton + +@Composable +fun WelcomeTOSScreen( + navHostController: NavHostController +) { + + Box(modifier = Modifier.size(20.dp, 20.dp)) { + WButton( + text = "Next", + onClick = { navHostController.navigate(WAppDestinations.WELCOME_SETTINGS) } + ) + } + +} \ No newline at end of file