mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 08:45:27 +02:00
Improved navigation
- Clear back stack when navigating between tools - Added unit converter to tools screen - Disabled epoch converter until ready
This commit is contained in:
parent
36befca5da
commit
951523a235
@ -19,13 +19,16 @@
|
|||||||
package com.sadellie.unitto
|
package com.sadellie.unitto
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
|
import androidx.navigation.NavOptions
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import com.sadellie.unitto.feature.calculator.navigation.calculatorScreen
|
import com.sadellie.unitto.feature.calculator.navigation.calculatorScreen
|
||||||
import com.sadellie.unitto.feature.calculator.navigation.navigateToCalculator
|
import com.sadellie.unitto.feature.calculator.navigation.navigateToCalculator
|
||||||
import com.sadellie.unitto.feature.converter.ConverterViewModel
|
import com.sadellie.unitto.feature.converter.ConverterViewModel
|
||||||
import com.sadellie.unitto.feature.converter.navigation.converterRoute
|
import com.sadellie.unitto.feature.converter.navigation.converterRoute
|
||||||
import com.sadellie.unitto.feature.converter.navigation.converterScreen
|
import com.sadellie.unitto.feature.converter.navigation.converterScreen
|
||||||
|
import com.sadellie.unitto.feature.converter.navigation.navigateToConverter
|
||||||
import com.sadellie.unitto.feature.epoch.navigation.epochScreen
|
import com.sadellie.unitto.feature.epoch.navigation.epochScreen
|
||||||
import com.sadellie.unitto.feature.epoch.navigation.navigateToEpoch
|
import com.sadellie.unitto.feature.epoch.navigation.navigateToEpoch
|
||||||
import com.sadellie.unitto.feature.settings.SettingsViewModel
|
import com.sadellie.unitto.feature.settings.SettingsViewModel
|
||||||
@ -57,7 +60,7 @@ fun UnittoNavigation(
|
|||||||
navigateToLeftScreen = navController::navigateToLeftSide,
|
navigateToLeftScreen = navController::navigateToLeftSide,
|
||||||
navigateToRightScreen = navController::navigateToRightSide,
|
navigateToRightScreen = navController::navigateToRightSide,
|
||||||
navigateToSettings = navController::navigateToSettings,
|
navigateToSettings = navController::navigateToSettings,
|
||||||
navigateToTools = navController::navigateToTools,
|
navigateToMenu = navController::navigateToTools,
|
||||||
viewModel = converterViewModel
|
viewModel = converterViewModel
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -83,14 +86,16 @@ fun UnittoNavigation(
|
|||||||
|
|
||||||
toolsScreen(
|
toolsScreen(
|
||||||
navigateUpAction = navController::navigateUp,
|
navigateUpAction = navController::navigateUp,
|
||||||
navigateToCalculator = navController::navigateToCalculator,
|
navigateToConverter = { navController.navigateToConverter(navController.clearStack) },
|
||||||
navigateToEpoch = navController::navigateToEpoch
|
navigateToCalculator = { navController.navigateToCalculator(navController.clearStack) },
|
||||||
|
navigateToEpoch = { navController.navigateToEpoch(navController.clearStack) }
|
||||||
)
|
)
|
||||||
|
|
||||||
calculatorScreen(navigateUpAction = navController::navigateUp)
|
calculatorScreen(navigateToMenu = navController::navigateToTools)
|
||||||
|
|
||||||
epochScreen(
|
epochScreen(navigateToMenu = navController::navigateToTools)
|
||||||
navigateUpAction = navController::navigateUp
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val NavController.clearStack: NavOptions
|
||||||
|
get() = NavOptions.Builder().setPopUpTo(this.graph.id, false).build()
|
@ -1016,9 +1016,12 @@
|
|||||||
<string name="additional_settings_group">Additional</string>
|
<string name="additional_settings_group">Additional</string>
|
||||||
|
|
||||||
<!--Tools-->
|
<!--Tools-->
|
||||||
|
<string name="unit_converter">Unit converter</string>
|
||||||
|
<string name="unit_converter_support">Convert from one unit to another</string>
|
||||||
<string name="epoch_converter">Epoch converter</string>
|
<string name="epoch_converter">Epoch converter</string>
|
||||||
<string name="epoch_converter_support">Convert Unix timestamp</string>
|
<string name="epoch_converter_support">Convert Unix timestamp</string>
|
||||||
<string name="tools_notice_title">Experimental features!</string>
|
<string name="tools_notice_title">Experimental features!</string>
|
||||||
|
<string name="soon_label">Soon</string>
|
||||||
<string name="tools_notice_description">This screen is part of an experiment. It may change in the future.</string>
|
<string name="tools_notice_description">This screen is part of an experiment. It may change in the future.</string>
|
||||||
<string name="click_to_read_more">Click to read more!</string>
|
<string name="click_to_read_more">Click to read more!</string>
|
||||||
|
|
||||||
|
@ -75,14 +75,14 @@ import kotlin.math.roundToInt
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun CalculatorRoute(
|
internal fun CalculatorRoute(
|
||||||
navigateUpAction: () -> Unit,
|
navigateToMenu: () -> 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,
|
||||||
navigateUpAction = navigateUpAction,
|
navigateToMenu = navigateToMenu,
|
||||||
addSymbol = viewModel::addSymbol,
|
addSymbol = viewModel::addSymbol,
|
||||||
clearSymbols = viewModel::clearSymbols,
|
clearSymbols = viewModel::clearSymbols,
|
||||||
deleteSymbol = viewModel::deleteSymbol,
|
deleteSymbol = viewModel::deleteSymbol,
|
||||||
@ -96,7 +96,7 @@ internal fun CalculatorRoute(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun CalculatorScreen(
|
private fun CalculatorScreen(
|
||||||
uiState: CalculatorUIState,
|
uiState: CalculatorUIState,
|
||||||
navigateUpAction: () -> Unit,
|
navigateToMenu: () -> Unit,
|
||||||
addSymbol: (String) -> Unit,
|
addSymbol: (String) -> Unit,
|
||||||
clearSymbols: () -> Unit,
|
clearSymbols: () -> Unit,
|
||||||
deleteSymbol: () -> Unit,
|
deleteSymbol: () -> Unit,
|
||||||
@ -115,7 +115,7 @@ private fun CalculatorScreen(
|
|||||||
|
|
||||||
UnittoScreenWithTopBar(
|
UnittoScreenWithTopBar(
|
||||||
title = { Text(stringResource(R.string.calculator)) },
|
title = { Text(stringResource(R.string.calculator)) },
|
||||||
navigationIcon = { MenuButton { navigateUpAction() } },
|
navigationIcon = { MenuButton { navigateToMenu() } },
|
||||||
colors = TopAppBarDefaults.topAppBarColors(MaterialTheme.colorScheme.surfaceVariant),
|
colors = TopAppBarDefaults.topAppBarColors(MaterialTheme.colorScheme.surfaceVariant),
|
||||||
actions = {
|
actions = {
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
@ -287,7 +287,7 @@ private fun PreviewCalculatorScreen() {
|
|||||||
output = "12345",
|
output = "12345",
|
||||||
history = historyItems
|
history = historyItems
|
||||||
),
|
),
|
||||||
navigateUpAction = {},
|
navigateToMenu = {},
|
||||||
addSymbol = {},
|
addSymbol = {},
|
||||||
clearSymbols = {},
|
clearSymbols = {},
|
||||||
deleteSymbol = {},
|
deleteSymbol = {},
|
||||||
|
@ -20,24 +20,25 @@ package com.sadellie.unitto.feature.calculator.navigation
|
|||||||
|
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
import androidx.navigation.NavOptions
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.navDeepLink
|
import androidx.navigation.navDeepLink
|
||||||
import com.sadellie.unitto.feature.calculator.CalculatorRoute
|
import com.sadellie.unitto.feature.calculator.CalculatorRoute
|
||||||
|
|
||||||
private const val calculatorRoute = "calculator_route"
|
private const val calculatorRoute = "calculator_route"
|
||||||
|
|
||||||
fun NavController.navigateToCalculator() {
|
fun NavController.navigateToCalculator(navOptions: NavOptions) {
|
||||||
navigate(calculatorRoute)
|
navigate(calculatorRoute, navOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NavGraphBuilder.calculatorScreen(
|
fun NavGraphBuilder.calculatorScreen(
|
||||||
navigateUpAction: () -> Unit
|
navigateToMenu: () -> 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(navigateUpAction = navigateUpAction)
|
CalculatorRoute(navigateToMenu = navigateToMenu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,39 +18,30 @@
|
|||||||
|
|
||||||
package com.sadellie.unitto.feature.converter
|
package com.sadellie.unitto.feature.converter
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.MoreVert
|
import androidx.compose.material.icons.outlined.MoreVert
|
||||||
import androidx.compose.material.icons.outlined.Science
|
|
||||||
import androidx.compose.material.ripple.rememberRipple
|
|
||||||
import androidx.compose.material3.Badge
|
|
||||||
import androidx.compose.material3.BadgedBox
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.semantics.Role
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
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.ui.R
|
import com.sadellie.unitto.core.ui.R
|
||||||
import com.sadellie.unitto.core.ui.common.AnimatedTopBarText
|
import com.sadellie.unitto.core.ui.common.AnimatedTopBarText
|
||||||
import com.sadellie.unitto.feature.converter.components.Keyboard
|
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.UnittoScreenWithTopBar
|
import com.sadellie.unitto.core.ui.common.UnittoScreenWithTopBar
|
||||||
|
import com.sadellie.unitto.feature.converter.components.Keyboard
|
||||||
import com.sadellie.unitto.feature.converter.components.TopScreenPart
|
import com.sadellie.unitto.feature.converter.components.TopScreenPart
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
@ -59,7 +50,7 @@ internal fun ConverterRoute(
|
|||||||
viewModel: ConverterViewModel = hiltViewModel(),
|
viewModel: ConverterViewModel = hiltViewModel(),
|
||||||
navigateToLeftScreen: (String) -> Unit,
|
navigateToLeftScreen: (String) -> Unit,
|
||||||
navigateToRightScreen: (unitFrom: String, unitTo: String, input: String) -> Unit,
|
navigateToRightScreen: (unitFrom: String, unitTo: String, input: String) -> Unit,
|
||||||
navigateToTools: () -> Unit,
|
navigateToMenu: () -> Unit,
|
||||||
navigateToSettings: () -> Unit
|
navigateToSettings: () -> Unit
|
||||||
) {
|
) {
|
||||||
val uiState = viewModel.uiStateFlow.collectAsStateWithLifecycle()
|
val uiState = viewModel.uiStateFlow.collectAsStateWithLifecycle()
|
||||||
@ -69,7 +60,7 @@ internal fun ConverterRoute(
|
|||||||
navigateToLeftScreen = navigateToLeftScreen,
|
navigateToLeftScreen = navigateToLeftScreen,
|
||||||
navigateToRightScreen = navigateToRightScreen,
|
navigateToRightScreen = navigateToRightScreen,
|
||||||
navigateToSettings = navigateToSettings,
|
navigateToSettings = navigateToSettings,
|
||||||
navigateToTools = navigateToTools,
|
navigateToMenu = navigateToMenu,
|
||||||
swapMeasurements = viewModel::swapUnits,
|
swapMeasurements = viewModel::swapUnits,
|
||||||
processInput = viewModel::processInput,
|
processInput = viewModel::processInput,
|
||||||
deleteDigit = viewModel::deleteDigit,
|
deleteDigit = viewModel::deleteDigit,
|
||||||
@ -84,7 +75,7 @@ private fun ConverterScreen(
|
|||||||
navigateToLeftScreen: (String) -> Unit,
|
navigateToLeftScreen: (String) -> Unit,
|
||||||
navigateToRightScreen: (unitFrom: String, unitTo: String, input: String) -> Unit,
|
navigateToRightScreen: (unitFrom: String, unitTo: String, input: String) -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
navigateToSettings: () -> Unit,
|
||||||
navigateToTools: () -> Unit,
|
navigateToMenu: () -> Unit,
|
||||||
swapMeasurements: () -> Unit,
|
swapMeasurements: () -> Unit,
|
||||||
processInput: (String) -> Unit,
|
processInput: (String) -> Unit,
|
||||||
deleteDigit: () -> Unit,
|
deleteDigit: () -> Unit,
|
||||||
@ -95,27 +86,7 @@ private fun ConverterScreen(
|
|||||||
|
|
||||||
UnittoScreenWithTopBar(
|
UnittoScreenWithTopBar(
|
||||||
title = { AnimatedTopBarText(launched) },
|
title = { AnimatedTopBarText(launched) },
|
||||||
navigationIcon = {
|
navigationIcon = { MenuButton { navigateToMenu() } },
|
||||||
BadgedBox(
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
.clickable(
|
|
||||||
onClick = navigateToTools,
|
|
||||||
interactionSource = remember { MutableInteractionSource() },
|
|
||||||
indication = rememberRipple(false),
|
|
||||||
role = Role.Button
|
|
||||||
),
|
|
||||||
badge = {
|
|
||||||
Badge { Text("1") }
|
|
||||||
},
|
|
||||||
content = {
|
|
||||||
Icon(
|
|
||||||
Icons.Outlined.Science,
|
|
||||||
contentDescription = stringResource(R.string.tools_screen)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(onClick = navigateToSettings) {
|
IconButton(onClick = navigateToSettings) {
|
||||||
Icon(
|
Icon(
|
||||||
@ -180,7 +151,7 @@ private fun PreviewConverterScreen() {
|
|||||||
navigateToLeftScreen = {},
|
navigateToLeftScreen = {},
|
||||||
navigateToRightScreen = {_, _, _ -> },
|
navigateToRightScreen = {_, _, _ -> },
|
||||||
navigateToSettings = {},
|
navigateToSettings = {},
|
||||||
navigateToTools = {},
|
navigateToMenu = {},
|
||||||
swapMeasurements = {},
|
swapMeasurements = {},
|
||||||
processInput = {},
|
processInput = {},
|
||||||
deleteDigit = {},
|
deleteDigit = {},
|
||||||
|
@ -34,7 +34,6 @@ import com.sadellie.unitto.data.model.AbstractUnit
|
|||||||
* @property unitTo Unit on the right.
|
* @property unitTo Unit on the right.
|
||||||
* @property mode
|
* @property mode
|
||||||
* @property formatTime If true will format output when converting time.
|
* @property formatTime If true will format output when converting time.
|
||||||
* @property showTools If true will show tools button in TopBar.
|
|
||||||
* @property allowVibration When true will vibrate on button clicks.
|
* @property allowVibration When true will vibrate on button clicks.
|
||||||
*/
|
*/
|
||||||
data class ConverterUIState(
|
data class ConverterUIState(
|
||||||
@ -47,7 +46,6 @@ data class ConverterUIState(
|
|||||||
val unitTo: AbstractUnit? = null,
|
val unitTo: AbstractUnit? = null,
|
||||||
val mode: ConverterMode = ConverterMode.DEFAULT,
|
val mode: ConverterMode = ConverterMode.DEFAULT,
|
||||||
val formatTime: Boolean = true,
|
val formatTime: Boolean = true,
|
||||||
val showTools: Boolean = false,
|
|
||||||
val allowVibration: Boolean = false
|
val allowVibration: Boolean = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ import com.sadellie.unitto.data.units.MyUnitIDS
|
|||||||
import com.sadellie.unitto.data.units.combine
|
import com.sadellie.unitto.data.units.combine
|
||||||
import com.sadellie.unitto.data.units.remote.CurrencyApi
|
import com.sadellie.unitto.data.units.remote.CurrencyApi
|
||||||
import com.sadellie.unitto.data.units.remote.CurrencyUnitResponse
|
import com.sadellie.unitto.data.units.remote.CurrencyUnitResponse
|
||||||
|
import com.sadellie.unitto.data.userprefs.UserPreferences
|
||||||
import com.sadellie.unitto.data.userprefs.UserPreferencesRepository
|
import com.sadellie.unitto.data.userprefs.UserPreferencesRepository
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -86,7 +87,7 @@ class ConverterViewModel @Inject constructor(
|
|||||||
private val _userPrefs = userPrefsRepository.userPreferencesFlow.stateIn(
|
private val _userPrefs = userPrefsRepository.userPreferencesFlow.stateIn(
|
||||||
viewModelScope,
|
viewModelScope,
|
||||||
SharingStarted.WhileSubscribed(5000),
|
SharingStarted.WhileSubscribed(5000),
|
||||||
com.sadellie.unitto.data.userprefs.UserPreferences()
|
UserPreferences()
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,7 +160,6 @@ class ConverterViewModel @Inject constructor(
|
|||||||
*/
|
*/
|
||||||
mode = if (_unitFrom.value is NumberBaseUnit) ConverterMode.BASE else ConverterMode.DEFAULT,
|
mode = if (_unitFrom.value is NumberBaseUnit) ConverterMode.BASE else ConverterMode.DEFAULT,
|
||||||
formatTime = formatTime,
|
formatTime = formatTime,
|
||||||
showTools = prefs.enableToolsExperiment,
|
|
||||||
allowVibration = prefs.enableVibrations
|
allowVibration = prefs.enableVibrations
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,24 @@
|
|||||||
|
|
||||||
package com.sadellie.unitto.feature.converter.navigation
|
package com.sadellie.unitto.feature.converter.navigation
|
||||||
|
|
||||||
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
import androidx.navigation.NavOptions
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import com.sadellie.unitto.feature.converter.ConverterRoute
|
import com.sadellie.unitto.feature.converter.ConverterRoute
|
||||||
import com.sadellie.unitto.feature.converter.ConverterViewModel
|
import com.sadellie.unitto.feature.converter.ConverterViewModel
|
||||||
|
|
||||||
const val converterRoute = "converter_route"
|
const val converterRoute = "converter_route"
|
||||||
|
|
||||||
|
fun NavController.navigateToConverter(navOptions: NavOptions) {
|
||||||
|
navigate(converterRoute, navOptions)
|
||||||
|
}
|
||||||
|
|
||||||
fun NavGraphBuilder.converterScreen(
|
fun NavGraphBuilder.converterScreen(
|
||||||
navigateToLeftScreen: (String) -> Unit,
|
navigateToLeftScreen: (String) -> Unit,
|
||||||
navigateToRightScreen: (unitFrom: String, unitTo: String, input: String) -> Unit,
|
navigateToRightScreen: (unitFrom: String, unitTo: String, input: String) -> Unit,
|
||||||
navigateToSettings: () -> Unit,
|
navigateToSettings: () -> Unit,
|
||||||
navigateToTools: () -> Unit,
|
navigateToMenu: () -> Unit,
|
||||||
viewModel: ConverterViewModel
|
viewModel: ConverterViewModel
|
||||||
) {
|
) {
|
||||||
composable(converterRoute) {
|
composable(converterRoute) {
|
||||||
@ -38,7 +44,7 @@ fun NavGraphBuilder.converterScreen(
|
|||||||
navigateToLeftScreen = navigateToLeftScreen,
|
navigateToLeftScreen = navigateToLeftScreen,
|
||||||
navigateToRightScreen = navigateToRightScreen,
|
navigateToRightScreen = navigateToRightScreen,
|
||||||
navigateToSettings = navigateToSettings,
|
navigateToSettings = navigateToSettings,
|
||||||
navigateToTools = navigateToTools
|
navigateToMenu = navigateToMenu
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,12 @@ import com.sadellie.unitto.feature.epoch.component.TopPart
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun EpochRoute(
|
internal fun EpochRoute(
|
||||||
navigateUpAction: () -> Unit,
|
navigateToMenu: () -> Unit,
|
||||||
viewModel: EpochViewModel = hiltViewModel()
|
viewModel: EpochViewModel = hiltViewModel()
|
||||||
) {
|
) {
|
||||||
val uiState = viewModel.uiState.collectAsStateWithLifecycle()
|
val uiState = viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
EpochScreen(
|
EpochScreen(
|
||||||
navigateUpAction = navigateUpAction,
|
navigateToMenu = navigateToMenu,
|
||||||
uiState = uiState.value,
|
uiState = uiState.value,
|
||||||
addSymbol = viewModel::addSymbol,
|
addSymbol = viewModel::addSymbol,
|
||||||
deleteSymbol = viewModel::deleteSymbol,
|
deleteSymbol = viewModel::deleteSymbol,
|
||||||
@ -52,7 +52,7 @@ internal fun EpochRoute(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun EpochScreen(
|
private fun EpochScreen(
|
||||||
navigateUpAction: () -> Unit,
|
navigateToMenu: () -> Unit,
|
||||||
uiState: EpochUIState,
|
uiState: EpochUIState,
|
||||||
addSymbol: (String) -> Unit,
|
addSymbol: (String) -> Unit,
|
||||||
deleteSymbol: () -> Unit,
|
deleteSymbol: () -> Unit,
|
||||||
@ -62,7 +62,7 @@ private fun EpochScreen(
|
|||||||
) {
|
) {
|
||||||
UnittoScreenWithTopBar(
|
UnittoScreenWithTopBar(
|
||||||
title = { Text(stringResource(R.string.epoch_converter)) },
|
title = { Text(stringResource(R.string.epoch_converter)) },
|
||||||
navigationIcon = { MenuButton { navigateUpAction() } }
|
navigationIcon = { MenuButton { navigateToMenu() } }
|
||||||
) { padding ->
|
) { padding ->
|
||||||
PortraitLandscape(
|
PortraitLandscape(
|
||||||
modifier = Modifier.padding(padding),
|
modifier = Modifier.padding(padding),
|
||||||
|
@ -18,42 +18,21 @@
|
|||||||
|
|
||||||
package com.sadellie.unitto.feature.epoch.navigation
|
package com.sadellie.unitto.feature.epoch.navigation
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.net.Uri
|
|
||||||
import androidx.core.content.pm.ShortcutInfoCompat
|
|
||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
|
||||||
import androidx.core.graphics.drawable.IconCompat
|
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
import androidx.navigation.NavOptions
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.navDeepLink
|
import androidx.navigation.navDeepLink
|
||||||
import com.sadellie.unitto.feature.epoch.EpochRoute
|
import com.sadellie.unitto.feature.epoch.EpochRoute
|
||||||
import com.sadellie.unitto.feature.epoch.R
|
|
||||||
|
|
||||||
private const val epochRoute = "epoch_route"
|
private const val epochRoute = "epoch_route"
|
||||||
|
|
||||||
fun NavController.navigateToEpoch() {
|
fun NavController.navigateToEpoch(navOptions: NavOptions) {
|
||||||
val shortcut = ShortcutInfoCompat
|
navigate(epochRoute, navOptions)
|
||||||
.Builder(context, epochRoute)
|
|
||||||
.setShortLabel(context.getString(R.string.epoch_converter))
|
|
||||||
.setLongLabel(context.getString(R.string.epoch_converter))
|
|
||||||
.setIcon(IconCompat.createWithResource(context, R.drawable.ic_shortcut_epoch))
|
|
||||||
.setIntent(
|
|
||||||
Intent(
|
|
||||||
Intent.ACTION_VIEW,
|
|
||||||
Uri.parse("app://com.sadellie.unitto/$epochRoute"),
|
|
||||||
context,
|
|
||||||
context.javaClass
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
|
|
||||||
|
|
||||||
navigate(epochRoute)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NavGraphBuilder.epochScreen(
|
fun NavGraphBuilder.epochScreen(
|
||||||
navigateUpAction: () -> Unit
|
navigateToMenu: () -> Unit
|
||||||
) {
|
) {
|
||||||
composable(
|
composable(
|
||||||
route = epochRoute,
|
route = epochRoute,
|
||||||
@ -61,8 +40,6 @@ fun NavGraphBuilder.epochScreen(
|
|||||||
navDeepLink { uriPattern = "app://com.sadellie.unitto/$epochRoute" }
|
navDeepLink { uriPattern = "app://com.sadellie.unitto/$epochRoute" }
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
EpochRoute(
|
EpochRoute(navigateToMenu = navigateToMenu)
|
||||||
navigateUpAction = navigateUpAction
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="48dp"
|
|
||||||
android:height="48dp"
|
|
||||||
android:viewportWidth="48"
|
|
||||||
android:viewportHeight="48">
|
|
||||||
<path
|
|
||||||
android:fillColor="#186C31"
|
|
||||||
android:pathData="m31.35,33.65 l2.25,-2.25 -7.95,-8L25.65,13.35h-3L22.65,24.6ZM24,44q-4.1,0 -7.75,-1.575 -3.65,-1.575 -6.375,-4.3 -2.725,-2.725 -4.3,-6.375Q4,28.1 4,24t1.575,-7.75q1.575,-3.65 4.3,-6.375 2.725,-2.725 6.375,-4.3Q19.9,4 24,4t7.75,1.575q3.65,1.575 6.375,4.3 2.725,2.725 4.3,6.375Q44,19.9 44,24t-1.575,7.75q-1.575,3.65 -4.3,6.375 -2.725,2.725 -6.375,4.3Q28.1,44 24,44ZM24,24ZM24,41q7,0 12,-5t5,-12q0,-7 -5,-12T24,7q-7,0 -12,5T7,24q0,7 5,12t12,5Z"/>
|
|
||||||
</vector>
|
|
@ -1,13 +1,17 @@
|
|||||||
package com.sadellie.unitto.feature.tools
|
package com.sadellie.unitto.feature.tools
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Calculate
|
import androidx.compose.material.icons.filled.Calculate
|
||||||
import androidx.compose.material.icons.filled.Schedule
|
import androidx.compose.material.icons.filled.Schedule
|
||||||
|
import androidx.compose.material.icons.filled.SwapHoriz
|
||||||
|
import androidx.compose.material3.Badge
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.ListItem
|
import androidx.compose.material3.ListItem
|
||||||
@ -16,14 +20,17 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.alpha
|
||||||
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 androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.sadellie.unitto.core.ui.common.UnittoLargeTopAppBar
|
import com.sadellie.unitto.core.ui.common.UnittoLargeTopAppBar
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@Suppress("UNUSED_PARAMETER")
|
||||||
internal fun ToolsScreen(
|
internal fun ToolsScreen(
|
||||||
navigateUpAction: () -> Unit,
|
navigateUpAction: () -> Unit,
|
||||||
|
navigateToConverter: () -> Unit,
|
||||||
navigateToCalculator: () -> Unit,
|
navigateToCalculator: () -> Unit,
|
||||||
navigateToEpoch: () -> Unit
|
navigateToEpoch: () -> Unit
|
||||||
) {
|
) {
|
||||||
@ -59,6 +66,19 @@ internal fun ToolsScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
item {
|
||||||
|
ListItem(
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.SwapHoriz,
|
||||||
|
stringResource(R.string.unit_converter)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
headlineText = { Text(stringResource(R.string.unit_converter)) },
|
||||||
|
supportingText = { Text(stringResource(R.string.unit_converter_support)) },
|
||||||
|
modifier = Modifier.clickable { navigateToConverter() }
|
||||||
|
)
|
||||||
|
}
|
||||||
item {
|
item {
|
||||||
ListItem(
|
ListItem(
|
||||||
leadingContent = {
|
leadingContent = {
|
||||||
@ -80,9 +100,14 @@ internal fun ToolsScreen(
|
|||||||
stringResource(R.string.epoch_converter)
|
stringResource(R.string.epoch_converter)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
headlineText = { Text(stringResource(R.string.epoch_converter)) },
|
headlineText = {
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||||
|
Text(stringResource(R.string.epoch_converter))
|
||||||
|
Badge { Text(stringResource(R.string.soon_label)) }
|
||||||
|
}
|
||||||
|
},
|
||||||
supportingText = { Text(stringResource(R.string.epoch_converter_support)) },
|
supportingText = { Text(stringResource(R.string.epoch_converter_support)) },
|
||||||
modifier = Modifier.clickable { navigateToEpoch() }
|
modifier = Modifier.alpha(0.5f)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,6 +119,7 @@ internal fun ToolsScreen(
|
|||||||
internal fun PreviewToolsScreen() {
|
internal fun PreviewToolsScreen() {
|
||||||
ToolsScreen(
|
ToolsScreen(
|
||||||
navigateUpAction = {},
|
navigateUpAction = {},
|
||||||
|
navigateToConverter = {},
|
||||||
navigateToEpoch = {},
|
navigateToEpoch = {},
|
||||||
navigateToCalculator = {}
|
navigateToCalculator = {}
|
||||||
)
|
)
|
||||||
|
@ -31,12 +31,14 @@ fun NavController.navigateToTools() {
|
|||||||
|
|
||||||
fun NavGraphBuilder.toolsScreen(
|
fun NavGraphBuilder.toolsScreen(
|
||||||
navigateUpAction: () -> Unit,
|
navigateUpAction: () -> Unit,
|
||||||
|
navigateToConverter: () -> Unit,
|
||||||
navigateToCalculator: () -> Unit,
|
navigateToCalculator: () -> Unit,
|
||||||
navigateToEpoch: () -> Unit
|
navigateToEpoch: () -> Unit
|
||||||
) {
|
) {
|
||||||
composable(toolsRoute) {
|
composable(toolsRoute) {
|
||||||
ToolsScreen(
|
ToolsScreen(
|
||||||
navigateUpAction = navigateUpAction,
|
navigateUpAction = navigateUpAction,
|
||||||
|
navigateToConverter = navigateToConverter,
|
||||||
navigateToCalculator = navigateToCalculator,
|
navigateToCalculator = navigateToCalculator,
|
||||||
navigateToEpoch = navigateToEpoch
|
navigateToEpoch = navigateToEpoch
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user