mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
parent
7cbbb846af
commit
80f1624748
@ -92,7 +92,8 @@ internal fun ComponentActivity.App(prefs: AppPreferences?) {
|
|||||||
modifier = Modifier,
|
modifier = Modifier,
|
||||||
state = drawerState,
|
state = drawerState,
|
||||||
gesturesEnabled = gesturesEnabled,
|
gesturesEnabled = gesturesEnabled,
|
||||||
tabs = DrawerItem.main,
|
mainTabs = DrawerItem.main,
|
||||||
|
additionalTabs = DrawerItem.additional,
|
||||||
currentDestination = navBackStackEntry?.destination?.route,
|
currentDestination = navBackStackEntry?.destination?.route,
|
||||||
onItemClick = { destination ->
|
onItemClick = { destination ->
|
||||||
drawerScope.launch { drawerState.close() }
|
drawerScope.launch { drawerState.close() }
|
||||||
|
@ -30,7 +30,6 @@ import com.sadellie.unitto.feature.bodymass.navigation.bodyMassGraph
|
|||||||
import com.sadellie.unitto.feature.calculator.navigation.calculatorGraph
|
import com.sadellie.unitto.feature.calculator.navigation.calculatorGraph
|
||||||
import com.sadellie.unitto.feature.converter.navigation.converterGraph
|
import com.sadellie.unitto.feature.converter.navigation.converterGraph
|
||||||
import com.sadellie.unitto.feature.datecalculator.navigation.dateCalculatorGraph
|
import com.sadellie.unitto.feature.datecalculator.navigation.dateCalculatorGraph
|
||||||
import com.sadellie.unitto.feature.settings.navigation.navigateToSettings
|
|
||||||
import com.sadellie.unitto.feature.settings.navigation.navigateToUnitGroups
|
import com.sadellie.unitto.feature.settings.navigation.navigateToUnitGroups
|
||||||
import com.sadellie.unitto.feature.settings.navigation.settingGraph
|
import com.sadellie.unitto.feature.settings.navigation.settingGraph
|
||||||
import com.sadellie.unitto.feature.timezone.navigation.timeZoneGraph
|
import com.sadellie.unitto.feature.timezone.navigation.timeZoneGraph
|
||||||
@ -48,39 +47,35 @@ internal fun UnittoNavigation(
|
|||||||
startDestination = startDestination,
|
startDestination = startDestination,
|
||||||
modifier = Modifier.background(MaterialTheme.colorScheme.background),
|
modifier = Modifier.background(MaterialTheme.colorScheme.background),
|
||||||
enterTransition = { fadeIn() },
|
enterTransition = { fadeIn() },
|
||||||
exitTransition = { fadeOut() }
|
exitTransition = { fadeOut() },
|
||||||
) {
|
) {
|
||||||
|
calculatorGraph(
|
||||||
|
openDrawer = openDrawer,
|
||||||
|
)
|
||||||
|
|
||||||
converterGraph(
|
converterGraph(
|
||||||
openDrawer = openDrawer,
|
openDrawer = openDrawer,
|
||||||
navController = navController,
|
navController = navController,
|
||||||
navigateToSettings = navController::navigateToSettings,
|
navigateToUnitGroups = navController::navigateToUnitGroups,
|
||||||
navigateToUnitGroups = navController::navigateToUnitGroups
|
|
||||||
)
|
|
||||||
|
|
||||||
settingGraph(
|
|
||||||
themmoController = themmoController,
|
|
||||||
navController = navController
|
|
||||||
)
|
|
||||||
|
|
||||||
calculatorGraph(
|
|
||||||
openDrawer = openDrawer,
|
|
||||||
navigateToSettings = navController::navigateToSettings
|
|
||||||
)
|
)
|
||||||
|
|
||||||
dateCalculatorGraph(
|
dateCalculatorGraph(
|
||||||
navigateToMenu = openDrawer,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navController::navigateToSettings
|
|
||||||
)
|
)
|
||||||
|
|
||||||
timeZoneGraph(
|
timeZoneGraph(
|
||||||
navigateToMenu = openDrawer,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navController::navigateToSettings,
|
|
||||||
navController = navController,
|
navController = navController,
|
||||||
)
|
)
|
||||||
|
|
||||||
bodyMassGraph(
|
bodyMassGraph(
|
||||||
openDrawer = openDrawer,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navController::navigateToSettings,
|
)
|
||||||
|
|
||||||
|
settingGraph(
|
||||||
|
openDrawer = openDrawer,
|
||||||
|
navController = navController,
|
||||||
|
themmoController = themmoController,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,16 +27,16 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import com.sadellie.unitto.core.base.R
|
import com.sadellie.unitto.core.base.R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Button that is used in Top bars
|
* Button that is used in Top bars to open drawer.
|
||||||
*
|
*
|
||||||
* @param onClick Action to be called when button is clicked.
|
* @param onClick Action to be called when button is clicked.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun MenuButton(onClick: () -> Unit) {
|
fun DrawerButton(onClick: () -> Unit) {
|
||||||
IconButton(onClick = onClick) {
|
IconButton(onClick = onClick) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Outlined.Menu,
|
imageVector = Icons.Outlined.Menu,
|
||||||
contentDescription = stringResource(R.string.open_menu_description)
|
contentDescription = stringResource(R.string.open_menu_description),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -111,7 +111,8 @@ fun NavigationDrawer(
|
|||||||
modifier: Modifier,
|
modifier: Modifier,
|
||||||
gesturesEnabled: Boolean,
|
gesturesEnabled: Boolean,
|
||||||
state: DrawerState = rememberDrawerState(),
|
state: DrawerState = rememberDrawerState(),
|
||||||
tabs: List<DrawerItem>,
|
mainTabs: List<DrawerItem>,
|
||||||
|
additionalTabs: List<DrawerItem>,
|
||||||
currentDestination: String?,
|
currentDestination: String?,
|
||||||
onItemClick: (DrawerItem) -> Unit,
|
onItemClick: (DrawerItem) -> Unit,
|
||||||
content: @Composable () -> Unit,
|
content: @Composable () -> Unit,
|
||||||
@ -126,7 +127,8 @@ fun NavigationDrawer(
|
|||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
) {
|
) {
|
||||||
SheetContent(
|
SheetContent(
|
||||||
tabs = tabs,
|
mainTabs = mainTabs,
|
||||||
|
additionalTabs = additionalTabs,
|
||||||
currentDestination = currentDestination,
|
currentDestination = currentDestination,
|
||||||
onItemClick = onItemClick
|
onItemClick = onItemClick
|
||||||
)
|
)
|
||||||
@ -144,7 +146,8 @@ fun NavigationDrawer(
|
|||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
) {
|
) {
|
||||||
SheetContent(
|
SheetContent(
|
||||||
tabs = tabs,
|
mainTabs = mainTabs,
|
||||||
|
additionalTabs = additionalTabs,
|
||||||
currentDestination = currentDestination,
|
currentDestination = currentDestination,
|
||||||
onItemClick = onItemClick
|
onItemClick = onItemClick
|
||||||
)
|
)
|
||||||
@ -279,7 +282,8 @@ private fun PreviewUnittoModalNavigationDrawerClose() {
|
|||||||
modifier = Modifier,
|
modifier = Modifier,
|
||||||
state = drawerState,
|
state = drawerState,
|
||||||
gesturesEnabled = true,
|
gesturesEnabled = true,
|
||||||
tabs = DrawerItem.main,
|
mainTabs = DrawerItem.main,
|
||||||
|
additionalTabs = DrawerItem.additional,
|
||||||
currentDestination = DrawerItem.Calculator.start,
|
currentDestination = DrawerItem.Calculator.start,
|
||||||
onItemClick = {},
|
onItemClick = {},
|
||||||
content = {
|
content = {
|
||||||
|
@ -71,7 +71,11 @@ fun ScaffoldWithTopBar(
|
|||||||
) {
|
) {
|
||||||
CenterAlignedTopAppBar(
|
CenterAlignedTopAppBar(
|
||||||
title = title,
|
title = title,
|
||||||
navigationIcon = if (LocalWindowSize.current.widthSizeClass != WindowWidthSizeClass.Expanded) navigationIcon else { {} },
|
navigationIcon = {
|
||||||
|
if (LocalWindowSize.current.widthSizeClass != WindowWidthSizeClass.Expanded) {
|
||||||
|
navigationIcon()
|
||||||
|
}
|
||||||
|
},
|
||||||
actions = actions,
|
actions = actions,
|
||||||
colors = colors,
|
colors = colors,
|
||||||
scrollBehavior = scrollBehavior,
|
scrollBehavior = scrollBehavior,
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Unitto is a calculator for Android
|
|
||||||
* Copyright (c) 2023-2024 Elshan Agaev
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.sadellie.unitto.core.ui.common
|
|
||||||
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.outlined.Settings
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import com.sadellie.unitto.core.base.R
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SettingsButton(onClick: () -> Unit) {
|
|
||||||
IconButton(onClick) {
|
|
||||||
Icon(Icons.Outlined.Settings, stringResource(R.string.open_settings_label))
|
|
||||||
}
|
|
||||||
}
|
|
@ -39,15 +39,14 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.sadellie.unitto.core.base.R
|
import com.sadellie.unitto.core.base.R
|
||||||
import com.sadellie.unitto.core.ui.LocalWindowSize
|
|
||||||
import com.sadellie.unitto.core.ui.WindowHeightSizeClass
|
|
||||||
import com.sadellie.unitto.core.ui.model.DrawerItem
|
import com.sadellie.unitto.core.ui.model.DrawerItem
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
@Suppress("UnusedReceiverParameter")
|
@Suppress("UnusedReceiverParameter")
|
||||||
@Composable
|
@Composable
|
||||||
internal fun ColumnScope.SheetContent(
|
internal fun ColumnScope.SheetContent(
|
||||||
tabs: List<DrawerItem>,
|
mainTabs: List<DrawerItem>,
|
||||||
|
additionalTabs: List<DrawerItem>,
|
||||||
currentDestination: String?,
|
currentDestination: String?,
|
||||||
onItemClick: (DrawerItem) -> Unit,
|
onItemClick: (DrawerItem) -> Unit,
|
||||||
) {
|
) {
|
||||||
@ -79,7 +78,7 @@ internal fun ColumnScope.SheetContent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
tabs.forEach { drawerItem ->
|
mainTabs.forEach { drawerItem ->
|
||||||
val selected = drawerItem.start == currentDestination
|
val selected = drawerItem.start == currentDestination
|
||||||
DrawerItem(
|
DrawerItem(
|
||||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding),
|
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding),
|
||||||
@ -90,15 +89,15 @@ internal fun ColumnScope.SheetContent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Top bar (and settings button in it) is not visible for compact height
|
HorizontalDivider(Modifier.padding(horizontal = 12.dp, vertical = 8.dp))
|
||||||
if (LocalWindowSize.current.heightSizeClass == WindowHeightSizeClass.Compact) {
|
|
||||||
HorizontalDivider(Modifier.padding(horizontal = 12.dp, vertical = 8.dp))
|
|
||||||
|
|
||||||
|
additionalTabs.forEach { drawerItem ->
|
||||||
|
val selected = drawerItem.start == currentDestination
|
||||||
DrawerItem(
|
DrawerItem(
|
||||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding),
|
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding),
|
||||||
destination = DrawerItem.Settings,
|
destination = drawerItem,
|
||||||
icon = DrawerItem.Settings.defaultIcon,
|
icon = if (selected) drawerItem.selectedIcon else drawerItem.defaultIcon,
|
||||||
selected = false,
|
selected = selected,
|
||||||
onClick = onItemClick
|
onClick = onItemClick
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -109,7 +108,12 @@ internal fun ColumnScope.SheetContent(
|
|||||||
private fun PreviewDrawerSheet() {
|
private fun PreviewDrawerSheet() {
|
||||||
Column {
|
Column {
|
||||||
SheetContent(
|
SheetContent(
|
||||||
tabs = listOf(
|
mainTabs = listOf(
|
||||||
|
DrawerItem.Calculator,
|
||||||
|
DrawerItem.Calculator,
|
||||||
|
DrawerItem.Calculator,
|
||||||
|
),
|
||||||
|
additionalTabs = listOf(
|
||||||
DrawerItem.Calculator,
|
DrawerItem.Calculator,
|
||||||
DrawerItem.Calculator,
|
DrawerItem.Calculator,
|
||||||
DrawerItem.Calculator,
|
DrawerItem.Calculator,
|
||||||
|
@ -139,7 +139,9 @@ sealed class DrawerItem(
|
|||||||
all
|
all
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val additional = listOf(Settings)
|
||||||
|
|
||||||
// Only routes, not graphs!
|
// Only routes, not graphs!
|
||||||
val startRoutes by lazy { main.map { it.start } }
|
val startRoutes by lazy { (main + additional).map { it.start } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,12 +50,11 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.sadellie.unitto.core.base.R
|
import com.sadellie.unitto.core.base.R
|
||||||
|
import com.sadellie.unitto.core.ui.common.DrawerButton
|
||||||
import com.sadellie.unitto.core.ui.common.EmptyScreen
|
import com.sadellie.unitto.core.ui.common.EmptyScreen
|
||||||
import com.sadellie.unitto.core.ui.common.MenuButton
|
|
||||||
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
|
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
|
||||||
import com.sadellie.unitto.core.ui.common.SegmentedButton
|
import com.sadellie.unitto.core.ui.common.SegmentedButton
|
||||||
import com.sadellie.unitto.core.ui.common.SegmentedButtonsRow
|
import com.sadellie.unitto.core.ui.common.SegmentedButtonsRow
|
||||||
import com.sadellie.unitto.core.ui.common.SettingsButton
|
|
||||||
import com.sadellie.unitto.core.ui.common.textfield.ExpressionTransformer
|
import com.sadellie.unitto.core.ui.common.textfield.ExpressionTransformer
|
||||||
import com.sadellie.unitto.core.ui.common.textfield.FormatterSymbols
|
import com.sadellie.unitto.core.ui.common.textfield.FormatterSymbols
|
||||||
import com.sadellie.unitto.core.ui.openLink
|
import com.sadellie.unitto.core.ui.openLink
|
||||||
@ -67,8 +66,7 @@ import java.math.BigDecimal
|
|||||||
@Composable
|
@Composable
|
||||||
internal fun BodyMassRoute(
|
internal fun BodyMassRoute(
|
||||||
openDrawer: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
viewModel: BodyMassViewModel = hiltViewModel(),
|
||||||
viewModel: BodyMassViewModel = hiltViewModel()
|
|
||||||
) {
|
) {
|
||||||
when (val uiState = viewModel.uiState.collectAsStateWithLifecycle().value) {
|
when (val uiState = viewModel.uiState.collectAsStateWithLifecycle().value) {
|
||||||
UIState.Loading -> EmptyScreen()
|
UIState.Loading -> EmptyScreen()
|
||||||
@ -79,7 +77,6 @@ internal fun BodyMassRoute(
|
|||||||
updateWeight = viewModel::updateWeight,
|
updateWeight = viewModel::updateWeight,
|
||||||
updateIsMetric = viewModel::updateIsMetric,
|
updateIsMetric = viewModel::updateIsMetric,
|
||||||
openDrawer = openDrawer,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +89,6 @@ private fun BodyMassScreen(
|
|||||||
updateWeight: (TextFieldValue) -> Unit,
|
updateWeight: (TextFieldValue) -> Unit,
|
||||||
updateIsMetric: (Boolean) -> Unit,
|
updateIsMetric: (Boolean) -> Unit,
|
||||||
openDrawer: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
) {
|
) {
|
||||||
val mContext = LocalContext.current
|
val mContext = LocalContext.current
|
||||||
val expressionTransformer = remember(uiState.formatterSymbols) {
|
val expressionTransformer = remember(uiState.formatterSymbols) {
|
||||||
@ -106,8 +102,7 @@ private fun BodyMassScreen(
|
|||||||
|
|
||||||
ScaffoldWithTopBar(
|
ScaffoldWithTopBar(
|
||||||
title = { Text(stringResource(R.string.body_mass_title)) },
|
title = { Text(stringResource(R.string.body_mass_title)) },
|
||||||
navigationIcon = { MenuButton(openDrawer) },
|
navigationIcon = { DrawerButton(openDrawer) },
|
||||||
actions = { SettingsButton(navigateToSettings) }
|
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -235,6 +230,5 @@ fun PreviewBodyMassScreen() {
|
|||||||
updateWeight = {},
|
updateWeight = {},
|
||||||
updateIsMetric = {},
|
updateIsMetric = {},
|
||||||
openDrawer = {},
|
openDrawer = {},
|
||||||
navigateToSettings = {}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ private val start = DrawerItem.BodyMass.start
|
|||||||
|
|
||||||
fun NavGraphBuilder.bodyMassGraph(
|
fun NavGraphBuilder.bodyMassGraph(
|
||||||
openDrawer: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit
|
|
||||||
) {
|
) {
|
||||||
unittoNavigation(
|
unittoNavigation(
|
||||||
startDestination = start,
|
startDestination = start,
|
||||||
@ -42,7 +41,6 @@ fun NavGraphBuilder.bodyMassGraph(
|
|||||||
unittoComposable(start) {
|
unittoComposable(start) {
|
||||||
BodyMassRoute(
|
BodyMassRoute(
|
||||||
openDrawer = openDrawer,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,16 +41,15 @@ class CalculatorScreenTest {
|
|||||||
setContent {
|
setContent {
|
||||||
CalculatorScreen(
|
CalculatorScreen(
|
||||||
uiState = CalculatorUIState.Loading,
|
uiState = CalculatorUIState.Loading,
|
||||||
navigateToMenu = {},
|
openDrawer = {},
|
||||||
navigateToSettings = {},
|
|
||||||
addTokens = {},
|
addTokens = {},
|
||||||
|
addBracket = {},
|
||||||
clearInput = {},
|
clearInput = {},
|
||||||
deleteTokens = {},
|
deleteTokens = {},
|
||||||
onValueChange = {},
|
onValueChange = {},
|
||||||
toggleCalculatorMode = {},
|
toggleCalculatorMode = {},
|
||||||
equal = {},
|
equal = {},
|
||||||
clearHistory = {},
|
clearHistory = {},
|
||||||
addBracket = {},
|
|
||||||
onDelete = {},
|
onDelete = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -74,16 +73,15 @@ class CalculatorScreenTest {
|
|||||||
acButton = true,
|
acButton = true,
|
||||||
partialHistoryView = true
|
partialHistoryView = true
|
||||||
),
|
),
|
||||||
navigateToMenu = {},
|
openDrawer = {},
|
||||||
navigateToSettings = {},
|
|
||||||
addTokens = {},
|
addTokens = {},
|
||||||
|
addBracket = {},
|
||||||
clearInput = {},
|
clearInput = {},
|
||||||
deleteTokens = {},
|
deleteTokens = {},
|
||||||
onValueChange = {},
|
onValueChange = {},
|
||||||
toggleCalculatorMode = {},
|
toggleCalculatorMode = {},
|
||||||
equal = {},
|
equal = {},
|
||||||
clearHistory = {},
|
clearHistory = {},
|
||||||
addBracket = {},
|
|
||||||
onDelete = {},
|
onDelete = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -108,16 +106,15 @@ class CalculatorScreenTest {
|
|||||||
acButton = true,
|
acButton = true,
|
||||||
partialHistoryView = true
|
partialHistoryView = true
|
||||||
),
|
),
|
||||||
navigateToMenu = {},
|
openDrawer = {},
|
||||||
navigateToSettings = {},
|
|
||||||
addTokens = {},
|
addTokens = {},
|
||||||
|
addBracket = {},
|
||||||
clearInput = {},
|
clearInput = {},
|
||||||
deleteTokens = {},
|
deleteTokens = {},
|
||||||
onValueChange = {},
|
onValueChange = {},
|
||||||
toggleCalculatorMode = {},
|
toggleCalculatorMode = {},
|
||||||
equal = {},
|
equal = {},
|
||||||
clearHistory = {},
|
clearHistory = {},
|
||||||
addBracket = {},
|
|
||||||
onDelete = {},
|
onDelete = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
package com.sadellie.unitto.feature.calculator
|
package com.sadellie.unitto.feature.calculator
|
||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.animation.Crossfade
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.gestures.AnchoredDraggableState
|
import androidx.compose.foundation.gestures.AnchoredDraggableState
|
||||||
@ -66,10 +66,9 @@ import com.sadellie.unitto.core.base.OutputFormat
|
|||||||
import com.sadellie.unitto.core.base.R
|
import com.sadellie.unitto.core.base.R
|
||||||
import com.sadellie.unitto.core.ui.LocalWindowSize
|
import com.sadellie.unitto.core.ui.LocalWindowSize
|
||||||
import com.sadellie.unitto.core.ui.WindowHeightSizeClass
|
import com.sadellie.unitto.core.ui.WindowHeightSizeClass
|
||||||
|
import com.sadellie.unitto.core.ui.common.DrawerButton
|
||||||
import com.sadellie.unitto.core.ui.common.EmptyScreen
|
import com.sadellie.unitto.core.ui.common.EmptyScreen
|
||||||
import com.sadellie.unitto.core.ui.common.MenuButton
|
|
||||||
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
|
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
|
||||||
import com.sadellie.unitto.core.ui.common.SettingsButton
|
|
||||||
import com.sadellie.unitto.core.ui.common.textfield.FormatterSymbols
|
import com.sadellie.unitto.core.ui.common.textfield.FormatterSymbols
|
||||||
import com.sadellie.unitto.data.model.HistoryItem
|
import com.sadellie.unitto.data.model.HistoryItem
|
||||||
import com.sadellie.unitto.feature.calculator.components.CalculatorKeyboard
|
import com.sadellie.unitto.feature.calculator.components.CalculatorKeyboard
|
||||||
@ -83,24 +82,22 @@ import kotlin.math.roundToInt
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun CalculatorRoute(
|
internal fun CalculatorRoute(
|
||||||
navigateToMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
viewModel: CalculatorViewModel = hiltViewModel(),
|
||||||
viewModel: CalculatorViewModel = hiltViewModel()
|
|
||||||
) {
|
) {
|
||||||
val uiState = viewModel.uiState.collectAsStateWithLifecycle()
|
val uiState = viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
CalculatorScreen(
|
CalculatorScreen(
|
||||||
uiState = uiState.value,
|
uiState = uiState.value,
|
||||||
navigateToMenu = navigateToMenu,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings,
|
|
||||||
addTokens = viewModel::addTokens,
|
addTokens = viewModel::addTokens,
|
||||||
|
addBracket = viewModel::addBracket,
|
||||||
clearInput = viewModel::clearInput,
|
clearInput = viewModel::clearInput,
|
||||||
deleteTokens = viewModel::deleteTokens,
|
deleteTokens = viewModel::deleteTokens,
|
||||||
onValueChange = viewModel::updateInput,
|
onValueChange = viewModel::updateInput,
|
||||||
toggleCalculatorMode = viewModel::updateRadianMode,
|
toggleCalculatorMode = viewModel::updateRadianMode,
|
||||||
equal = viewModel::equal,
|
equal = viewModel::equal,
|
||||||
clearHistory = viewModel::clearHistory,
|
clearHistory = viewModel::clearHistory,
|
||||||
addBracket = viewModel::addBracket,
|
|
||||||
onDelete = viewModel::deleteHistoryItem,
|
onDelete = viewModel::deleteHistoryItem,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -108,8 +105,7 @@ internal fun CalculatorRoute(
|
|||||||
@Composable
|
@Composable
|
||||||
internal fun CalculatorScreen(
|
internal fun CalculatorScreen(
|
||||||
uiState: CalculatorUIState,
|
uiState: CalculatorUIState,
|
||||||
navigateToMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
addTokens: (String) -> Unit,
|
addTokens: (String) -> Unit,
|
||||||
addBracket: () -> Unit,
|
addBracket: () -> Unit,
|
||||||
clearInput: () -> Unit,
|
clearInput: () -> Unit,
|
||||||
@ -124,16 +120,15 @@ internal fun CalculatorScreen(
|
|||||||
is CalculatorUIState.Loading -> EmptyScreen()
|
is CalculatorUIState.Loading -> EmptyScreen()
|
||||||
is CalculatorUIState.Ready -> Ready(
|
is CalculatorUIState.Ready -> Ready(
|
||||||
uiState = uiState,
|
uiState = uiState,
|
||||||
navigateToMenu = navigateToMenu,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings,
|
|
||||||
addSymbol = addTokens,
|
addSymbol = addTokens,
|
||||||
|
addBracket = addBracket,
|
||||||
clearSymbols = clearInput,
|
clearSymbols = clearInput,
|
||||||
deleteSymbol = deleteTokens,
|
deleteSymbol = deleteTokens,
|
||||||
onValueChange = onValueChange,
|
onValueChange = onValueChange,
|
||||||
toggleAngleMode = { toggleCalculatorMode(!uiState.radianMode) },
|
toggleAngleMode = { toggleCalculatorMode(!uiState.radianMode) },
|
||||||
equal = equal,
|
equal = equal,
|
||||||
clearHistory = clearHistory,
|
clearHistory = clearHistory,
|
||||||
addBracket = addBracket,
|
|
||||||
onDelete = onDelete,
|
onDelete = onDelete,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -142,8 +137,7 @@ internal fun CalculatorScreen(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun Ready(
|
private fun Ready(
|
||||||
uiState: CalculatorUIState.Ready,
|
uiState: CalculatorUIState.Ready,
|
||||||
navigateToMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
addSymbol: (String) -> Unit,
|
addSymbol: (String) -> Unit,
|
||||||
addBracket: () -> Unit,
|
addBracket: () -> Unit,
|
||||||
clearSymbols: () -> Unit,
|
clearSymbols: () -> Unit,
|
||||||
@ -167,25 +161,21 @@ private fun Ready(
|
|||||||
val isOpen = dragState.currentValue == DragState.OPEN
|
val isOpen = dragState.currentValue == DragState.OPEN
|
||||||
|
|
||||||
ScaffoldWithTopBar(
|
ScaffoldWithTopBar(
|
||||||
title = { Text(stringResource(R.string.calculator_title)) },
|
title = {},
|
||||||
navigationIcon = { MenuButton { navigateToMenu() } },
|
navigationIcon = { DrawerButton { openDrawer() } },
|
||||||
colors = TopAppBarDefaults.topAppBarColors(MaterialTheme.colorScheme.surfaceVariant),
|
colors = TopAppBarDefaults.topAppBarColors(MaterialTheme.colorScheme.surfaceVariant),
|
||||||
actions = {
|
actions = {
|
||||||
Crossfade(isOpen, label = "Clear button reveal") {
|
AnimatedVisibility(isOpen, label = "Clear button reveal") {
|
||||||
if (it) {
|
IconButton(
|
||||||
IconButton(
|
onClick = { showClearHistoryDialog = true },
|
||||||
onClick = { showClearHistoryDialog = true },
|
content = {
|
||||||
content = {
|
Icon(
|
||||||
Icon(
|
Icons.Default.Delete,
|
||||||
Icons.Default.Delete,
|
stringResource(R.string.clear_history_label)
|
||||||
stringResource(R.string.clear_history_label)
|
)
|
||||||
)
|
},
|
||||||
},
|
modifier = Modifier.semantics { testTag = "historyButton" }
|
||||||
modifier = Modifier.semantics { testTag = "historyButton" }
|
)
|
||||||
)
|
|
||||||
} else {
|
|
||||||
SettingsButton(navigateToSettings)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
@ -371,16 +361,15 @@ private fun PreviewCalculatorScreen() {
|
|||||||
acButton = true,
|
acButton = true,
|
||||||
partialHistoryView = true
|
partialHistoryView = true
|
||||||
),
|
),
|
||||||
navigateToMenu = {},
|
openDrawer = {},
|
||||||
navigateToSettings = {},
|
|
||||||
addTokens = {},
|
addTokens = {},
|
||||||
|
addBracket = {},
|
||||||
clearInput = {},
|
clearInput = {},
|
||||||
deleteTokens = {},
|
deleteTokens = {},
|
||||||
onValueChange = {},
|
onValueChange = {},
|
||||||
toggleCalculatorMode = {},
|
toggleCalculatorMode = {},
|
||||||
equal = {},
|
equal = {},
|
||||||
clearHistory = {},
|
clearHistory = {},
|
||||||
addBracket = {},
|
|
||||||
onDelete = {},
|
onDelete = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -30,7 +30,6 @@ private val start = DrawerItem.Calculator.start
|
|||||||
|
|
||||||
fun NavGraphBuilder.calculatorGraph(
|
fun NavGraphBuilder.calculatorGraph(
|
||||||
openDrawer: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit
|
|
||||||
) {
|
) {
|
||||||
unittoNavigation(
|
unittoNavigation(
|
||||||
startDestination = start,
|
startDestination = start,
|
||||||
@ -41,8 +40,7 @@ fun NavGraphBuilder.calculatorGraph(
|
|||||||
) {
|
) {
|
||||||
unittoComposable(start) {
|
unittoComposable(start) {
|
||||||
CalculatorRoute(
|
CalculatorRoute(
|
||||||
navigateToMenu = openDrawer,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,11 +75,10 @@ import com.sadellie.unitto.core.base.R
|
|||||||
import com.sadellie.unitto.core.base.Token
|
import com.sadellie.unitto.core.base.Token
|
||||||
import com.sadellie.unitto.core.ui.LocalLocale
|
import com.sadellie.unitto.core.ui.LocalLocale
|
||||||
import com.sadellie.unitto.core.ui.common.ColumnWithConstraints
|
import com.sadellie.unitto.core.ui.common.ColumnWithConstraints
|
||||||
|
import com.sadellie.unitto.core.ui.common.DrawerButton
|
||||||
import com.sadellie.unitto.core.ui.common.EmptyScreen
|
import com.sadellie.unitto.core.ui.common.EmptyScreen
|
||||||
import com.sadellie.unitto.core.ui.common.MenuButton
|
|
||||||
import com.sadellie.unitto.core.ui.common.PortraitLandscape
|
import com.sadellie.unitto.core.ui.common.PortraitLandscape
|
||||||
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
|
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
|
||||||
import com.sadellie.unitto.core.ui.common.SettingsButton
|
|
||||||
import com.sadellie.unitto.core.ui.common.textfield.ExpressionTextField
|
import com.sadellie.unitto.core.ui.common.textfield.ExpressionTextField
|
||||||
import com.sadellie.unitto.core.ui.common.textfield.FormatterSymbols
|
import com.sadellie.unitto.core.ui.common.textfield.FormatterSymbols
|
||||||
import com.sadellie.unitto.core.ui.common.textfield.NumberBaseTextField
|
import com.sadellie.unitto.core.ui.common.textfield.NumberBaseTextField
|
||||||
@ -99,8 +98,7 @@ internal fun ConverterRoute(
|
|||||||
viewModel: ConverterViewModel = hiltViewModel(),
|
viewModel: ConverterViewModel = hiltViewModel(),
|
||||||
navigateToLeftScreen: (uiState: UnitConverterUIState) -> Unit,
|
navigateToLeftScreen: (uiState: UnitConverterUIState) -> Unit,
|
||||||
navigateToRightScreen: (uiState: UnitConverterUIState) -> Unit,
|
navigateToRightScreen: (uiState: UnitConverterUIState) -> Unit,
|
||||||
navigateToMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
) {
|
) {
|
||||||
val uiState = viewModel.converterUiState.collectAsStateWithLifecycle()
|
val uiState = viewModel.converterUiState.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
@ -108,8 +106,7 @@ internal fun ConverterRoute(
|
|||||||
uiState = uiState.value,
|
uiState = uiState.value,
|
||||||
navigateToLeftScreen = navigateToLeftScreen,
|
navigateToLeftScreen = navigateToLeftScreen,
|
||||||
navigateToRightScreen = navigateToRightScreen,
|
navigateToRightScreen = navigateToRightScreen,
|
||||||
navigateToSettings = navigateToSettings,
|
openDrawer = openDrawer,
|
||||||
navigateToMenu = navigateToMenu,
|
|
||||||
swapUnits = viewModel::swapUnits,
|
swapUnits = viewModel::swapUnits,
|
||||||
processInput = viewModel::addTokens,
|
processInput = viewModel::addTokens,
|
||||||
deleteDigit = viewModel::deleteTokens,
|
deleteDigit = viewModel::deleteTokens,
|
||||||
@ -126,8 +123,7 @@ private fun ConverterScreen(
|
|||||||
uiState: UnitConverterUIState,
|
uiState: UnitConverterUIState,
|
||||||
navigateToLeftScreen: (uiState: UnitConverterUIState) -> Unit,
|
navigateToLeftScreen: (uiState: UnitConverterUIState) -> Unit,
|
||||||
navigateToRightScreen: (uiState: UnitConverterUIState) -> Unit,
|
navigateToRightScreen: (uiState: UnitConverterUIState) -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToMenu: () -> Unit,
|
|
||||||
swapUnits: () -> Unit,
|
swapUnits: () -> Unit,
|
||||||
processInput: (String) -> Unit,
|
processInput: (String) -> Unit,
|
||||||
deleteDigit: () -> Unit,
|
deleteDigit: () -> Unit,
|
||||||
@ -142,8 +138,7 @@ private fun ConverterScreen(
|
|||||||
|
|
||||||
is UnitConverterUIState.NumberBase -> {
|
is UnitConverterUIState.NumberBase -> {
|
||||||
UnitConverterTopBar(
|
UnitConverterTopBar(
|
||||||
navigateToMenu = navigateToMenu,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings
|
|
||||||
) {
|
) {
|
||||||
NumberBase(
|
NumberBase(
|
||||||
modifier = Modifier.padding(it),
|
modifier = Modifier.padding(it),
|
||||||
@ -161,8 +156,7 @@ private fun ConverterScreen(
|
|||||||
|
|
||||||
is UnitConverterUIState.Default -> {
|
is UnitConverterUIState.Default -> {
|
||||||
UnitConverterTopBar(
|
UnitConverterTopBar(
|
||||||
navigateToMenu = navigateToMenu,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings
|
|
||||||
) {
|
) {
|
||||||
Default(
|
Default(
|
||||||
modifier = Modifier.padding(it),
|
modifier = Modifier.padding(it),
|
||||||
@ -185,16 +179,12 @@ private fun ConverterScreen(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun UnitConverterTopBar(
|
private fun UnitConverterTopBar(
|
||||||
navigateToMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
content: @Composable (PaddingValues) -> Unit
|
content: @Composable (PaddingValues) -> Unit
|
||||||
) {
|
) {
|
||||||
ScaffoldWithTopBar(
|
ScaffoldWithTopBar(
|
||||||
title = { Text(stringResource(R.string.unit_converter_title)) },
|
title = {},
|
||||||
navigationIcon = { MenuButton { navigateToMenu() } },
|
navigationIcon = { DrawerButton { openDrawer() } },
|
||||||
actions = {
|
|
||||||
SettingsButton(navigateToSettings)
|
|
||||||
},
|
|
||||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||||
content = { content(it) }
|
content = { content(it) }
|
||||||
)
|
)
|
||||||
@ -584,8 +574,7 @@ private fun PreviewConverterScreen() {
|
|||||||
uiState = UnitConverterUIState.Loading,
|
uiState = UnitConverterUIState.Loading,
|
||||||
navigateToLeftScreen = {},
|
navigateToLeftScreen = {},
|
||||||
navigateToRightScreen = {},
|
navigateToRightScreen = {},
|
||||||
navigateToSettings = {},
|
openDrawer = {},
|
||||||
navigateToMenu = {},
|
|
||||||
swapUnits = {},
|
swapUnits = {},
|
||||||
processInput = {},
|
processInput = {},
|
||||||
deleteDigit = {},
|
deleteDigit = {},
|
||||||
@ -593,6 +582,6 @@ private fun PreviewConverterScreen() {
|
|||||||
onValueChange = {},
|
onValueChange = {},
|
||||||
onFocusOnInput2 = {},
|
onFocusOnInput2 = {},
|
||||||
onErrorClick = {},
|
onErrorClick = {},
|
||||||
addBracket = {}
|
addBracket = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,6 @@ private fun NavHostController.navigateRight(
|
|||||||
fun NavGraphBuilder.converterGraph(
|
fun NavGraphBuilder.converterGraph(
|
||||||
openDrawer: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
navigateToUnitGroups: () -> Unit,
|
navigateToUnitGroups: () -> Unit,
|
||||||
) {
|
) {
|
||||||
unittoNavigation(
|
unittoNavigation(
|
||||||
@ -127,8 +126,7 @@ fun NavGraphBuilder.converterGraph(
|
|||||||
UnitConverterUIState.Loading -> Unit
|
UnitConverterUIState.Loading -> Unit
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
navigateToSettings = navigateToSettings,
|
openDrawer = openDrawer,
|
||||||
navigateToMenu = openDrawer
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +35,7 @@ import androidx.compose.ui.platform.LocalFocusManager
|
|||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import com.sadellie.unitto.core.base.R
|
import com.sadellie.unitto.core.base.R
|
||||||
import com.sadellie.unitto.core.ui.common.MenuButton
|
import com.sadellie.unitto.core.ui.common.DrawerButton
|
||||||
import com.sadellie.unitto.core.ui.common.SettingsButton
|
|
||||||
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
|
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
|
||||||
import com.sadellie.unitto.feature.datecalculator.addsubtract.AddSubtractPage
|
import com.sadellie.unitto.feature.datecalculator.addsubtract.AddSubtractPage
|
||||||
import com.sadellie.unitto.feature.datecalculator.difference.DateDifferencePage
|
import com.sadellie.unitto.feature.datecalculator.difference.DateDifferencePage
|
||||||
@ -44,19 +43,16 @@ import kotlinx.coroutines.launch
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun DateCalculatorRoute(
|
internal fun DateCalculatorRoute(
|
||||||
navigateToMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
) {
|
) {
|
||||||
DateCalculatorScreen(
|
DateCalculatorScreen(
|
||||||
navigateToMenu = navigateToMenu,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun DateCalculatorScreen(
|
internal fun DateCalculatorScreen(
|
||||||
navigateToMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
) {
|
) {
|
||||||
val addSubtractLabel = "${stringResource(R.string.date_calculator_add)}/${stringResource(R.string.date_calculator_subtract)}"
|
val addSubtractLabel = "${stringResource(R.string.date_calculator_add)}/${stringResource(R.string.date_calculator_subtract)}"
|
||||||
val differenceLabel = stringResource(R.string.date_calculator_difference)
|
val differenceLabel = stringResource(R.string.date_calculator_difference)
|
||||||
@ -69,8 +65,7 @@ internal fun DateCalculatorScreen(
|
|||||||
ScaffoldWithTopBar(
|
ScaffoldWithTopBar(
|
||||||
modifier = Modifier,
|
modifier = Modifier,
|
||||||
title = { Text(stringResource(R.string.date_calculator_title)) },
|
title = { Text(stringResource(R.string.date_calculator_title)) },
|
||||||
navigationIcon = { MenuButton(navigateToMenu) },
|
navigationIcon = { DrawerButton(openDrawer) },
|
||||||
actions = { SettingsButton(navigateToSettings) },
|
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(paddingValues),
|
modifier = Modifier.padding(paddingValues),
|
||||||
@ -111,7 +106,6 @@ internal fun DateCalculatorScreen(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun DateCalculatorScreenPreview() {
|
private fun DateCalculatorScreenPreview() {
|
||||||
DateCalculatorScreen(
|
DateCalculatorScreen(
|
||||||
navigateToMenu = {},
|
openDrawer = {},
|
||||||
navigateToSettings = {},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,7 @@ private val graph = DrawerItem.DateCalculator.graph
|
|||||||
private val start = DrawerItem.DateCalculator.start
|
private val start = DrawerItem.DateCalculator.start
|
||||||
|
|
||||||
fun NavGraphBuilder.dateCalculatorGraph(
|
fun NavGraphBuilder.dateCalculatorGraph(
|
||||||
navigateToMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit
|
|
||||||
) {
|
) {
|
||||||
unittoNavigation(
|
unittoNavigation(
|
||||||
startDestination = start,
|
startDestination = start,
|
||||||
@ -41,8 +40,7 @@ fun NavGraphBuilder.dateCalculatorGraph(
|
|||||||
) {
|
) {
|
||||||
unittoComposable(start) {
|
unittoComposable(start) {
|
||||||
DateCalculatorRoute(
|
DateCalculatorRoute(
|
||||||
navigateToMenu = navigateToMenu,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,10 +75,12 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
|||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.sadellie.unitto.core.base.BuildConfig
|
import com.sadellie.unitto.core.base.BuildConfig
|
||||||
import com.sadellie.unitto.core.base.R
|
import com.sadellie.unitto.core.base.R
|
||||||
|
import com.sadellie.unitto.core.ui.LocalWindowSize
|
||||||
|
import com.sadellie.unitto.core.ui.WindowWidthSizeClass
|
||||||
import com.sadellie.unitto.core.ui.common.EmptyScreen
|
import com.sadellie.unitto.core.ui.common.EmptyScreen
|
||||||
import com.sadellie.unitto.core.ui.common.Header
|
import com.sadellie.unitto.core.ui.common.Header
|
||||||
import com.sadellie.unitto.core.ui.common.ListItem
|
import com.sadellie.unitto.core.ui.common.ListItem
|
||||||
import com.sadellie.unitto.core.ui.common.NavigateUpButton
|
import com.sadellie.unitto.core.ui.common.DrawerButton
|
||||||
import com.sadellie.unitto.core.ui.common.ScaffoldWithLargeTopBar
|
import com.sadellie.unitto.core.ui.common.ScaffoldWithLargeTopBar
|
||||||
import com.sadellie.unitto.core.ui.openLink
|
import com.sadellie.unitto.core.ui.openLink
|
||||||
import com.sadellie.unitto.core.ui.showToast
|
import com.sadellie.unitto.core.ui.showToast
|
||||||
@ -97,7 +99,7 @@ import java.time.format.DateTimeFormatter
|
|||||||
@Composable
|
@Composable
|
||||||
internal fun SettingsRoute(
|
internal fun SettingsRoute(
|
||||||
viewModel: SettingsViewModel = hiltViewModel(),
|
viewModel: SettingsViewModel = hiltViewModel(),
|
||||||
navigateUp: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navControllerAction: (String) -> Unit,
|
navControllerAction: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val mContext = LocalContext.current
|
val mContext = LocalContext.current
|
||||||
@ -115,7 +117,7 @@ internal fun SettingsRoute(
|
|||||||
|
|
||||||
is SettingsUIState.Ready -> SettingsScreen(
|
is SettingsUIState.Ready -> SettingsScreen(
|
||||||
uiState = uiState,
|
uiState = uiState,
|
||||||
navigateUp = navigateUp,
|
openDrawer = openDrawer,
|
||||||
navControllerAction = navControllerAction,
|
navControllerAction = navControllerAction,
|
||||||
updateLastReadChangelog = viewModel::updateLastReadChangelog,
|
updateLastReadChangelog = viewModel::updateLastReadChangelog,
|
||||||
updateVibrations = viewModel::updateVibrations,
|
updateVibrations = viewModel::updateVibrations,
|
||||||
@ -129,7 +131,7 @@ internal fun SettingsRoute(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun SettingsScreen(
|
private fun SettingsScreen(
|
||||||
uiState: SettingsUIState.Ready,
|
uiState: SettingsUIState.Ready,
|
||||||
navigateUp: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navControllerAction: (String) -> Unit,
|
navControllerAction: (String) -> Unit,
|
||||||
updateLastReadChangelog: (String) -> Unit,
|
updateLastReadChangelog: (String) -> Unit,
|
||||||
updateVibrations: (Boolean) -> Unit,
|
updateVibrations: (Boolean) -> Unit,
|
||||||
@ -158,7 +160,11 @@ private fun SettingsScreen(
|
|||||||
|
|
||||||
ScaffoldWithLargeTopBar(
|
ScaffoldWithLargeTopBar(
|
||||||
title = stringResource(R.string.settings_title),
|
title = stringResource(R.string.settings_title),
|
||||||
navigationIcon = { NavigateUpButton(navigateUp) },
|
navigationIcon = {
|
||||||
|
if (LocalWindowSize.current.widthSizeClass != WindowWidthSizeClass.Expanded) {
|
||||||
|
DrawerButton(openDrawer)
|
||||||
|
}
|
||||||
|
},
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = { showMenu = !showMenu },
|
onClick = { showMenu = !showMenu },
|
||||||
@ -336,7 +342,7 @@ private fun PreviewSettingsScreen() {
|
|||||||
|
|
||||||
SettingsScreen(
|
SettingsScreen(
|
||||||
uiState = uiState,
|
uiState = uiState,
|
||||||
navigateUp = {},
|
openDrawer = {},
|
||||||
navControllerAction = {},
|
navControllerAction = {},
|
||||||
updateLastReadChangelog = {
|
updateLastReadChangelog = {
|
||||||
uiState = uiState.copy(showUpdateChangelog = false)
|
uiState = uiState.copy(showUpdateChangelog = false)
|
||||||
|
@ -51,17 +51,14 @@ internal const val calculatorSettingsRoute = "calculator_settings_route"
|
|||||||
internal const val converterSettingsRoute = "converter_settings_route"
|
internal const val converterSettingsRoute = "converter_settings_route"
|
||||||
internal const val bouncingEmoji = "bouncing_emoji_route"
|
internal const val bouncingEmoji = "bouncing_emoji_route"
|
||||||
|
|
||||||
fun NavController.navigateToSettings() {
|
|
||||||
navigate(DrawerItem.Settings.start)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun NavController.navigateToUnitGroups() {
|
fun NavController.navigateToUnitGroups() {
|
||||||
navigate(unitsGroupRoute)
|
navigate(unitsGroupRoute)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NavGraphBuilder.settingGraph(
|
fun NavGraphBuilder.settingGraph(
|
||||||
themmoController: ThemmoController,
|
openDrawer: () -> Unit,
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
|
themmoController: ThemmoController,
|
||||||
) {
|
) {
|
||||||
unittoNavigation(
|
unittoNavigation(
|
||||||
startDestination = start,
|
startDestination = start,
|
||||||
@ -72,7 +69,7 @@ fun NavGraphBuilder.settingGraph(
|
|||||||
) {
|
) {
|
||||||
unittoStackedComposable(start) {
|
unittoStackedComposable(start) {
|
||||||
SettingsRoute(
|
SettingsRoute(
|
||||||
navigateUp = navController::navigateUp,
|
openDrawer = openDrawer,
|
||||||
navControllerAction = navController::navigate
|
navControllerAction = navController::navigate
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -73,8 +73,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.sadellie.unitto.core.base.R
|
import com.sadellie.unitto.core.base.R
|
||||||
import com.sadellie.unitto.core.ui.common.MenuButton
|
import com.sadellie.unitto.core.ui.common.DrawerButton
|
||||||
import com.sadellie.unitto.core.ui.common.SettingsButton
|
|
||||||
import com.sadellie.unitto.core.ui.common.EmptyScreen
|
import com.sadellie.unitto.core.ui.common.EmptyScreen
|
||||||
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
|
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
|
||||||
import com.sadellie.unitto.core.ui.common.datetimepicker.TimePickerDialog
|
import com.sadellie.unitto.core.ui.common.datetimepicker.TimePickerDialog
|
||||||
@ -94,8 +93,7 @@ import java.time.ZonedDateTime
|
|||||||
@Composable
|
@Composable
|
||||||
internal fun TimeZoneRoute(
|
internal fun TimeZoneRoute(
|
||||||
viewModel: TimeZoneViewModel = hiltViewModel(),
|
viewModel: TimeZoneViewModel = hiltViewModel(),
|
||||||
openMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
navigateToAddTimeZone: (ZonedDateTime) -> Unit,
|
navigateToAddTimeZone: (ZonedDateTime) -> Unit,
|
||||||
) {
|
) {
|
||||||
when (val uiState = viewModel.uiState.collectAsStateWithLifecycle().value) {
|
when (val uiState = viewModel.uiState.collectAsStateWithLifecycle().value) {
|
||||||
@ -103,8 +101,7 @@ internal fun TimeZoneRoute(
|
|||||||
is TimeZoneUIState.Ready -> {
|
is TimeZoneUIState.Ready -> {
|
||||||
TimeZoneScreen(
|
TimeZoneScreen(
|
||||||
uiState = uiState,
|
uiState = uiState,
|
||||||
openMenu = openMenu,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings,
|
|
||||||
navigateToAddTimeZone = navigateToAddTimeZone,
|
navigateToAddTimeZone = navigateToAddTimeZone,
|
||||||
setCurrentTime = viewModel::setCurrentTime,
|
setCurrentTime = viewModel::setCurrentTime,
|
||||||
setSelectedTime = viewModel::setSelectedTime,
|
setSelectedTime = viewModel::setSelectedTime,
|
||||||
@ -122,8 +119,7 @@ internal fun TimeZoneRoute(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun TimeZoneScreen(
|
private fun TimeZoneScreen(
|
||||||
uiState: TimeZoneUIState.Ready,
|
uiState: TimeZoneUIState.Ready,
|
||||||
openMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
navigateToAddTimeZone: (ZonedDateTime) -> Unit,
|
navigateToAddTimeZone: (ZonedDateTime) -> Unit,
|
||||||
setCurrentTime: () -> Unit,
|
setCurrentTime: () -> Unit,
|
||||||
setSelectedTime: (ZonedDateTime) -> Unit,
|
setSelectedTime: (ZonedDateTime) -> Unit,
|
||||||
@ -179,8 +175,7 @@ private fun TimeZoneScreen(
|
|||||||
|
|
||||||
ScaffoldWithTopBar(
|
ScaffoldWithTopBar(
|
||||||
title = { Text(stringResource(R.string.time_zone_title)) },
|
title = { Text(stringResource(R.string.time_zone_title)) },
|
||||||
navigationIcon = { MenuButton(openMenu) },
|
navigationIcon = { DrawerButton(openDrawer) },
|
||||||
actions = { SettingsButton(navigateToSettings) },
|
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
LargeFloatingActionButton(
|
LargeFloatingActionButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
@ -366,8 +361,7 @@ fun PreviewTimeZoneScreen() {
|
|||||||
selectedTimeZone = null,
|
selectedTimeZone = null,
|
||||||
dialogState = TimeZoneDialogState.Nothing
|
dialogState = TimeZoneDialogState.Nothing
|
||||||
),
|
),
|
||||||
openMenu = {},
|
openDrawer = {},
|
||||||
navigateToSettings = {},
|
|
||||||
navigateToAddTimeZone = {},
|
navigateToAddTimeZone = {},
|
||||||
setCurrentTime = {},
|
setCurrentTime = {},
|
||||||
setSelectedTime = {},
|
setSelectedTime = {},
|
||||||
@ -375,6 +369,6 @@ fun PreviewTimeZoneScreen() {
|
|||||||
delete = {},
|
delete = {},
|
||||||
updateLabel = { _, _ -> },
|
updateLabel = { _, _ -> },
|
||||||
selectTimeZone = {},
|
selectTimeZone = {},
|
||||||
setDialogState = {}
|
setDialogState = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,7 @@ private fun NavController.navigateToAddTimeZone(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun NavGraphBuilder.timeZoneGraph(
|
fun NavGraphBuilder.timeZoneGraph(
|
||||||
navigateToMenu: () -> Unit,
|
openDrawer: () -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
) {
|
) {
|
||||||
unittoNavigation(
|
unittoNavigation(
|
||||||
@ -68,8 +67,7 @@ fun NavGraphBuilder.timeZoneGraph(
|
|||||||
}
|
}
|
||||||
|
|
||||||
TimeZoneRoute(
|
TimeZoneRoute(
|
||||||
openMenu = navigateToMenu,
|
openDrawer = openDrawer,
|
||||||
navigateToSettings = navigateToSettings,
|
|
||||||
navigateToAddTimeZone = navController::navigateToAddTimeZone
|
navigateToAddTimeZone = navController::navigateToAddTimeZone
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user