Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Fix exception when deselecting person (EXPOSUREAPP-6003) #2715

Merged
merged 8 commits into from
Mar 31, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import org.joda.time.Duration
import org.joda.time.LocalDate
import timber.log.Timber

class ContactDiaryLocationListViewModel @AssistedInject constructor(
val dispatcherProvider: DispatcherProvider,
Expand Down Expand Up @@ -112,6 +113,12 @@ class ContactDiaryLocationListViewModel @AssistedInject constructor(
circumstances: String
) {
val visit = item.visit ?: return

if (visit.circumstances.isNullOrBlank() && circumstances.isBlank()) {
Timber.d("onCircumstancesChanged but there is nothing to be updated")
return
}

val sanitized = circumstances.trim().trimToLength(250)
launchOnAppScope {
contactDiaryRepository.updateLocationVisit(visit.id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package de.rki.coronawarnapp.contactdiary.ui.day.tabs.location
import android.view.ViewGroup
import android.view.accessibility.AccessibilityEvent
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.contactdiary.util.hideKeyboard
import de.rki.coronawarnapp.contactdiary.util.setClickLabel
import de.rki.coronawarnapp.ui.durationpicker.toContactDiaryFormat
import de.rki.coronawarnapp.databinding.ContactDiaryLocationListItemBinding
Expand Down Expand Up @@ -56,6 +57,7 @@ class DiaryLocationViewHolder(
}

durationInput.setOnClickListener {
it.hideKeyboard()
circumstances.clearFocus()
item.onDurationDialog(item, durationInput.text.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ class ContactDiaryPersonListViewModel @AssistedInject constructor(
) {
Timber.d("onCircumstancesChanged(item=%s, circumstances=%s)", item, circumstances)
val encounter = item.personEncounter ?: return

if (encounter.circumstances.isNullOrBlank() && circumstances.isBlank()) {
Timber.d("onCircumstancesChanged but there is nothing to be updated")
return
}

launchOnAppScope {
val sanitized = circumstances.trim().trimToLength(250)
contactDiaryRepository.updatePersonEncounter(encounter.id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.accessibility.AccessibilityEvent
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.contactdiary.model.ContactDiaryPersonEncounter.DurationClassification
import de.rki.coronawarnapp.contactdiary.ui.day.tabs.common.setOnCheckedChangeListener
import de.rki.coronawarnapp.contactdiary.util.hideKeyboard
import de.rki.coronawarnapp.contactdiary.util.setClickLabel
import de.rki.coronawarnapp.databinding.ContactDiaryPersonListItemBinding
import de.rki.coronawarnapp.ui.lists.BaseAdapter
Expand All @@ -26,6 +27,7 @@ class DiaryPersonViewHolder(

mainBox.apply {
header.setOnClickListenerThrottled {
hideKeyboard()
it.contentDescription = item.onClickDescription.get(context)
it.sendAccessibilityEvent(AccessibilityEvent.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION)
item.onItemClick(item)
Expand All @@ -45,6 +47,7 @@ class DiaryPersonViewHolder(
null -> clearChecked()
}
setOnCheckedChangeListener { checkedId ->
hideKeyboard()
when (checkedId) {
R.id.duration_above_15 -> DurationClassification.MORE_THAN_15_MINUTES
R.id.duration_below_15 -> DurationClassification.LESS_THAN_15_MINUTES
Expand All @@ -61,6 +64,7 @@ class DiaryPersonViewHolder(
null -> clearChecked()
}
setOnCheckedChangeListener { checkedId ->
hideKeyboard()
when (checkedId) {
R.id.mask_with -> true
R.id.mask_without -> false
Expand All @@ -77,6 +81,7 @@ class DiaryPersonViewHolder(
null -> clearChecked()
}
setOnCheckedChangeListener { checkedId ->
hideKeyboard()
when (checkedId) {
R.id.environment_outside -> true
R.id.environment_inside -> false
Expand Down