Skip to content

Commit

Permalink
[refactor/#21] timepicker 0~59 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
imtaejugkim committed Jan 18, 2025
1 parent cf57b55 commit 36a53cf
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/src/main/java/org/memento/ui/MementoTimePicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -15,6 +16,7 @@ import androidx.compose.ui.unit.dp
import com.sd.lib.compose.wheel_picker.FVerticalWheelPicker
import com.sd.lib.compose.wheel_picker.FWheelPickerFocusVertical
import com.sd.lib.compose.wheel_picker.rememberFWheelPickerState
import kotlinx.coroutines.delay
import org.memento.ui.theme.MementoTheme
import org.memento.ui.theme.darkModeColors

Expand All @@ -27,28 +29,27 @@ fun MementoTimePicker(
val minuteState = rememberFWheelPickerState(initialIndex = 0)
val periodState = rememberFWheelPickerState(initialIndex = 0)

val minuteValues = listOf(0, 30)
val periods = listOf("AM", "PM")

fun getFormattedTime(): String {
val hour = hourState.currentIndex
val minuteIndex = minuteState.currentIndex.takeIf { it in minuteValues.indices } ?: 0
val minute = minuteState.currentIndex
val periodIndex = periodState.currentIndex.takeIf { it in periods.indices } ?: 0

val minute = minuteValues[minuteIndex]
val period = periods[periodIndex]

return "${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')} $period"
}

LaunchedEffect(hourState.currentIndex, minuteState.currentIndex, periodState.currentIndex) {
delay(100)
onTimeSelected(getFormattedTime())
}

Row(
modifier =
Modifier
.fillMaxWidth(),
.fillMaxWidth()
.padding(horizontal = 30.dp),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
Expand Down Expand Up @@ -76,7 +77,7 @@ fun MementoTimePicker(

FVerticalWheelPicker(
modifier = Modifier.weight(1f),
count = minuteValues.size,
count = 60,
state = minuteState,
focus = {
FWheelPickerFocusVertical(
Expand All @@ -86,7 +87,7 @@ fun MementoTimePicker(
},
) { index ->
Text(
text = minuteValues[index].toString().padStart(2, '0'),
text = index.toString().padStart(2, '0'),
style =
MementoTheme.typography.body_b_18.copy(
color = darkModeColors.white,
Expand Down

0 comments on commit 36a53cf

Please sign in to comment.