-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change areItemsTheSame to check if internal objects are the same with === #1185
Conversation
…nswerChanged calls this internally
… which may contain nested questionnaireReponseItems
Codecov Report
@@ Coverage Diff @@
## master #1185 +/- ##
=========================================
Coverage 84.57% 84.57%
- Complexity 627 632 +5
=========================================
Files 135 135
Lines 10404 10407 +3
Branches 786 787 +1
=========================================
+ Hits 8799 8802 +3
+ Misses 1210 1209 -1
- Partials 395 396 +1
Continue to review full report at Codecov.
|
Thanks Kashyap for fixing this. First thought is that we should write some tests to cover this case. Upon second thought I'm not entirely sure why this would be the fix anyway - it seems like if |
Sure , ill write a UT first. |
* perform a Diff before updating the view. While checking if two [QuestionnaireItemViewItem]s are | ||
* equal or not, we need to check if they are referencing the same objects. | ||
*/ | ||
override fun equals(other: Any?): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return early if other isn't also a questionnaire item view item?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
...capture/src/main/java/com/google/android/fhir/datacapture/views/QuestionnaireItemViewItem.kt
Outdated
Show resolved
Hide resolved
return this.questionnaireItem === (other as QuestionnaireItemViewItem).questionnaireItem && | ||
this.questionnaireResponseItem === | ||
(other as QuestionnaireItemViewItem).questionnaireResponseItem | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add another function equalsDeep
to handle the areContentsTheSame
functino of the DiffCallback
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @joiskash again for debugging fixing this very thorny issue!
Just a few nits! Please feel free to merge once these are addressed.
* [QuestionnaireResponseItem] match. | ||
*/ | ||
override fun equals(other: Any?): Boolean { | ||
return if (other is QuestionnaireItemViewItem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turn this if condition around and return early.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* On the other hand, under certain circumstances, the underlying [QuestionnaireResponseItem] | ||
* might be recreated for the same question. For example, if a [QuestionnaireItem] is nested under | ||
* another [QuestionnaireItem], the [QuestionnaireResponseItem](s) will be nested under the parent | ||
* [QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent]. and if the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* [QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent]. and if the | |
* [QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent], and if the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* Comparing the contents of two [QuestionnaireItemViewItem]s,involves traversing the underlying | ||
* [Questionnaire.QuestionnaireItemComponent] and | ||
* [QuestionnaireResponse.QuestionnaireResponseItemComponent],and comparing values of all the | ||
* properties. This is done by using the [Questionnaire.QuestionnaireItemComponent.equalsDeep] and | ||
* [QuestionnaireResponse.QuestionnaireResponseItemComponent.equalsDeep] functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Comparing the contents of two [QuestionnaireItemViewItem]s,involves traversing the underlying | |
* [Questionnaire.QuestionnaireItemComponent] and | |
* [QuestionnaireResponse.QuestionnaireResponseItemComponent],and comparing values of all the | |
* properties. This is done by using the [Questionnaire.QuestionnaireItemComponent.equalsDeep] and | |
* [QuestionnaireResponse.QuestionnaireResponseItemComponent.equalsDeep] functions | |
* Comparing the contents of two [QuestionnaireItemViewItem]s by traversing the underlying | |
* [Questionnaire.QuestionnaireItemComponent] and | |
* [QuestionnaireResponse.QuestionnaireResponseItemComponent] and comparing values of all the | |
* properties. This is done by using [Questionnaire.QuestionnaireItemComponent.equalsDeep] and | |
* [QuestionnaireResponse.QuestionnaireResponseItemComponent.equalsDeep]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
...capture/src/main/java/com/google/android/fhir/datacapture/views/QuestionnaireItemViewItem.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Jing Tang <[email protected]>
IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).
Fixes #765
Description
If you have a questionnaire with multiple levels of nesting, questionnaire response items are nested within answers. When the parent answer is changed, we clear the questionnaireResponseItem.answer list and add the new answer to it. The nested questionnaireResponseItems also get cleared and new instances of them are created in the questionnaireResponseItemChangedCallback. Since questionnaireItemViewItem.questionnaireResponseItem was a value , the ViewHolderFactory would always hold the reference to the old nested questionnaireResponseItem. On making it a variable, the viewHolderFactory now gets the reference of the correct questionnaireResponseitem while setting the answer. This allows enable when to work properly and thus displays the third nested answer too.
Alternative(s) considered
No
Type
Choose one: Bug fix
Screenshots (if applicable)
Checklist
./gradlew spotlessApply
and./gradlew spotlessCheck
to check my code follows the style guide of this project./gradlew check
and./gradlew connectedCheck
to test my changes locally