Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/gradle/com.fasterxml.jackson.da…
Browse files Browse the repository at this point in the history
…taformat-jackson-dataformat-xml-2.16.1
  • Loading branch information
jingtang10 authored Jan 30, 2024
2 parents fa9fecd + 99c5b9c commit cfe59d4
Show file tree
Hide file tree
Showing 22 changed files with 493 additions and 79 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Releases.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* Copyright 2023-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,7 +54,7 @@ object Releases {

object DataCapture : LibraryArtifact {
override val artifactId = "data-capture"
override val version = "1.0.0"
override val version = "1.1.0"
override val name = "Android FHIR Structured Data Capture Library"
}

Expand Down
60 changes: 60 additions & 0 deletions datacapture/sampledata/layout_paginated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"resourceType": "Questionnaire",
"item": [
{
"linkId": "1",
"type": "group",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "1.1",
"type": "display",
"text": "Personal information",
"prefix": "1."
}
]
},
{
"linkId": "2",
"type": "group",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "2.1",
"type": "date",
"text": "Date of birth",
"prefix": "2.",
"required": true
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* Copyright 2023-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -105,6 +105,30 @@ class QuestionnaireUiEspressoTest {
)
}

@Test
fun shouldHideNextButtonIfDisabled() {
buildFragmentFromQuestionnaire("/layout_paginated.json", true)

clickOnText("Next")

onView(withId(R.id.pagination_next_button))
.check(
ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.GONE)),
)
}

@Test
fun shouldDisplayNextButtonIfEnabled() {
buildFragmentFromQuestionnaire("/layout_paginated.json", true)

onView(withId(R.id.pagination_next_button))
.check(
ViewAssertions.matches(
ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE),
),
)
}

@Test
fun integerTextEdit_inputOutOfRange_shouldShowError() {
buildFragmentFromQuestionnaire("/text_questionnaire_integer.json")
Expand Down Expand Up @@ -503,6 +527,7 @@ class QuestionnaireUiEspressoTest {
val questionnaireFragment =
QuestionnaireFragment.builder()
.setQuestionnaire(questionnaireJsonString)
.setShowCancelButton(true)
.showReviewPageBeforeSubmit(isReviewMode)
.build()
activityScenarioRule.scenario.onActivity { activity ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* Copyright 2023-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -190,10 +190,10 @@ class QuestionnaireFragment : Fragment() {
reviewModeEditButton.visibility = View.GONE

if (displayMode.pagination.isPaginated) {
paginationPreviousButton.visibility = View.VISIBLE
paginationPreviousButton.isEnabled = displayMode.pagination.hasPreviousPage
paginationNextButton.visibility = View.VISIBLE
paginationNextButton.isEnabled = displayMode.pagination.hasNextPage
paginationPreviousButton.visibility =
if (displayMode.pagination.hasPreviousPage) View.VISIBLE else View.GONE
paginationNextButton.visibility =
if (displayMode.pagination.hasNextPage) View.VISIBLE else View.GONE
} else {
paginationPreviousButton.visibility = View.GONE
paginationNextButton.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,16 +47,17 @@ internal object EditTextDecimalViewHolderFactory :
) {
val questionnaireItemViewItemDecimalAnswer =
questionnaireViewItem.answers.singleOrNull()?.valueDecimalType?.value?.toString()

val draftAnswer = questionnaireViewItem.draftAnswer?.toString()

val decimalStringToDisplay = questionnaireItemViewItemDecimalAnswer ?: draftAnswer

if (
decimalStringToDisplay?.toDoubleOrNull() !=
if (questionnaireItemViewItemDecimalAnswer.isNullOrEmpty() && draftAnswer.isNullOrEmpty()) {
textInputEditText.setText("")
} else if (
questionnaireItemViewItemDecimalAnswer?.toDoubleOrNull() !=
textInputEditText.text.toString().toDoubleOrNull()
) {
textInputEditText.setText(decimalStringToDisplay)
textInputEditText.setText(questionnaireItemViewItemDecimalAnswer)
} else if (draftAnswer != null && draftAnswer != textInputEditText.text.toString()) {
textInputEditText.setText(draftAnswer)
}
// Update error message if draft answer present
if (draftAnswer != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -64,14 +64,16 @@ internal object EditTextIntegerViewHolderFactory :
questionnaireViewItem.answers.singleOrNull()?.valueIntegerType?.value?.toString()
val draftAnswer = questionnaireViewItem.draftAnswer?.toString()

val text = answer ?: draftAnswer

// Update the text on the UI only if the value of the saved answer or draft answer
// is different from what the user is typing. We compare the two fields as integers to
// avoid shifting focus if the text values are different, but their integer representation
// is the same (e.g. "001" compared to "1")
if ((text?.toIntOrNull() != textInputEditText.text.toString().toIntOrNull())) {
textInputEditText.setText(text)
if (answer.isNullOrEmpty() && draftAnswer.isNullOrEmpty()) {
textInputEditText.setText("")
} else if (answer?.toIntOrNull() != textInputEditText.text.toString().toIntOrNull()) {
textInputEditText.setText(answer)
} else if (draftAnswer != null && draftAnswer != textInputEditText.text.toString()) {
textInputEditText.setText(draftAnswer)
}

// Update error message if draft answer present
Expand Down
2 changes: 1 addition & 1 deletion datacapture/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
</style>
<style
name="Questionnaire.CancelButtonStyle"
parent="Widget.Material3.Button.OutlinedButton"
parent="Widget.Material3.Button.TextButton"
>
<item name="android:textAllCaps">false</item>
<item name="android:visibility">visible</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -139,6 +139,153 @@ class QuestionnaireFragmentTest {
.isEqualTo(View.VISIBLE)
}

@Test
fun `should hide next button on last page`() {
val questionnaireJson =
"""{
"resourceType": "Questionnaire",
"item": [
{
"linkId": "1",
"type": "group",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "1.1",
"type": "display",
"text": "Item 1"
}
]
},
{
"linkId": "2",
"type": "group",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "2.1",
"type": "display",
"text": "Item 2"
}
]
}
]
}
"""
val scenario =
launchFragmentInContainer<QuestionnaireFragment>(
bundleOf(
EXTRA_QUESTIONNAIRE_JSON_STRING to questionnaireJson,
),
)
scenario.moveToState(Lifecycle.State.RESUMED)
val view = scenario.withFragment { requireView() }
view.findViewById<Button>(R.id.pagination_next_button).performClick()
assertThat(view.findViewById<Button>(R.id.pagination_next_button).visibility)
.isEqualTo(View.GONE)
}

@Test
fun `should hide previous button on first page`() {
val questionnaireJson =
"""{
"resourceType": "Questionnaire",
"item": [
{
"linkId": "1",
"type": "group",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "1.1",
"type": "display",
"text": "Item 1"
}
]
},
{
"linkId": "2",
"type": "group",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "2.1",
"type": "display",
"text": "Item 2"
}
]
}
]
}
"""
val scenario =
launchFragmentInContainer<QuestionnaireFragment>(
bundleOf(
EXTRA_QUESTIONNAIRE_JSON_STRING to questionnaireJson,
),
)
scenario.moveToState(Lifecycle.State.RESUMED)
val view = scenario.withFragment { requireView() }
assertThat(view.findViewById<Button>(R.id.pagination_previous_button).visibility)
.isEqualTo(View.GONE)
}

@Test
fun `questionnaireItemViewHolderFactoryMatchersProvider should have custom QuestionnaireItemViewHolderFactoryMatchers `() {
ApplicationProvider.getApplicationContext<DataCaptureTestApplication>()
Expand Down
Loading

0 comments on commit cfe59d4

Please sign in to comment.