mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
Adaptive time selector.
Date selector will be fixed by Google (hopefully). Users can switch to text input for convenience. closes #64
This commit is contained in:
parent
cce8799ce5
commit
ac4c6665fa
@ -36,6 +36,7 @@ import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TimePicker
|
||||
import androidx.compose.material3.TimePickerLayoutType
|
||||
import androidx.compose.material3.rememberDatePickerState
|
||||
import androidx.compose.material3.rememberTimePickerState
|
||||
import androidx.compose.runtime.Composable
|
||||
@ -63,6 +64,7 @@ fun TimePickerDialog(
|
||||
dismissLabel: String = stringResource(R.string.cancel_label),
|
||||
onDismiss: () -> Unit = {},
|
||||
onConfirm: (LocalDateTime) -> Unit,
|
||||
vertical: Boolean
|
||||
) {
|
||||
val pickerState = rememberTimePickerState(
|
||||
localDateTime.hour,
|
||||
@ -73,7 +75,7 @@ fun TimePickerDialog(
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
modifier = modifier.wrapContentHeight(),
|
||||
properties = DialogProperties()
|
||||
properties = DialogProperties(usePlatformDefaultWidth = vertical)
|
||||
) {
|
||||
Surface(
|
||||
modifier = modifier,
|
||||
@ -94,7 +96,8 @@ fun TimePickerDialog(
|
||||
|
||||
TimePicker(
|
||||
state = pickerState,
|
||||
modifier = Modifier.padding(top = 20.dp)
|
||||
modifier = Modifier.padding(top = 20.dp),
|
||||
layoutType = if (vertical) TimePickerLayoutType.Vertical else TimePickerLayoutType.Horizontal
|
||||
)
|
||||
|
||||
Row(
|
||||
@ -153,6 +156,7 @@ fun DatePickerDialog(
|
||||
Box(modifier = Modifier
|
||||
.align(Alignment.End)
|
||||
.padding(DialogButtonsPadding)) {
|
||||
|
||||
AlertDialogFlowRow(
|
||||
mainAxisSpacing = DialogButtonsMainAxisSpacing,
|
||||
crossAxisSpacing = DialogButtonsCrossAxisSpacing
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.sadellie.unitto.feature.datedifference
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
@ -33,6 +34,7 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
@ -72,9 +74,10 @@ internal fun DateDifferenceScreen(
|
||||
navigateToSettings: () -> Unit,
|
||||
updateStart: (LocalDateTime) -> Unit,
|
||||
updateEnd: (LocalDateTime) -> Unit,
|
||||
uiState: UIState
|
||||
uiState: UIState,
|
||||
) {
|
||||
var dialogState by remember { mutableStateOf(DialogState.NONE) }
|
||||
val isVertical = LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
|
||||
UnittoScreenWithTopBar(
|
||||
title = { Text(stringResource(R.string.date_difference)) },
|
||||
@ -141,7 +144,8 @@ internal fun DateDifferenceScreen(
|
||||
updateStart(it)
|
||||
dialogState = DialogState.FROM_DATE
|
||||
},
|
||||
confirmLabel = stringResource(R.string.next_label)
|
||||
confirmLabel = stringResource(R.string.next_label),
|
||||
vertical = isVertical,
|
||||
)
|
||||
}
|
||||
|
||||
@ -152,7 +156,8 @@ internal fun DateDifferenceScreen(
|
||||
onConfirm = {
|
||||
updateStart(it)
|
||||
resetDialog()
|
||||
}
|
||||
},
|
||||
vertical = isVertical,
|
||||
)
|
||||
}
|
||||
|
||||
@ -175,7 +180,8 @@ internal fun DateDifferenceScreen(
|
||||
updateEnd(it)
|
||||
dialogState = DialogState.TO_DATE
|
||||
},
|
||||
confirmLabel = stringResource(R.string.next_label)
|
||||
confirmLabel = stringResource(R.string.next_label),
|
||||
vertical = isVertical,
|
||||
)
|
||||
}
|
||||
|
||||
@ -186,7 +192,8 @@ internal fun DateDifferenceScreen(
|
||||
onConfirm = {
|
||||
updateEnd(it)
|
||||
resetDialog()
|
||||
}
|
||||
},
|
||||
vertical = isVertical,
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user