Skip to content

Commit

Permalink
About card navigation now integrated into navigation graph
Browse files Browse the repository at this point in the history
  • Loading branch information
jherkenhoff committed Sep 21, 2024
1 parent b62fb15 commit a9725c0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
34 changes: 22 additions & 12 deletions app/src/main/java/com/jherkenhoff/qalculate/ui/NavigationDrawer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
)
Expand All @@ -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)
)
Expand All @@ -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)
)
Expand All @@ -114,6 +122,8 @@ fun NavigationDrawer(
@Preview(showBackground = true)
@Composable
private fun DefaultPreview() {
NavigationDrawer()
NavigationDrawer(
QalculateDestinations.UNITS
)
}

16 changes: 4 additions & 12 deletions app/src/main/java/com/jherkenhoff/qalculate/ui/QalculateApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,25 +35,21 @@ 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)
)}
) {
QalculateNavGraph(
navController = navController,
openDrawer = { coroutineScope.launch { drawerState.open() } },
)
if (aboutCardVisible) {
Dialog(onDismissRequest = { aboutCardVisible = false }) {
AboutCard()
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,45 @@ 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,
startDestination = startDestination,
modifier = modifier
) {

composable(route = QalculateDestinations.CALCULATOR) {
composable<Calculator> {
CalculatorScreen(
viewModel = hiltViewModel<CalculatorViewModel>(),
openDrawer = openDrawer,
)
}

composable(route = QalculateDestinations.UNITS) {
composable<Units> {
UnitsScreen(
viewModel = hiltViewModel<UnitsViewModel>(),
openDrawer = openDrawer,
)
}

dialog<About> {
AboutCard()
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a9725c0

Please sign in to comment.