Skip to content

Commit

Permalink
Cleaner UI
Browse files Browse the repository at this point in the history
closes #182
  • Loading branch information
sadellie committed Feb 10, 2024
1 parent 7cbbb84 commit 80f1624
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 203 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/com/sadellie/unitto/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ internal fun ComponentActivity.App(prefs: AppPreferences?) {
modifier = Modifier,
state = drawerState,
gesturesEnabled = gesturesEnabled,
tabs = DrawerItem.main,
mainTabs = DrawerItem.main,
additionalTabs = DrawerItem.additional,
currentDestination = navBackStackEntry?.destination?.route,
onItemClick = { destination ->
drawerScope.launch { drawerState.close() }
Expand Down
31 changes: 13 additions & 18 deletions app/src/main/java/com/sadellie/unitto/UnittoNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.converter.navigation.converterGraph
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.settingGraph
import com.sadellie.unitto.feature.timezone.navigation.timeZoneGraph
Expand All @@ -48,39 +47,35 @@ internal fun UnittoNavigation(
startDestination = startDestination,
modifier = Modifier.background(MaterialTheme.colorScheme.background),
enterTransition = { fadeIn() },
exitTransition = { fadeOut() }
exitTransition = { fadeOut() },
) {
converterGraph(
calculatorGraph(
openDrawer = openDrawer,
navController = navController,
navigateToSettings = navController::navigateToSettings,
navigateToUnitGroups = navController::navigateToUnitGroups
)

settingGraph(
themmoController = themmoController,
navController = navController
)

calculatorGraph(
converterGraph(
openDrawer = openDrawer,
navigateToSettings = navController::navigateToSettings
navController = navController,
navigateToUnitGroups = navController::navigateToUnitGroups,
)

dateCalculatorGraph(
navigateToMenu = openDrawer,
navigateToSettings = navController::navigateToSettings
openDrawer = openDrawer,
)

timeZoneGraph(
navigateToMenu = openDrawer,
navigateToSettings = navController::navigateToSettings,
openDrawer = openDrawer,
navController = navController,
)

bodyMassGraph(
openDrawer = openDrawer,
navigateToSettings = navController::navigateToSettings,
)

settingGraph(
openDrawer = openDrawer,
navController = navController,
themmoController = themmoController,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ import androidx.compose.ui.res.stringResource
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.
*/
@Composable
fun MenuButton(onClick: () -> Unit) {
fun DrawerButton(onClick: () -> Unit) {
IconButton(onClick = onClick) {
Icon(
Icons.Outlined.Menu,
contentDescription = stringResource(R.string.open_menu_description)
imageVector = Icons.Outlined.Menu,
contentDescription = stringResource(R.string.open_menu_description),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ fun NavigationDrawer(
modifier: Modifier,
gesturesEnabled: Boolean,
state: DrawerState = rememberDrawerState(),
tabs: List<DrawerItem>,
mainTabs: List<DrawerItem>,
additionalTabs: List<DrawerItem>,
currentDestination: String?,
onItemClick: (DrawerItem) -> Unit,
content: @Composable () -> Unit,
Expand All @@ -126,7 +127,8 @@ fun NavigationDrawer(
.verticalScroll(rememberScrollState())
) {
SheetContent(
tabs = tabs,
mainTabs = mainTabs,
additionalTabs = additionalTabs,
currentDestination = currentDestination,
onItemClick = onItemClick
)
Expand All @@ -144,7 +146,8 @@ fun NavigationDrawer(
.verticalScroll(rememberScrollState())
) {
SheetContent(
tabs = tabs,
mainTabs = mainTabs,
additionalTabs = additionalTabs,
currentDestination = currentDestination,
onItemClick = onItemClick
)
Expand Down Expand Up @@ -279,7 +282,8 @@ private fun PreviewUnittoModalNavigationDrawerClose() {
modifier = Modifier,
state = drawerState,
gesturesEnabled = true,
tabs = DrawerItem.main,
mainTabs = DrawerItem.main,
additionalTabs = DrawerItem.additional,
currentDestination = DrawerItem.Calculator.start,
onItemClick = {},
content = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ fun ScaffoldWithTopBar(
) {
CenterAlignedTopAppBar(
title = title,
navigationIcon = if (LocalWindowSize.current.widthSizeClass != WindowWidthSizeClass.Expanded) navigationIcon else { {} },
navigationIcon = {
if (LocalWindowSize.current.widthSizeClass != WindowWidthSizeClass.Expanded) {
navigationIcon()
}
},
actions = actions,
colors = colors,
scrollBehavior = scrollBehavior,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
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 kotlinx.coroutines.delay

@Suppress("UnusedReceiverParameter")
@Composable
internal fun ColumnScope.SheetContent(
tabs: List<DrawerItem>,
mainTabs: List<DrawerItem>,
additionalTabs: List<DrawerItem>,
currentDestination: String?,
onItemClick: (DrawerItem) -> Unit,
) {
Expand Down Expand Up @@ -79,7 +78,7 @@ internal fun ColumnScope.SheetContent(
)
}

tabs.forEach { drawerItem ->
mainTabs.forEach { drawerItem ->
val selected = drawerItem.start == currentDestination
DrawerItem(
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding),
Expand All @@ -90,15 +89,15 @@ internal fun ColumnScope.SheetContent(
)
}

// Top bar (and settings button in it) is not visible for compact height
if (LocalWindowSize.current.heightSizeClass == WindowHeightSizeClass.Compact) {
HorizontalDivider(Modifier.padding(horizontal = 12.dp, vertical = 8.dp))
HorizontalDivider(Modifier.padding(horizontal = 12.dp, vertical = 8.dp))

additionalTabs.forEach { drawerItem ->
val selected = drawerItem.start == currentDestination
DrawerItem(
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding),
destination = DrawerItem.Settings,
icon = DrawerItem.Settings.defaultIcon,
selected = false,
destination = drawerItem,
icon = if (selected) drawerItem.selectedIcon else drawerItem.defaultIcon,
selected = selected,
onClick = onItemClick
)
}
Expand All @@ -109,7 +108,12 @@ internal fun ColumnScope.SheetContent(
private fun PreviewDrawerSheet() {
Column {
SheetContent(
tabs = listOf(
mainTabs = listOf(
DrawerItem.Calculator,
DrawerItem.Calculator,
DrawerItem.Calculator,
),
additionalTabs = listOf(
DrawerItem.Calculator,
DrawerItem.Calculator,
DrawerItem.Calculator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ sealed class DrawerItem(
all
}

val additional = listOf(Settings)

// Only routes, not graphs!
val startRoutes by lazy { main.map { it.start } }
val startRoutes by lazy { (main + additional).map { it.start } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
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.MenuButton
import com.sadellie.unitto.core.ui.common.ScaffoldWithTopBar
import com.sadellie.unitto.core.ui.common.SegmentedButton
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.FormatterSymbols
import com.sadellie.unitto.core.ui.openLink
Expand All @@ -67,8 +66,7 @@ import java.math.BigDecimal
@Composable
internal fun BodyMassRoute(
openDrawer: () -> Unit,
navigateToSettings: () -> Unit,
viewModel: BodyMassViewModel = hiltViewModel()
viewModel: BodyMassViewModel = hiltViewModel(),
) {
when (val uiState = viewModel.uiState.collectAsStateWithLifecycle().value) {
UIState.Loading -> EmptyScreen()
Expand All @@ -79,7 +77,6 @@ internal fun BodyMassRoute(
updateWeight = viewModel::updateWeight,
updateIsMetric = viewModel::updateIsMetric,
openDrawer = openDrawer,
navigateToSettings = navigateToSettings
)
}
}
Expand All @@ -92,7 +89,6 @@ private fun BodyMassScreen(
updateWeight: (TextFieldValue) -> Unit,
updateIsMetric: (Boolean) -> Unit,
openDrawer: () -> Unit,
navigateToSettings: () -> Unit,
) {
val mContext = LocalContext.current
val expressionTransformer = remember(uiState.formatterSymbols) {
Expand All @@ -106,8 +102,7 @@ private fun BodyMassScreen(

ScaffoldWithTopBar(
title = { Text(stringResource(R.string.body_mass_title)) },
navigationIcon = { MenuButton(openDrawer) },
actions = { SettingsButton(navigateToSettings) }
navigationIcon = { DrawerButton(openDrawer) },
) { paddingValues ->
Column(
modifier = Modifier
Expand Down Expand Up @@ -235,6 +230,5 @@ fun PreviewBodyMassScreen() {
updateWeight = {},
updateIsMetric = {},
openDrawer = {},
navigateToSettings = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ private val start = DrawerItem.BodyMass.start

fun NavGraphBuilder.bodyMassGraph(
openDrawer: () -> Unit,
navigateToSettings: () -> Unit
) {
unittoNavigation(
startDestination = start,
Expand All @@ -42,7 +41,6 @@ fun NavGraphBuilder.bodyMassGraph(
unittoComposable(start) {
BodyMassRoute(
openDrawer = openDrawer,
navigateToSettings = navigateToSettings
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ class CalculatorScreenTest {
setContent {
CalculatorScreen(
uiState = CalculatorUIState.Loading,
navigateToMenu = {},
navigateToSettings = {},
openDrawer = {},
addTokens = {},
addBracket = {},
clearInput = {},
deleteTokens = {},
onValueChange = {},
toggleCalculatorMode = {},
equal = {},
clearHistory = {},
addBracket = {},
onDelete = {},
)
}
Expand All @@ -74,16 +73,15 @@ class CalculatorScreenTest {
acButton = true,
partialHistoryView = true
),
navigateToMenu = {},
navigateToSettings = {},
openDrawer = {},
addTokens = {},
addBracket = {},
clearInput = {},
deleteTokens = {},
onValueChange = {},
toggleCalculatorMode = {},
equal = {},
clearHistory = {},
addBracket = {},
onDelete = {},
)
}
Expand All @@ -108,16 +106,15 @@ class CalculatorScreenTest {
acButton = true,
partialHistoryView = true
),
navigateToMenu = {},
navigateToSettings = {},
openDrawer = {},
addTokens = {},
addBracket = {},
clearInput = {},
deleteTokens = {},
onValueChange = {},
toggleCalculatorMode = {},
equal = {},
clearHistory = {},
addBracket = {},
onDelete = {},
)
}
Expand Down
Loading

0 comments on commit 80f1624

Please sign in to comment.