Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
fix: Correct time picker display and mode switching (#3403)
Browse files Browse the repository at this point in the history
  • Loading branch information
akashs056 authored Aug 7, 2024
1 parent 51d66c7 commit d9ffffd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
10 changes: 7 additions & 3 deletions app/src/main/java/com/ivy/wallet/RootActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,15 @@ class RootActivity : AppCompatActivity(), RootScreen {
}

private fun setupTimePicker() {
ivyContext.onShowTimePicker = { onTimePicked ->
val nowLocal = timeNowLocal()
ivyContext.onShowTimePicker = { initialTime,
onTimePicked ->
val nowLocal = initialTime ?: timeNowLocal().toLocalTime()
val is24Hour = android.text.format.DateFormat.is24HourFormat(this)
val timeFormat = if (is24Hour) TimeFormat.CLOCK_24H else TimeFormat.CLOCK_12H

val picker =
MaterialTimePicker.Builder()
.setTimeFormat(TimeFormat.CLOCK_12H)
.setTimeFormat(timeFormat)
.setHour(nowLocal.hour)
.setMinute(nowLocal.minute)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ private fun BoxWithConstraintsScope.UI(
}
},
onEditTime = {
ivyContext.timePicker { time ->
ivyContext.timePicker(
initialTime = dateTime?.toLocalTime()
) { time ->
onSetTime(time)
}
}
Expand Down
12 changes: 9 additions & 3 deletions temp/legacy-code/src/main/java/com/ivy/legacy/IvyWalletCtx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ class IvyWalletCtx @Inject constructor() : IvyContext() {
initialDate: LocalDate?,
onDatePicked: (LocalDate) -> Unit
) -> Unit
lateinit var onShowTimePicker: (onDatePicked: (LocalTime) -> Unit) -> Unit
lateinit var onShowTimePicker: (
initialTime: LocalTime?,
onDatePicked: (LocalTime) -> Unit
) -> Unit

@Deprecated("Legacy code. Don't use it, please.")
fun datePicker(
Expand All @@ -127,8 +130,11 @@ class IvyWalletCtx @Inject constructor() : IvyContext() {
}

@Deprecated("Legacy code. Don't use it, please.")
fun timePicker(onTimePicked: (LocalTime) -> Unit) {
onShowTimePicker(onTimePicked)
fun timePicker(
initialTime: LocalTime?,
onTimePicked: (LocalTime) -> Unit
) {
onShowTimePicker(initialTime, onTimePicked)
}
// Activity help -------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ fun DateTimeRow(
text = dateTime.formatLocalTime(),
iconStart = R.drawable.ic_date
) {
ivyContext.timePicker {
ivyContext.timePicker(
initialTime = dateTime.convertUTCtoLocal().toLocalTime()
) {
onSetDateTime(getTrueDate(dateTime.convertUTCtoLocal().toLocalDate(), it))
}
}
Expand Down

0 comments on commit d9ffffd

Please sign in to comment.