Skip to content

Commit

Permalink
In paginated layout extra display text is shown at the top. (#1314)
Browse files Browse the repository at this point in the history
* In paginated layout extra display text is shown at the top.

* clean up

* Address review comments.

* Address review comment.
  • Loading branch information
santosh-pingle authored Apr 20, 2022
1 parent def241a commit ae4c26a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,4 +100,42 @@ class QuestionnaireItemGroupViewHolderFactoryInstrumentedTest {

assertThat(viewHolder.itemView.findViewById<TextView>(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<QuestionnaireItemHeaderView>(R.id.header)
.findViewById<TextView>(R.id.hint)
.text
.isNullOrEmpty()
)
.isTrue()
assertThat(
viewHolder
.itemView
.findViewById<QuestionnaireItemHeaderView>(R.id.header)
.findViewById<TextView>(R.id.hint)
.visibility
)
.isEqualTo(View.GONE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit ae4c26a

Please sign in to comment.