From 50b24e3a4f77e3dd433acca413813c5b618a55f5 Mon Sep 17 00:00:00 2001 From: ralfgehrer Date: Tue, 30 Mar 2021 12:07:27 +0200 Subject: [PATCH 1/2] Fix NPE when not changing but deselecting person/location with focus on note field --- .../day/tabs/location/ContactDiaryLocationListViewModel.kt | 7 +++++++ .../ui/day/tabs/person/ContactDiaryPersonListViewModel.kt | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/location/ContactDiaryLocationListViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/location/ContactDiaryLocationListViewModel.kt index 874d073130c..33987d166b6 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/location/ContactDiaryLocationListViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/location/ContactDiaryLocationListViewModel.kt @@ -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, @@ -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) { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/person/ContactDiaryPersonListViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/person/ContactDiaryPersonListViewModel.kt index 1e60f3f3495..e2c86625dd5 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/person/ContactDiaryPersonListViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/person/ContactDiaryPersonListViewModel.kt @@ -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) { From 6a1313c1920c4a3080e6288f7d70845f2b9db8d5 Mon Sep 17 00:00:00 2001 From: ralfgehrer Date: Tue, 30 Mar 2021 12:12:35 +0200 Subject: [PATCH 2/2] hide keyboard when selecting other elements but notes --- .../ui/day/tabs/location/DiaryLocationViewHolder.kt | 2 ++ .../contactdiary/ui/day/tabs/person/DiaryPersonViewHolder.kt | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/location/DiaryLocationViewHolder.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/location/DiaryLocationViewHolder.kt index 20ebb65500b..f7998681bcf 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/location/DiaryLocationViewHolder.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/location/DiaryLocationViewHolder.kt @@ -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 @@ -56,6 +57,7 @@ class DiaryLocationViewHolder( } durationInput.setOnClickListener { + it.hideKeyboard() circumstances.clearFocus() item.onDurationDialog(item, durationInput.text.toString()) } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/person/DiaryPersonViewHolder.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/person/DiaryPersonViewHolder.kt index bae3f5575df..1e6fe5c83e7 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/person/DiaryPersonViewHolder.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/contactdiary/ui/day/tabs/person/DiaryPersonViewHolder.kt @@ -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 @@ -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) @@ -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 @@ -61,6 +64,7 @@ class DiaryPersonViewHolder( null -> clearChecked() } setOnCheckedChangeListener { checkedId -> + hideKeyboard() when (checkedId) { R.id.mask_with -> true R.id.mask_without -> false @@ -77,6 +81,7 @@ class DiaryPersonViewHolder( null -> clearChecked() } setOnCheckedChangeListener { checkedId -> + hideKeyboard() when (checkedId) { R.id.environment_outside -> true R.id.environment_inside -> false