diff --git a/app/src/main/java/com/jherkenhoff/qalculate/ui/NavigationDrawer.kt b/app/src/main/java/com/jherkenhoff/qalculate/ui/NavigationDrawer.kt index 8d1e460..232a0e3 100644 --- a/app/src/main/java/com/jherkenhoff/qalculate/ui/NavigationDrawer.kt +++ b/app/src/main/java/com/jherkenhoff/qalculate/ui/NavigationDrawer.kt @@ -32,8 +32,16 @@ import com.jherkenhoff.qalculate.R @Composable fun NavigationDrawer( + currentPage: String, modifier: Modifier = Modifier, onNavigation: (String) -> Unit = {}, + onCalculatorClick: () -> Unit = {}, + onFunctionsClick: () -> Unit = {}, + onVariablesClick: () -> Unit = {}, + onUnitsClick: () -> Unit = {}, + onDatasetsClick: () -> Unit = {}, + onAboutClick: () -> Unit = {}, + onSettingsClick: () -> Unit = {}, ) { ModalDrawerSheet(modifier = modifier) { Box( @@ -52,8 +60,8 @@ fun NavigationDrawer( } NavigationDrawerItem( label = { Text(text = "Calculator") }, - selected = true, - onClick = { onNavigation(QalculateDestinations.CALCULATOR) }, + selected = currentPage == QalculateDestinations.CALCULATOR, + onClick = onCalculatorClick, icon = { Icon(Icons.Filled.Calculate, contentDescription = "Calculator icon") }, modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) ) @@ -62,29 +70,29 @@ fun NavigationDrawer( .padding(horizontal = 25.dp, vertical = 15.dp)) NavigationDrawerItem( label = { Text(text = "Functions") }, - selected = false, - onClick = { /*TODO*/ }, + selected = currentPage == QalculateDestinations.FUNCTIONS, + onClick = onFunctionsClick, icon = { Icon(Icons.Outlined.Functions, contentDescription = "Functions icon") }, modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) ) NavigationDrawerItem( label = { Text(text = "Variables") }, - selected = false, - onClick = { /*TODO*/ }, + selected = currentPage == QalculateDestinations.VARIABLES, + onClick = onVariablesClick, icon = { Icon(Icons.Outlined.Pin, contentDescription = "Variables icon") }, modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) ) NavigationDrawerItem( label = { Text(text = "Units") }, - selected = false, - onClick = { onNavigation(QalculateDestinations.UNITS) }, + selected = currentPage == QalculateDestinations.UNITS, + onClick = onUnitsClick, icon = { Icon(Icons.Outlined.Straighten, contentDescription = "Units icon") }, modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) ) NavigationDrawerItem( label = { Text(text = "Datasets") }, selected = false, - onClick = { /*TODO*/ }, + onClick = onDatasetsClick, icon = { Icon(Icons.Outlined.Dataset, contentDescription = "Datasets icon") }, modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) ) @@ -97,14 +105,14 @@ fun NavigationDrawer( NavigationDrawerItem( label = { Text(text = "About") }, selected = false, - onClick = { onNavigation(QalculateDestinations.ABOUT) }, + onClick = onAboutClick, icon = { Icon(Icons.Filled.Info, contentDescription = "About icon") }, modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) ) NavigationDrawerItem( label = { Text(text = "Settings") }, selected = false, - onClick = { /*TODO*/ }, + onClick = onSettingsClick, icon = { Icon(Icons.Filled.Settings, contentDescription = "Settings icon") }, modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) ) @@ -114,6 +122,8 @@ fun NavigationDrawer( @Preview(showBackground = true) @Composable private fun DefaultPreview() { - NavigationDrawer() + NavigationDrawer( + QalculateDestinations.UNITS + ) } diff --git a/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateApp.kt b/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateApp.kt index 48453f8..ed92f1f 100644 --- a/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateApp.kt +++ b/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateApp.kt @@ -4,15 +4,11 @@ import androidx.compose.material3.DrawerValue import androidx.compose.material3.ModalNavigationDrawer import androidx.compose.material3.rememberDrawerState import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.window.Dialog import androidx.compose.ui.zIndex import androidx.navigation.compose.rememberNavController import com.jherkenhoff.qalculate.ui.theme.QalculateTheme @@ -39,13 +35,14 @@ fun QalculateApp() { } ) - var aboutCardVisible by remember { mutableStateOf(false) } - ModalNavigationDrawer( drawerState = drawerState, drawerContent = { NavigationDrawer( - onNavigation = { navController.navigate(it); coroutineScope.launch { drawerState.close() } }, + "unints", + onCalculatorClick = { navController.navigate(Calculator); coroutineScope.launch { drawerState.close() } }, + onUnitsClick = { navController.navigate(Units); coroutineScope.launch { drawerState.close() } }, + onAboutClick = { navController.navigate(About); coroutineScope.launch { drawerState.close() } }, modifier = Modifier.zIndex(1000f) )} ) { @@ -53,11 +50,6 @@ fun QalculateApp() { navController = navController, openDrawer = { coroutineScope.launch { drawerState.open() } }, ) - if (aboutCardVisible) { - Dialog(onDismissRequest = { aboutCardVisible = false }) { - AboutCard() - } - } } } } diff --git a/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateNavGraph.kt b/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateNavGraph.kt index 95c6700..54060ff 100644 --- a/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateNavGraph.kt +++ b/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateNavGraph.kt @@ -6,15 +6,21 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable +import androidx.navigation.compose.dialog import androidx.navigation.compose.rememberNavController +import kotlinx.serialization.Serializable +@Serializable data object Calculator + +@Serializable data object Units +@Serializable data object About @Composable fun QalculateNavGraph( modifier: Modifier = Modifier, navController: NavHostController = rememberNavController(), openDrawer: () -> Unit = {}, - startDestination: String = QalculateDestinations.CALCULATOR, + startDestination: Calculator = Calculator, ) { NavHost( navController = navController, @@ -22,19 +28,23 @@ fun QalculateNavGraph( modifier = modifier ) { - composable(route = QalculateDestinations.CALCULATOR) { + composable { CalculatorScreen( viewModel = hiltViewModel(), openDrawer = openDrawer, ) } - composable(route = QalculateDestinations.UNITS) { + composable { UnitsScreen( viewModel = hiltViewModel(), openDrawer = openDrawer, ) } + dialog { + AboutCard() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateNavigation.kt b/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateNavigation.kt index 0d1e718..a913a04 100644 --- a/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateNavigation.kt +++ b/app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateNavigation.kt @@ -5,8 +5,10 @@ import androidx.navigation.NavHostController object QalculateDestinations { const val CALCULATOR = "calculator" - const val UNITS = "units" - const val ABOUT = "about" + const val FUNCTIONS = "functions" + const val VARIABLES = "variables" + const val UNITS = "units" + const val ABOUT = "about" } class QalculateNavigationActions(navController: NavHostController) {