diff --git a/datacapture/src/androidTest/java/com/google/android/fhir/datacapture/views/QuestionnaireItemGroupViewHolderFactoryInstrumentedTest.kt b/datacapture/src/androidTest/java/com/google/android/fhir/datacapture/views/QuestionnaireItemGroupViewHolderFactoryInstrumentedTest.kt index 17b56e8e74..7796252d4a 100644 --- a/datacapture/src/androidTest/java/com/google/android/fhir/datacapture/views/QuestionnaireItemGroupViewHolderFactoryInstrumentedTest.kt +++ b/datacapture/src/androidTest/java/com/google/android/fhir/datacapture/views/QuestionnaireItemGroupViewHolderFactoryInstrumentedTest.kt @@ -16,6 +16,7 @@ package com.google.android.fhir.datacapture.views +import android.view.View import android.widget.FrameLayout import android.widget.TextView import androidx.appcompat.view.ContextThemeWrapper @@ -99,4 +100,42 @@ class QuestionnaireItemGroupViewHolderFactoryInstrumentedTest { assertThat(viewHolder.itemView.findViewById(R.id.error).text).isEqualTo("") } + + @Test + fun hintText_nestedDisplayItem_shouldNotShowHintText() { + viewHolder.bind( + QuestionnaireItemViewItem( + Questionnaire.QuestionnaireItemComponent().apply { + type = Questionnaire.QuestionnaireItemType.GROUP + item = + listOf( + Questionnaire.QuestionnaireItemComponent().apply { + linkId = "nested-display-question" + text = "text" + type = Questionnaire.QuestionnaireItemType.DISPLAY + } + ) + }, + QuestionnaireResponse.QuestionnaireResponseItemComponent() + ) {} + ) + + assertThat( + viewHolder + .itemView + .findViewById(R.id.header) + .findViewById(R.id.hint) + .text + .isNullOrEmpty() + ) + .isTrue() + assertThat( + viewHolder + .itemView + .findViewById(R.id.header) + .findViewById(R.id.hint) + .visibility + ) + .isEqualTo(View.GONE) + } } diff --git a/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponents.kt b/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponents.kt index 08ab8e0846..02112f8559 100644 --- a/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponents.kt +++ b/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponents.kt @@ -142,13 +142,19 @@ internal val Questionnaire.QuestionnaireItemComponent.localizedPrefixSpanned: Sp * question. */ internal val Questionnaire.QuestionnaireItemComponent.localizedHintSpanned: Spanned? - get() = - item - .firstOrNull { questionnaireItem -> - questionnaireItem.type == Questionnaire.QuestionnaireItemType.DISPLAY && - questionnaireItem.displayItemControl == null + get() { + return when (type) { + Questionnaire.QuestionnaireItemType.GROUP -> null + else -> { + item + .firstOrNull { questionnaireItem -> + questionnaireItem.type == Questionnaire.QuestionnaireItemType.DISPLAY && + questionnaireItem.displayItemControl == null + } + ?.localizedTextSpanned } - ?.localizedTextSpanned + } + } /** * A nested questionnaire item of type display with code [DisplayItemControlType.FLYOVER] (if diff --git a/datacapture/src/main/java/com/google/android/fhir/datacapture/views/QuestionnaireItemHeaderView.kt b/datacapture/src/main/java/com/google/android/fhir/datacapture/views/QuestionnaireItemHeaderView.kt index 9cea313707..97221693b3 100644 --- a/datacapture/src/main/java/com/google/android/fhir/datacapture/views/QuestionnaireItemHeaderView.kt +++ b/datacapture/src/main/java/com/google/android/fhir/datacapture/views/QuestionnaireItemHeaderView.kt @@ -41,22 +41,31 @@ internal class QuestionnaireItemHeaderView(context: Context, attrs: AttributeSet private var hint: TextView = findViewById(R.id.hint) fun bind(questionnaireItem: Questionnaire.QuestionnaireItemComponent) { - questionnaireItem.localizedPrefixSpanned.let { - if (!it.isNullOrEmpty()) { - prefix.visibility = View.VISIBLE - prefix.text = it + val localizedPrefixSpanned = questionnaireItem.localizedPrefixSpanned + prefix.visibility = + if (localizedPrefixSpanned.isNullOrEmpty()) { + View.GONE } else { - prefix.visibility = View.GONE + View.VISIBLE } - } - question.text = questionnaireItem.localizedTextSpanned - questionnaireItem.localizedHintSpanned.let { - if (!it.isNullOrEmpty()) { - hint.visibility = View.VISIBLE - hint.text = it + prefix.text = localizedPrefixSpanned + + val localizedTextSpanned = questionnaireItem.localizedTextSpanned + question.visibility = + if (localizedTextSpanned.isNullOrEmpty()) { + View.GONE + } else { + View.VISIBLE + } + question.text = localizedTextSpanned + + val localizedHintSpanned = questionnaireItem.localizedHintSpanned + hint.visibility = + if (localizedHintSpanned.isNullOrEmpty()) { + View.GONE } else { - hint.visibility = View.GONE + View.VISIBLE } - } + hint.text = localizedHintSpanned } } diff --git a/datacapture/src/test/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponentsTest.kt b/datacapture/src/test/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponentsTest.kt index b4a3f81add..4b712ef156 100644 --- a/datacapture/src/test/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponentsTest.kt +++ b/datacapture/src/test/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponentsTest.kt @@ -340,6 +340,23 @@ class MoreQuestionnaireItemComponentsTest { assertThat(questionItemList.first().localizedHintSpanned).isNull() } + @Test + fun localizedHintSpanned_groupType_shouldReturnNull() { + val questionnaireItemComponent = + Questionnaire.QuestionnaireItemComponent().apply { + type = Questionnaire.QuestionnaireItemType.GROUP + item = + listOf( + Questionnaire.QuestionnaireItemComponent().apply { + linkId = "nested-display-question" + text = "text" + } + ) + } + + assertThat(questionnaireItemComponent.localizedHintSpanned).isNull() + } + @Test fun localizedHintSpanned_shouldReturnText() { val questionItemList =