Skip to content

Added configurable time range #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.ui.unit.dp
import com.commandiron.wheel_picker_compose.core.DefaultWheelTimePicker
import com.commandiron.wheel_picker_compose.core.SelectorProperties
import com.commandiron.wheel_picker_compose.core.TimeFormat
import com.commandiron.wheel_picker_compose.core.TimeRangeConfig
import com.commandiron.wheel_picker_compose.core.WheelPickerDefaults
import java.time.LocalTime

Expand All @@ -26,6 +27,7 @@ fun WheelTimePicker(
textStyle: TextStyle = MaterialTheme.typography.titleMedium,
textColor: Color = LocalContentColor.current,
selectorProperties: SelectorProperties = WheelPickerDefaults.selectorProperties(),
timeRangeConfig: TimeRangeConfig = TimeRangeConfig(),
onSnappedTime : (snappedTime: LocalTime) -> Unit = {},
) {
DefaultWheelTimePicker(
Expand All @@ -39,6 +41,7 @@ fun WheelTimePicker(
textStyle,
textColor,
selectorProperties,
timeRangeConfig,
onSnappedTime = { snappedTime, _ ->
onSnappedTime(snappedTime.snappedLocalTime)
snappedTime.snappedIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal fun DefaultWheelDateTimePicker(
textStyle: TextStyle = MaterialTheme.typography.titleMedium,
textColor: Color = LocalContentColor.current,
selectorProperties: SelectorProperties = WheelPickerDefaults.selectorProperties(),
timeRangeConfig: TimeRangeConfig = TimeRangeConfig(),
onSnappedDateTime : (snappedDateTime: SnappedDateTime) -> Int? = { _ -> null }
) {

Expand Down Expand Up @@ -109,6 +110,7 @@ internal fun DefaultWheelDateTimePicker(
selectorProperties = WheelPickerDefaults.selectorProperties(
enabled = false
),
timeRangeConfig = timeRangeConfig,
onSnappedTime = { snappedTime, timeFormat ->

val newDateTime = when(snappedTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,32 @@ internal fun DefaultWheelTimePicker(
textStyle: TextStyle = MaterialTheme.typography.titleMedium,
textColor: Color = LocalContentColor.current,
selectorProperties: SelectorProperties = WheelPickerDefaults.selectorProperties(),
timeRangeConfig: TimeRangeConfig = TimeRangeConfig(),
onSnappedTime : (snappedTime: SnappedTime, timeFormat: TimeFormat) -> Int? = { _,_ -> null },
) {

var snappedTime by remember { mutableStateOf(startTime.truncatedTo(ChronoUnit.MINUTES)) }

val hours = (0..23).map {
val hours = (timeRangeConfig.startHour..timeRangeConfig.endHour).mapIndexed { index, i ->
Hour(
text = it.toString().padStart(2, '0'),
value = it,
index = it
text = i.toString().padStart(2, '0'),
value = i,
index = index
)
}
val amPmHours = (1..12).map {
val amPmHours = (timeRangeConfig.startHourAmPm..timeRangeConfig.endHourAmPm).mapIndexed { index, i ->
AmPmHour(
text = it.toString(),
value = it,
index = it - 1
text = i.toString(),
value = i,
index = index
)
}

val minutes = (0..59).map {
val minutes = (timeRangeConfig.startMinute..timeRangeConfig.endMinute).mapIndexed { index, i ->
Minute(
text = it.toString().padStart(2, '0'),
value = it,
index = it
text = i.toString().padStart(2, '0'),
value = i,
index = index
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.commandiron.wheel_picker_compose.core

data class TimeRangeConfig(
val startHour: Int = 0,
val endHour: Int = 23,
val startHourAmPm: Int = 1,
val endHourAmPm: Int = 12,
val startMinute: Int = 0,
val endMinute: Int = 59,
)