Skip to content

Commit

Permalink
Merge pull request #12 from commandiron/1.1.5-development
Browse files Browse the repository at this point in the history
1.1.5 development
  • Loading branch information
commandiron committed Nov 30, 2022
2 parents 8a54abb + 89d5375 commit b141492
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class MainActivity : ComponentActivity() {
2025, 10, 30, 5, 0
),
yearsRange = null,
size = DpSize(200.dp, 100.dp),
backwardsDisabled = true,
size = DpSize(200.dp, 100.dp),
textStyle = MaterialTheme.typography.titleSmall,
textColor = Color(0xFFffc300),
selectorProperties = WheelPickerDefaults.selectorProperties(
Expand Down
2 changes: 1 addition & 1 deletion wheel-picker-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ afterEvaluate {

groupId = 'com.git.luolix.topmandiron'
artifactId = 'wheel-picker-compose'
version = '1.1.4'
version = '1.1.5'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import com.commandiron.wheel_picker_compose.core.DefaultWheelDateTimePicker
import com.commandiron.wheel_picker_compose.core.SelectorProperties
import com.commandiron.wheel_picker_compose.core.TimeFormat
import com.commandiron.wheel_picker_compose.core.WheelPickerDefaults
import java.time.LocalDateTime

Expand All @@ -21,6 +22,7 @@ fun WheelDateTimePicker(
modifier: Modifier = Modifier,
startDateTime: LocalDateTime = LocalDateTime.now(),
yearsRange: IntRange? = IntRange(1922, 2122),
timeFormat: TimeFormat = TimeFormat.HOUR_24,
backwardsDisabled: Boolean = false,
size: DpSize = DpSize(256.dp, 128.dp),
textStyle: TextStyle = MaterialTheme.typography.titleMedium,
Expand All @@ -32,6 +34,7 @@ fun WheelDateTimePicker(
modifier,
startDateTime,
yearsRange,
timeFormat,
backwardsDisabled,
size,
textStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun WheelTimePicker(
textStyle,
textColor,
selectorProperties,
onSnappedTime = { snappedTime ->
onSnappedTime = { snappedTime, _ ->
onSnappedTime(snappedTime.snappedLocalTime)
snappedTime.snappedIndex
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal fun DefaultWheelDateTimePicker(
modifier: Modifier = Modifier,
startDateTime: LocalDateTime = LocalDateTime.now(),
yearsRange: IntRange? = IntRange(1922, 2122),
timeFormat: TimeFormat = TimeFormat.HOUR_24,
backwardsDisabled: Boolean = false,
size: DpSize = DpSize(256.dp, 128.dp),
textStyle: TextStyle = MaterialTheme.typography.titleMedium,
Expand Down Expand Up @@ -105,6 +106,7 @@ internal fun DefaultWheelDateTimePicker(
//Time
DefaultWheelTimePicker(
startTime = startDateTime.toLocalTime(),
timeFormat = timeFormat,
backwardsDisabled = false,
size = DpSize(
width = if(yearsRange == null ) size.width * 3 / 6 else size.width * 2 / 5 ,
Expand All @@ -115,7 +117,7 @@ internal fun DefaultWheelDateTimePicker(
selectorProperties = WheelPickerDefaults.selectorProperties(
enabled = false
),
onSnappedTime = { snappedTime ->
onSnappedTime = { snappedTime, timeFormat ->

val newDateTime = when(snappedTime) {
is SnappedTime.Hour -> {
Expand All @@ -139,7 +141,7 @@ internal fun DefaultWheelDateTimePicker(
return@DefaultWheelTimePicker when(snappedTime) {
is SnappedTime.Hour -> {
onSnappedDateTime(SnappedDateTime.Hour(snappedDateTime, snappedDateTime.hour))
snappedDateTime.hour
if(timeFormat == TimeFormat.HOUR_24) snappedDateTime.hour else snappedDateTime.hour - 1
}
is SnappedTime.Minute -> {
onSnappedDateTime(SnappedDateTime.Minute(snappedDateTime, snappedDateTime.minute))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal fun DefaultWheelTimePicker(
textStyle: TextStyle = MaterialTheme.typography.titleMedium,
textColor: Color = LocalContentColor.current,
selectorProperties: SelectorProperties = WheelPickerDefaults.selectorProperties(),
onSnappedTime : (snappedTime: SnappedTime) -> Int? = { _ -> null },
onSnappedTime : (snappedTime: SnappedTime, timeFormat: TimeFormat) -> Int? = { _,_ -> null },
) {

var snappedTime by remember { mutableStateOf(startTime.truncatedTo(ChronoUnit.MINUTES)) }
Expand Down Expand Up @@ -138,7 +138,8 @@ internal fun DefaultWheelTimePicker(
SnappedTime.Hour(
localTime = snappedTime,
index = newIndex
)
),
timeFormat
)?.let { return@WheelTextPicker it }
}
}
Expand Down Expand Up @@ -197,7 +198,8 @@ internal fun DefaultWheelTimePicker(
SnappedTime.Minute(
localTime = snappedTime,
index = newIndex
)
),
timeFormat
)?.let { return@WheelTextPicker it }
}
}
Expand All @@ -222,7 +224,13 @@ internal fun DefaultWheelTimePicker(
),
onScrollFinished = { snappedIndex ->

val newAmPm = amPms.find { it.index == snappedIndex }
val newAmPm = amPms.find {
if(snappedIndex == 2) {
it.index == 1
} else {
it.index == snappedIndex
}
}

newAmPm?.let {
snappedAmPm = newAmPm
Expand Down Expand Up @@ -255,7 +263,8 @@ internal fun DefaultWheelTimePicker(
SnappedTime.Hour(
localTime = snappedTime,
index = newIndex
)
),
timeFormat
)
}
}
Expand Down Expand Up @@ -310,6 +319,7 @@ private data class AmPmHour(
)

private fun hourToAmPmHour(hour: Int): Int {

if(hour == 0) {
return 12
}
Expand All @@ -320,6 +330,7 @@ private fun hourToAmPmHour(hour: Int): Int {
}

private fun amPmHourToHour(amPmHour: Int, amPmValue: AmPmValue): Int {

return when(amPmValue) {
AmPmValue.AM -> {
amPmHour
Expand Down

0 comments on commit b141492

Please sign in to comment.