Skip to content
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

Slider Question functionality added #287

Merged
merged 15 commits into from
Mar 13, 2021

Conversation

MuhammadSalman-7214
Copy link
Contributor

No description provided.

@jingtang10
Copy link
Collaborator

jingtang10 commented Mar 5, 2021

Thanks @MuhammadSalman-7214! Can you please always make sure to link to the issue this PR is addressing (and close the issue after this is merged).

@joiskash do you have bandwidth to take a look at this? Thanks!

@joiskash
Copy link
Collaborator

joiskash commented Mar 5, 2021

Sure I'll have a look at this PR

Copy link
Collaborator

@joiskash joiskash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests in the QuestionnaireItemAdapterTest and address the comments below :)

android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:valueFrom="0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these values should not be hardcoded. They must be obtained from the Questionnaire from sliderStepValue , maxValue & minValue. If not specified in the questionnaire then they must be in values.xml (?) @jingtang10 please comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently these values should remain hard coded as discussed with @jingtang10, and for their values, I am not able to find values.xml currently in the code

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't hardcode these in the xml file. hardcode these in the kotlin files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

) {}
)

Truth.assertThat(viewHolder.itemView.findViewById<TextView>(R.id.slider_header).text)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we import com.google.common.truth.Truth.assertThat and just use assertThat? Just to keep it consistent with all the other Unit tests that have already been written

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please comment again once done.

Copy link
Contributor Author

@MuhammadSalman-7214 MuhammadSalman-7214 Mar 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

@Test
fun singleAnswerOrNull_singleAnswer_shouldReturnSingleAnswer() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to write tests verifying that the slider is working as it is supposed to . Check the answerFalse_shouldSetCheckBoxUnchecked unit test in QuestionnaireItemCheckBoxViewHolderFactoryInstrumentedTest to get a better understanding. The assert statement should use the value returned from the viewHolder.findViewById(R.id.slider)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please comment again once done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@jingtang10 jingtang10 Mar 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see https://github.com/google/android-fhir/blob/master/datacapture/src/androidTest/java/com/google/android/fhir/datacapture/views/QuestionnaireItemEditTextSingleLineViewHolderFactoryInstrumentedTest.kt. So there're two types of test cases, you have the ones that update the UI, and you have the ones that change the UI and update the questionnaire respoonse.

so you'll need to add at least another test case that tests the answer is set after you modify the slider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

val questionnaireItem = questionnaireItemViewItem.questionnaireItem
val answer = questionnaireItemViewItem.singleAnswerOrNull
sliderHeader.text = questionnaireItem.text.value
val sliderValue = answer?.value?.integer?.value?.toString() ?: "0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cant be hardcoded.. imagine if the slider is from 5 to 10

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now, this is hard coded, will create a new issue for this as discussed with @jingtang10 to read values from extensions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i think we'll have to do this in a follow up and especially considering the ongoing work in #224

.setInteger(Integer.newBuilder().setValue(newValue.toInt())
.build()).build()

questionnaireItemViewItem.singleAnswerOrNull = this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this questionnaireItemViewItem.singleAnswerOrNull = for better readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, not understanding this. Can you explain this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of questionnaireItemViewItem.singleAnswerOrNull = this inside the apply block can you refactor such that it is something like this

questionnaireItemViewItem.singleAnswerOrNull = QuestionnaireResponse.Item.Answer.newBuilder().apply { value = .... }

You can refer to the other factories to find this pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joiskash but this is already doing the same way as QuestionnaireResponse.Item.Answer.newBuilder().apply in the code
Screenshot from 2021-03-08 17-44-05

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is the same thing. Just suggesting to maintain uniformity in the code. Also why is the callback called inside apply?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not set questionnaireItemViewItem.singleAnswerOrNull inside the apply

also keep questionnaireItemViewItem.questionnaireResponseItemChangedCallback() outside of apply

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@MuhammadSalman-7214
Copy link
Contributor Author

@jingtang10 and @joiskash made the requested changes, please check, thanks.

}

@Test
fun singleAnswerOrNull_singleAnswer_shouldReturnSingleAnswer() {
Copy link
Collaborator

@jingtang10 jingtang10 Mar 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see https://github.com/google/android-fhir/blob/master/datacapture/src/androidTest/java/com/google/android/fhir/datacapture/views/QuestionnaireItemEditTextSingleLineViewHolderFactoryInstrumentedTest.kt. So there're two types of test cases, you have the ones that update the UI, and you have the ones that change the UI and update the questionnaire respoonse.

so you'll need to add at least another test case that tests the answer is set after you modify the slider.

}

@Test
fun singleAnswerOrNull_singleAnswer_shouldReturnSingleAnswer() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun singleAnswerOrNull_singleAnswer_shouldReturnSingleAnswer() {
fun shouldSetSliderValue() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

@Test
fun singleAnswerOrNull_multipleAnswers_shouldReturnNull() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun singleAnswerOrNull_multipleAnswers_shouldReturnNull() {
fun shouldSetSliderValueToDefault() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

.setInteger(Integer.newBuilder().setValue(newValue.toInt())
.build()).build()

questionnaireItemViewItem.singleAnswerOrNull = this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not set questionnaireItemViewItem.singleAnswerOrNull inside the apply

also keep questionnaireItemViewItem.questionnaireResponseItemChangedCallback() outside of apply

@MuhammadSalman-7214
Copy link
Contributor Author

MuhammadSalman-7214 commented Mar 9, 2021

#287 (comment)
@jingtang10 to take callback out of apply is fine, but how can I take questionnaireItemViewItem.questionnaireResponseItemChangedCallback() outside of apply? as it requires assigning within this apply block. Please mention. Thanks.

@jingtang10
Copy link
Collaborator

thanks @MuhammadSalman-7214. I see you have moved the callback call outside of the apply function.

Have you read this comment from @joiskash https://github.com/google/android-fhir/pull/287/files#r589390062 ?

so maybe this is where the confusion comes from, have you read about scope functions https://kotlinlang.org/docs/scope-functions.html?

you need to do the assignment outside of the apply function:

something = something.newBuilder().apply{...}

@MuhammadSalman-7214
Copy link
Contributor Author

MuhammadSalman-7214 commented Mar 9, 2021

thanks @MuhammadSalman-7214. I see you have moved the callback call outside of the apply function.

Have you read this comment from @joiskash https://github.com/google/android-fhir/pull/287/files#r589390062 ?

so maybe this is where the confusion comes from, have you read about scope functions https://kotlinlang.org/docs/scope-functions.html?

you need to do the assignment outside of the apply function:

something = something.newBuilder().apply{...}

@jingtang10 yes I have already read about scope functions, just there was a bit confusion, but now everything is done. All other requested changes are done as well. Thanks.

Copy link
Collaborator

@jingtang10 jingtang10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MuhammadSalman-7214
Copy link
Contributor Author

thanks @MuhammadSalman-7214

your welcome @jingtang10 👍

@jingtang10
Copy link
Collaborator

#294 has been merged. So please rebase your branch onto master (or merge master into your feature branch if rebase is too difficult) and follow this section in the developer's guide to set up your environment to use the new coding conventions. Thanks!

# Conflicts:
#	datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemExtensions.kt
#	datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireItemAdapter.kt
#	datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireItemViewHolderType.kt
#	datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireItemViewHolderTypeTest.kt
@MuhammadSalman-7214 MuhammadSalman-7214 dismissed joiskash’s stale review March 13, 2021 07:13

Because all the changes have been done already

@MuhammadSalman-7214 MuhammadSalman-7214 merged commit a3c4916 into master Mar 13, 2021
@MuhammadSalman-7214 MuhammadSalman-7214 deleted the ms/add-handle-slider-question branch March 13, 2021 07:13
@s-ayush2903 s-ayush2903 mentioned this pull request Mar 16, 2021
@jingtang10 jingtang10 linked an issue Mar 16, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add slider control
3 participants