Skip to content
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

Cleanup and moved Date and Time pickers to material #1312

Merged
merged 10 commits into from
Apr 29, 2022
Prev Previous commit
Next Next commit
Review comment changes
  • Loading branch information
aditya-07 committed Apr 21, 2022
commit 0fe4b1d638d5b984d6b7567ea953df05a496cb0e

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package com.google.android.fhir.datacapture.views

import android.annotation.SuppressLint
import android.content.Context
import android.text.InputType
import android.text.format.DateFormat
import android.view.View
import com.google.android.fhir.datacapture.R
import com.google.android.fhir.datacapture.entryFormat
Expand Down Expand Up @@ -64,10 +66,10 @@ internal object QuestionnaireItemDateTimePickerViewHolderFactory :
createMaterialDatePicker()
.apply {
addOnPositiveButtonClickListener { epochMilli ->
localDate = Instant.ofEpochMilli(epochMilli).atZone(ZONE_ID_UTC).toLocalDate()
localDate?.let {
dateInputEditText.setText(it.format(LOCAL_DATE_FORMATTER))
generateLocalDateTime(it, localTime)?.let {
with(Instant.ofEpochMilli(epochMilli).atZone(ZONE_ID_UTC).toLocalDate()) {
localDate = this
dateInputEditText.setText(this.format(LOCAL_DATE_FORMATTER))
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved
generateLocalDateTime(this, localTime)?.let {
updateDateTimeInput(it)
updateDateTimeAnswer(it)
}
Expand All @@ -88,21 +90,21 @@ internal object QuestionnaireItemDateTimePickerViewHolderFactory :
// necessary to access the base context twice to retrieve the application object
// from the view's context.
val context = itemView.context.tryUnwrapContext()!!
createMaterialTimePicker()
createMaterialTimePicker(context)
.apply {
addOnPositiveButtonClickListener {
localTime = LocalTime.of(this.hour, this.minute, 0)
localTime?.let {
timeInputEditText.setText(it.format(LOCAL_TIME_FORMATTER))
generateLocalDateTime(localDate, it)?.let {
with(LocalTime.of(this.hour, this.minute, 0)) {
localTime = this
timeInputEditText.setText(this.format(LOCAL_TIME_FORMATTER))
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved
generateLocalDateTime(localDate, this)?.let {
updateDateTimeInput(it)
updateDateTimeAnswer(it)
}
timeInputEditText.clearFocus()
}
timeInputEditText.clearFocus()
}
}
.show(context.supportFragmentManager, "time-picker")
.show(context.supportFragmentManager, TAG_TIME_PICKER)
}
}

Expand Down Expand Up @@ -212,16 +214,19 @@ internal object QuestionnaireItemDateTimePickerViewHolderFactory :
.build()
}

private fun createMaterialTimePicker(): MaterialTimePicker {
private fun createMaterialTimePicker(context: Context): MaterialTimePicker {
val selectedTime =
questionnaireItemViewItem.singleAnswerOrNull?.valueDateTimeType?.localTime
?: LocalTime.now()

return MaterialTimePicker.Builder()
.setTitleText(R.string.select_time)
.setTimeFormat(TimeFormat.CLOCK_12H)
.setHour(selectedTime.hour)
.setMinute(selectedTime.minute)
.apply {
setTitleText(R.string.select_time)
setHour(selectedTime.hour)
setMinute(selectedTime.minute)
if (DateFormat.is24HourFormat(context)) setTimeFormat(TimeFormat.CLOCK_24H)
else setTimeFormat(TimeFormat.CLOCK_12H)
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved
}
.build()
}
}
Expand All @@ -231,6 +236,8 @@ internal object QuestionnaireItemDateTimePickerViewHolderFactory :
val LOCAL_TIME_FORMATTER = DateTimeFormatter.ISO_LOCAL_TIME!!
}

private const val TAG_TIME_PICKER = "time-picker"

internal val DateTimeType.localDate
get() =
LocalDate.of(
Expand Down

This file was deleted.