mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 08:45:27 +02:00
Settings button in calculator
This commit is contained in:
parent
951523a235
commit
30b97ef821
@ -91,7 +91,10 @@ fun UnittoNavigation(
|
|||||||
navigateToEpoch = { navController.navigateToEpoch(navController.clearStack) }
|
navigateToEpoch = { navController.navigateToEpoch(navController.clearStack) }
|
||||||
)
|
)
|
||||||
|
|
||||||
calculatorScreen(navigateToMenu = navController::navigateToTools)
|
calculatorScreen(
|
||||||
|
navigateToMenu = navController::navigateToTools,
|
||||||
|
navigateToSettings = navController::navigateToSettings
|
||||||
|
)
|
||||||
|
|
||||||
epochScreen(navigateToMenu = navController::navigateToTools)
|
epochScreen(navigateToMenu = navController::navigateToTools)
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,8 @@
|
|||||||
|
|
||||||
package com.sadellie.unitto.feature.calculator
|
package com.sadellie.unitto.feature.calculator
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.Crossfade
|
||||||
import androidx.compose.animation.core.animateFloatAsState
|
import androidx.compose.animation.core.animateFloatAsState
|
||||||
import androidx.compose.animation.fadeIn
|
|
||||||
import androidx.compose.animation.fadeOut
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.gestures.Orientation
|
import androidx.compose.foundation.gestures.Orientation
|
||||||
import androidx.compose.foundation.gestures.draggable
|
import androidx.compose.foundation.gestures.draggable
|
||||||
@ -36,6 +34,7 @@ import androidx.compose.foundation.layout.sizeIn
|
|||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Delete
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material.icons.outlined.MoreVert
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
@ -76,6 +75,7 @@ import kotlin.math.roundToInt
|
|||||||
@Composable
|
@Composable
|
||||||
internal fun CalculatorRoute(
|
internal fun CalculatorRoute(
|
||||||
navigateToMenu: () -> Unit,
|
navigateToMenu: () -> Unit,
|
||||||
|
navigateToSettings: () -> Unit,
|
||||||
viewModel: CalculatorViewModel = hiltViewModel()
|
viewModel: CalculatorViewModel = hiltViewModel()
|
||||||
) {
|
) {
|
||||||
val uiState = viewModel.uiState.collectAsStateWithLifecycle()
|
val uiState = viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
@ -83,6 +83,7 @@ internal fun CalculatorRoute(
|
|||||||
CalculatorScreen(
|
CalculatorScreen(
|
||||||
uiState = uiState.value,
|
uiState = uiState.value,
|
||||||
navigateToMenu = navigateToMenu,
|
navigateToMenu = navigateToMenu,
|
||||||
|
navigateToSettings = navigateToSettings,
|
||||||
addSymbol = viewModel::addSymbol,
|
addSymbol = viewModel::addSymbol,
|
||||||
clearSymbols = viewModel::clearSymbols,
|
clearSymbols = viewModel::clearSymbols,
|
||||||
deleteSymbol = viewModel::deleteSymbol,
|
deleteSymbol = viewModel::deleteSymbol,
|
||||||
@ -97,6 +98,7 @@ internal fun CalculatorRoute(
|
|||||||
private fun CalculatorScreen(
|
private fun CalculatorScreen(
|
||||||
uiState: CalculatorUIState,
|
uiState: CalculatorUIState,
|
||||||
navigateToMenu: () -> Unit,
|
navigateToMenu: () -> Unit,
|
||||||
|
navigateToSettings: () -> Unit,
|
||||||
addSymbol: (String) -> Unit,
|
addSymbol: (String) -> Unit,
|
||||||
clearSymbols: () -> Unit,
|
clearSymbols: () -> Unit,
|
||||||
deleteSymbol: () -> Unit,
|
deleteSymbol: () -> Unit,
|
||||||
@ -118,20 +120,25 @@ private fun CalculatorScreen(
|
|||||||
navigationIcon = { MenuButton { navigateToMenu() } },
|
navigationIcon = { MenuButton { navigateToMenu() } },
|
||||||
colors = TopAppBarDefaults.topAppBarColors(MaterialTheme.colorScheme.surfaceVariant),
|
colors = TopAppBarDefaults.topAppBarColors(MaterialTheme.colorScheme.surfaceVariant),
|
||||||
actions = {
|
actions = {
|
||||||
AnimatedVisibility(
|
Crossfade(showClearHistoryButton) {
|
||||||
visible = showClearHistoryButton,
|
if (it) {
|
||||||
enter = fadeIn(),
|
IconButton(
|
||||||
exit = fadeOut()
|
onClick = { showClearHistoryDialog = true },
|
||||||
) {
|
content = {
|
||||||
IconButton(
|
Icon(
|
||||||
onClick = { showClearHistoryDialog = true },
|
Icons.Default.Delete,
|
||||||
content = {
|
stringResource(R.string.calculator_clear_history_title)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
IconButton(onClick = navigateToSettings) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Delete,
|
Icons.Outlined.MoreVert,
|
||||||
stringResource(R.string.calculator_clear_history_title)
|
contentDescription = stringResource(R.string.open_settings_description)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
@ -288,6 +295,7 @@ private fun PreviewCalculatorScreen() {
|
|||||||
history = historyItems
|
history = historyItems
|
||||||
),
|
),
|
||||||
navigateToMenu = {},
|
navigateToMenu = {},
|
||||||
|
navigateToSettings = {},
|
||||||
addSymbol = {},
|
addSymbol = {},
|
||||||
clearSymbols = {},
|
clearSymbols = {},
|
||||||
deleteSymbol = {},
|
deleteSymbol = {},
|
||||||
|
@ -32,13 +32,17 @@ fun NavController.navigateToCalculator(navOptions: NavOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun NavGraphBuilder.calculatorScreen(
|
fun NavGraphBuilder.calculatorScreen(
|
||||||
navigateToMenu: () -> Unit
|
navigateToMenu: () -> Unit,
|
||||||
|
navigateToSettings: () -> Unit
|
||||||
) {
|
) {
|
||||||
composable(
|
composable(
|
||||||
route = calculatorRoute,
|
route = calculatorRoute,
|
||||||
deepLinks = listOf(
|
deepLinks = listOf(
|
||||||
navDeepLink { uriPattern = "app://com.sadellie.unitto/$calculatorRoute" }
|
navDeepLink { uriPattern = "app://com.sadellie.unitto/$calculatorRoute" }
|
||||||
)) {
|
)) {
|
||||||
CalculatorRoute(navigateToMenu = navigateToMenu)
|
CalculatorRoute(
|
||||||
|
navigateToMenu = navigateToMenu,
|
||||||
|
navigateToSettings = navigateToSettings
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user