mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
feat: Add information for value of 1 for conversions
Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
parent
305744f9d5
commit
855f620548
@ -106,6 +106,7 @@ import app.myzel394.numberhub.feature.converter.components.BaseCalculationSummar
|
||||
import app.myzel394.numberhub.feature.converter.components.DefaultKeyboard
|
||||
import app.myzel394.numberhub.feature.converter.components.NumberBaseKeyboard
|
||||
import app.myzel394.numberhub.feature.converter.components.UnitSelectionButton
|
||||
import app.myzel394.numberhub.feature.converter.components.ValueOneSummary
|
||||
import java.math.BigDecimal
|
||||
import java.util.Locale
|
||||
import kotlin.math.absoluteValue
|
||||
@ -331,6 +332,20 @@ private fun Default(
|
||||
}
|
||||
var focusedOnInput1 by rememberSaveable { mutableStateOf(true) }
|
||||
|
||||
val density = LocalDensity.current
|
||||
val dragState = remember {
|
||||
AnchoredDraggableState(
|
||||
initialValue = DragState.CLOSED,
|
||||
anchors = DraggableAnchors {
|
||||
DragState.CLOSED at 0f
|
||||
DragState.OPEN at with(density) { -60.dp.toPx() }
|
||||
},
|
||||
positionalThreshold = { 0f },
|
||||
velocityThreshold = { 0f },
|
||||
animationSpec = tween(easing = LinearEasing, durationMillis = 50),
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(connection) {
|
||||
if ((connection == ConnectionState.Available) and (uiState.result is ConverterResult.Error)) {
|
||||
val unitFrom = uiState.unitFrom
|
||||
@ -351,7 +366,13 @@ private fun Default(
|
||||
PortraitLandscape(
|
||||
modifier = modifier.fillMaxSize(),
|
||||
content1 = { contentModifier ->
|
||||
ColumnWithConstraints(modifier = contentModifier) { boxWithConstraintsScope ->
|
||||
ColumnWithConstraints(
|
||||
modifier = contentModifier
|
||||
.anchoredDraggable(
|
||||
state = dragState,
|
||||
orientation = Orientation.Vertical,
|
||||
),
|
||||
) { boxWithConstraintsScope ->
|
||||
val textFieldModifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(2f)
|
||||
@ -472,6 +493,16 @@ private fun Default(
|
||||
),
|
||||
)
|
||||
|
||||
ValueOneSummary(
|
||||
modifier = with(density) {
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.height(dragState.offset.absoluteValue.toDp())
|
||||
.horizontalScroll(rememberScrollState())
|
||||
},
|
||||
uiState = uiState,
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(boxWithConstraintsScope.maxHeight * 0.03f))
|
||||
|
||||
UnitSelectionButtons(
|
||||
|
@ -0,0 +1,74 @@
|
||||
package app.myzel394.numberhub.feature.converter.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import app.myzel394.numberhub.data.common.format
|
||||
import app.myzel394.numberhub.feature.converter.UnitConverterUIState
|
||||
import java.math.BigDecimal
|
||||
|
||||
@Composable
|
||||
internal fun ValueOneSummary(
|
||||
modifier: Modifier = Modifier,
|
||||
uiState: UnitConverterUIState.Default,
|
||||
) {
|
||||
val unitFromLabel = LocalContext.current.getString(uiState.unitFrom.displayName)
|
||||
val unitToLabel = LocalContext.current.getString(uiState.unitTo.displayName)
|
||||
val value = uiState.unitFrom.convert(uiState.unitTo, BigDecimal(1))
|
||||
.format(uiState.scale, uiState.outputFormat)
|
||||
|
||||
val fontStyle = MaterialTheme.typography.headlineSmall
|
||||
|
||||
Row(
|
||||
modifier = modifier,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.End,
|
||||
) {
|
||||
Text(
|
||||
1.toString(),
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
|
||||
Text(
|
||||
" ",
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
|
||||
Text(
|
||||
unitFromLabel,
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
)
|
||||
|
||||
Text(
|
||||
" = ",
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
|
||||
Text(
|
||||
value,
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
|
||||
Text(
|
||||
" ",
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
|
||||
Text(
|
||||
unitToLabel,
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user