-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply separate style to question text if type is group. (#1546)
* Apply style to group type header view. * Address review comments. * Address review comment. * Address review comments. Co-authored-by: Santosh Pingle <[email protected]>
- Loading branch information
1 parent
aeb5259
commit b12ff3a
Showing
9 changed files
with
251 additions
and
43 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...c/main/java/com/google/android/fhir/datacapture/views/QuestionnaireGroupTypeHeaderView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.fhir.datacapture.views | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.widget.LinearLayout | ||
import android.widget.TextView | ||
import com.google.android.fhir.datacapture.R | ||
import com.google.android.fhir.datacapture.localizedHintSpanned | ||
import com.google.android.fhir.datacapture.localizedPrefixSpanned | ||
import com.google.android.fhir.datacapture.localizedTextSpanned | ||
import org.hl7.fhir.r4.model.Questionnaire | ||
|
||
internal class QuestionnaireGroupTypeHeaderView(context: Context, attrs: AttributeSet?) : | ||
LinearLayout(context, attrs) { | ||
|
||
init { | ||
LayoutInflater.from(context).inflate(R.layout.questionnaire_group_type_header, this, true) | ||
} | ||
|
||
fun bind(questionnaireItem: Questionnaire.QuestionnaireItemComponent) { | ||
val prefix = findViewById<TextView>(R.id.prefix) | ||
val question = findViewById<TextView>(R.id.question) | ||
val hint = findViewById<TextView>(R.id.hint) | ||
prefix.updateTextAndVisibility(questionnaireItem.localizedPrefixSpanned) | ||
question.updateTextAndVisibility(questionnaireItem.localizedTextSpanned) | ||
hint.updateTextAndVisibility(questionnaireItem.localizedHintSpanned) | ||
visibility = getViewGroupVisibility(prefix, question, hint) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
datacapture/src/main/res/layout/questionnaire_group_type_header.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
> | ||
|
||
<TextView | ||
android:id="@+id/prefix" | ||
style="?attr/questionnaireGroupTypeQuestionTextStyle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingEnd="@dimen/prefix_padding_end" | ||
app:layout_constraintEnd_toStartOf="@+id/question" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/question" | ||
style="?attr/questionnaireGroupTypeQuestionTextStyle" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toEndOf="@id/prefix" | ||
app:layout_constraintTop_toTopOf="parent" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/hint" | ||
style="?attr/questionnaireSubtitleTextStyle" | ||
android:text="group type" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="4dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/question" | ||
/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...st/java/com/google/android/fhir/datacapture/views/QuestionnaireGroupTypeHeaderViewTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.fhir.datacapture.views | ||
|
||
import android.view.View | ||
import android.widget.FrameLayout | ||
import android.widget.TextView | ||
import androidx.core.view.isVisible | ||
import com.google.android.fhir.datacapture.R | ||
import com.google.common.truth.Truth.assertThat | ||
import org.hl7.fhir.r4.model.Questionnaire | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.RuntimeEnvironment | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class QuestionnaireGroupTypeHeaderViewTest { | ||
private val parent = | ||
FrameLayout( | ||
RuntimeEnvironment.getApplication().apply { setTheme(R.style.Theme_MaterialComponents) } | ||
) | ||
private val view = QuestionnaireGroupTypeHeaderView(parent.context, null) | ||
|
||
@Test | ||
fun shouldShowPrefix() { | ||
view.bind(Questionnaire.QuestionnaireItemComponent().apply { prefix = "Prefix?" }) | ||
|
||
assertThat(view.findViewById<TextView>(R.id.prefix).isVisible).isTrue() | ||
assertThat(view.findViewById<TextView>(R.id.prefix).text.toString()).isEqualTo("Prefix?") | ||
} | ||
|
||
@Test | ||
fun shouldHidePrefix() { | ||
view.bind(Questionnaire.QuestionnaireItemComponent().apply { prefix = "" }) | ||
|
||
assertThat(view.findViewById<TextView>(R.id.prefix).isVisible).isFalse() | ||
} | ||
|
||
@Test | ||
fun shouldShowQuestion() { | ||
view.bind( | ||
Questionnaire.QuestionnaireItemComponent().apply { | ||
repeats = true | ||
text = "Question?" | ||
} | ||
) | ||
|
||
assertThat(view.findViewById<TextView>(R.id.question).text.toString()).isEqualTo("Question?") | ||
} | ||
|
||
@Test | ||
fun shouldShowHint() { | ||
view.bind( | ||
Questionnaire.QuestionnaireItemComponent().apply { | ||
item = | ||
listOf( | ||
Questionnaire.QuestionnaireItemComponent().apply { | ||
linkId = "nested-display-question" | ||
text = "subtitle text" | ||
type = Questionnaire.QuestionnaireItemType.DISPLAY | ||
} | ||
) | ||
} | ||
) | ||
|
||
assertThat(view.findViewById<TextView>(R.id.hint).isVisible).isTrue() | ||
assertThat(view.findViewById<TextView>(R.id.hint).text.toString()).isEqualTo("subtitle text") | ||
} | ||
|
||
@Test | ||
fun shouldHideHint() { | ||
view.bind( | ||
Questionnaire.QuestionnaireItemComponent().apply { | ||
item = | ||
listOf( | ||
Questionnaire.QuestionnaireItemComponent().apply { | ||
linkId = "nested-display-question" | ||
type = Questionnaire.QuestionnaireItemType.DISPLAY | ||
} | ||
) | ||
} | ||
) | ||
|
||
assertThat(view.findViewById<TextView>(R.id.hint).visibility).isEqualTo(View.GONE) | ||
} | ||
|
||
@Test | ||
fun shouldShowHeaderView() { | ||
view.bind( | ||
Questionnaire.QuestionnaireItemComponent().apply { | ||
item = | ||
listOf( | ||
Questionnaire.QuestionnaireItemComponent().apply { | ||
linkId = "nested-display-question" | ||
text = "subtitle text" | ||
type = Questionnaire.QuestionnaireItemType.DISPLAY | ||
} | ||
) | ||
} | ||
) | ||
|
||
assertThat(view.visibility).isEqualTo(View.VISIBLE) | ||
} | ||
|
||
@Test | ||
fun shouldHideHeaderView() { | ||
view.bind(Questionnaire.QuestionnaireItemComponent()) | ||
|
||
assertThat(view.visibility).isEqualTo(View.GONE) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters