| 32 | import java.util.Calendar |
| 33 | |
| 34 | @Keep |
| 35 | open class ValdiTimePicker(context: Context) : ViewGroup(context), ValdiTouchTarget { |
| 36 | |
| 37 | companion object { |
| 38 | private val hourOfDayProperty = InternedString.create("hourOfDay") |
| 39 | private val minuteOfHourProperty = InternedString.create("minuteOfHour") |
| 40 | |
| 41 | // Source of truth: STYLE_MAP in the date picker's TypeScript preferred-style definitions |
| 42 | private const val STYLE_SPINNER = 1 |
| 43 | private const val STYLE_OVERLAY = 2 |
| 44 | |
| 45 | fun timePickerAttributeSet(context: Context): AttributeSet? { |
| 46 | return attributeSetFromXml(context, com.snapchat.client.R.xml.valdi_time_picker) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | private var currentHour: Int = 0 |
| 51 | private var currentMinute: Int = 0 |
| 52 | |
| 53 | var hourOfDay: Int? |
| 54 | get() = currentHour |
| 55 | set(value) { |
| 56 | currentHour = value ?: 0 |
| 57 | safeUpdate { underlyingTimePickerHour = currentHour } |
| 58 | updateOverlayLabel() |
| 59 | } |
| 60 | |
| 61 | var minuteOfHour: Int? |
| 62 | get() = currentMinute |
| 63 | set(value) { |
| 64 | currentMinute = value ?: 0 |
| 65 | safeUpdate { underlyingTimePickerMinuteIndex = currentMinute / intervalMinutes } |
| 66 | updateOverlayLabel() |
| 67 | } |
| 68 | |
| 69 | var intervalMinutes: Int = 1 |
| 70 | set(value) { |
| 71 | safeUpdate { |
| 72 | setMinutesInterval(value) |
| 73 | field = value |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | private var underlyingTimePickerHour: Int |
| 78 | get() { |
| 79 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| 80 | return timePicker.getHour() |
| 81 | } else { |
| 82 | return timePicker.getCurrentHour() |
| 83 | } |
| 84 | } |
| 85 | set(value) { |
| 86 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| 87 | timePicker.setHour(value) |
| 88 | } else { |
| 89 | timePicker.setCurrentHour(value) |
| 90 | } |
| 91 | } |
no test coverage detected