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

Clearing the old state of date and date-time ViewHolders #1581

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -55,6 +55,7 @@ internal object QuestionnaireItemDatePickerViewHolderFactory :
private lateinit var textInputLayout: TextInputLayout
private lateinit var textInputEditText: TextInputEditText
override lateinit var questionnaireItemViewItem: QuestionnaireItemViewItem
private var previousQuestionnaireItemViewItem: QuestionnaireItemViewItem? = null
private var textWatcher: TextWatcher? = null
// Medium and long format styles use alphabetical month names which are difficult for the user
// to input. Use short format style which is always numerical.
Expand Down Expand Up @@ -102,6 +103,13 @@ internal object QuestionnaireItemDatePickerViewHolderFactory :
header.bind(questionnaireItemViewItem.questionnaireItem)
textInputLayout.hint = localePattern
textInputEditText.removeTextChangedListener(textWatcher)
// Cleanup old state when the ViewHolder is now being used for a different questionnaireItem
if (previousQuestionnaireItemViewItem?.questionnaireItem !=
questionnaireItemViewItem.questionnaireItem
) {
textInputEditText.text = null
}
previousQuestionnaireItemViewItem = questionnaireItemViewItem

if (textInputEditText.text.isNullOrEmpty()) {
textInputEditText.setText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ internal object QuestionnaireItemDateTimePickerViewHolderFactory :
private lateinit var timeInputLayout: TextInputLayout
private lateinit var timeInputEditText: TextInputEditText
override lateinit var questionnaireItemViewItem: QuestionnaireItemViewItem
private var previousQuestionnaireItemViewItem: QuestionnaireItemViewItem? = null
private var localDate: LocalDate? = null
private var localTime: LocalTime? = null
private var textWatcher: TextWatcher? = null
Expand Down Expand Up @@ -142,7 +143,6 @@ internal object QuestionnaireItemDateTimePickerViewHolderFactory :
clearPreviousState()
header.bind(questionnaireItemViewItem.questionnaireItem)
dateInputLayout.hint = localeDatePattern
dateInputEditText.removeTextChangedListener(textWatcher)
val dateTime = questionnaireItemViewItem.answers.singleOrNull()?.valueDateTimeType
updateDateTimeInput(
dateTime?.let {
Expand Down Expand Up @@ -272,9 +272,18 @@ internal object QuestionnaireItemDateTimePickerViewHolderFactory :
}

private fun clearPreviousState() {
localDate = null
localTime = null
setReadOnlyInternal(isReadOnly = false)
dateInputEditText.removeTextChangedListener(textWatcher)
// Cleanup old state when the ViewHolder is now being used for a different questionnaireItem
if (previousQuestionnaireItemViewItem?.questionnaireItem !=
questionnaireItemViewItem.questionnaireItem
) {
dateInputEditText.text = null
timeInputEditText.text = null
localDate = null
localTime = null
}
previousQuestionnaireItemViewItem = questionnaireItemViewItem
}

private fun enableOrDisableTimePicker(enableIt: Boolean) {
Expand Down