Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jingtang10 authored Feb 6, 2024
2 parents ac7b9dc + dbf4ff8 commit 4db4464
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 99 deletions.
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 @@ -78,7 +78,6 @@ class BehaviorListFragment : Fragment(R.layout.behavior_list_fragment) {
backgroundContext = coroutineContext,
fileName = behavior.questionnaireFileName,
),
workflow = behavior.workFlow,
),
)
}
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 All @@ -17,6 +17,7 @@
package com.google.android.fhir.catalog

import android.app.Application
import android.content.Context
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.lifecycle.AndroidViewModel
Expand All @@ -31,7 +32,6 @@ class BehaviorListViewModel(application: Application) : AndroidViewModel(applica
@DrawableRes val iconId: Int,
@StringRes val textId: Int,
val questionnaireFileName: String,
val workFlow: WorkflowType = WorkflowType.BEHAVIOR,
) {
CALCULATED_EXPRESSION(
R.drawable.ic_calculations_behavior,
Expand Down Expand Up @@ -64,4 +64,7 @@ class BehaviorListViewModel(application: Application) : AndroidViewModel(applica
"behavior_dynamic_question_text.json",
),
}

fun isBehavior(context: Context, title: String) =
getBehaviorList().map { context.getString(it.textId) }.contains(title)
}
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 @@ -109,7 +109,6 @@ class ComponentListFragment : Fragment(R.layout.component_list_fragment) {
fileName = it,
)
},
workflow = component.workflow,
),
)
}
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 All @@ -17,6 +17,7 @@
package com.google.android.fhir.catalog

import android.app.Application
import android.content.Context
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.lifecycle.AndroidViewModel
Expand Down Expand Up @@ -46,7 +47,6 @@ class ComponentListViewModel(application: Application, private val state: SavedS
* answer the required questions, an error may be displayed on the particular question.
*/
val questionnaireFileWithValidation: String? = null,
val workflow: WorkflowType = WorkflowType.COMPONENT,
) {
BOOLEAN_CHOICE(
R.drawable.ic_booleanchoice,
Expand Down Expand Up @@ -172,4 +172,10 @@ class ComponentListViewModel(application: Application, private val state: SavedS
ViewItem.ComponentItem(Component.ITEM_ANSWER_MEDIA),
ViewItem.ComponentItem(Component.INITIAL_VALUE),
)

fun isComponent(context: Context, title: String) =
viewItemList
.filterIsInstance<ViewItem.ComponentItem>()
.map { context.getString(it.component.textId) }
.contains(title)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import org.hl7.fhir.r4.model.Patient

class DemoQuestionnaireFragment : Fragment() {
private val viewModel: DemoQuestionnaireViewModel by viewModels()
private val componentListViewModel: ComponentListViewModel by viewModels()
private val behaviorListViewModel: BehaviorListViewModel by viewModels()
private val layoutListViewModel: LayoutListViewModel by viewModels()
private val args: DemoQuestionnaireFragmentArgs by navArgs()
private var isErrorState = false
private lateinit var infoCard: MaterialCardView
Expand All @@ -56,7 +59,7 @@ class DemoQuestionnaireFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
requireContext().setTheme(getThemeId())
requireContext().setTheme(getThemeId(args.questionnaireTitleKey))
return inflater.inflate(R.layout.fragment_demo_questionnaire, container, false)
}

Expand Down Expand Up @@ -184,21 +187,28 @@ class DemoQuestionnaireFragment : Fragment() {
}
}

private fun getThemeId(): Int {
return when (args.workflow) {
WorkflowType.DEFAULT -> R.style.Theme_Androidfhir_DefaultLayout
WorkflowType.COMPONENT,
WorkflowType.BEHAVIOR, -> R.style.Theme_Androidfhir_Component
WorkflowType.PAGINATED -> R.style.Theme_Androidfhir_PaginatedLayout
private fun getThemeId(title: String) =
if (
layoutListViewModel.isPaginatedLayout(requireContext(), title) ||
componentListViewModel.isComponent(requireContext(), title) ||
behaviorListViewModel.isBehavior(requireContext(), title)
) {
R.style.Theme_Androidfhir_PaginatedLayout
} else {
R.style.Theme_Androidfhir_DefaultLayout
}
}

private fun getMenu(): Int? {
return when (args.workflow) {
WorkflowType.COMPONENT -> R.menu.component_menu
else -> null
private fun getMenu(): Int? =
if (
componentListViewModel.isComponent(
requireContext(),
args.questionnaireTitleKey!!,
)
) {
R.menu.component_menu
} else {
null
}
}

private fun onSubmitQuestionnaireClick() {
val questionnaireFragment =
Expand Down Expand Up @@ -229,10 +239,3 @@ class DemoQuestionnaireFragment : Fragment() {
const val QUESTIONNAIRE_FRAGMENT_TAG = "questionnaire-fragment-tag"
}
}

enum class WorkflowType {
COMPONENT,
DEFAULT,
PAGINATED,
BEHAVIOR,
}
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 @@ -81,7 +81,6 @@ class LayoutListFragment : Fragment(R.layout.layout_list_fragment) {
backgroundContext = coroutineContext,
fileName = layout.questionnaireFileName,
),
workflow = layout.workflow,
),
)
}
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 All @@ -17,6 +17,7 @@
package com.google.android.fhir.catalog

import android.app.Application
import android.content.Context
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.lifecycle.AndroidViewModel
Expand All @@ -33,13 +34,11 @@ class LayoutListViewModel(application: Application, private val state: SavedStat
@DrawableRes val iconId: Int,
@StringRes val textId: Int,
val questionnaireFileName: String,
val workflow: WorkflowType = WorkflowType.PAGINATED,
) {
DEFAULT(
R.drawable.ic_defaultlayout,
R.string.layout_name_default_text,
"layout_default.json",
WorkflowType.DEFAULT,
),
PAGINATED(
R.drawable.ic_paginatedlayout,
Expand All @@ -49,4 +48,10 @@ class LayoutListViewModel(application: Application, private val state: SavedStat
REVIEW(R.drawable.ic_reviewlayout, R.string.layout_name_review, ""),
READ_ONLY(R.drawable.ic_readonlylayout, R.string.layout_name_read_only, ""),
}

fun isDefaultLayout(context: Context, title: String) =
context.getString(Layout.DEFAULT.textId) == title

fun isPaginatedLayout(context: Context, title: String) =
context.getString(Layout.PAGINATED.textId) == title
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 Google LLC
* Copyright 2021-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 @@ -103,7 +103,6 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
backgroundContext = coroutineContext,
uri = uri,
),
workflow = WorkflowType.DEFAULT,
),
)
}
Expand Down
4 changes: 0 additions & 4 deletions catalog/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@
app:nullable="true"
android:defaultValue="@null"
/>
<argument
android:name="workflow"
app:argType="com.google.android.fhir.catalog.WorkflowType"
/>
<action
android:id="@+id/action_galleryQuestionnaireFragment_to_questionnaireResponseFragment"
app:destination="@id/questionnaireResponseFragment"
Expand Down
22 changes: 0 additions & 22 deletions catalog/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@
>@style/DarkTheme.MyQuestionnaire.PaginatedLayout</item>
</style>

<style name="Theme.Androidfhir.Component">
<!-- Customize theme for questionnaires in this application. -->
<item
name="questionnaire_theme"
>@style/DarkTheme.MyQuestionnaire.PaginatedLayout.Component</item>
</style>

<style name="DarkTheme.MyQuestionnaire" parent="Theme.MyQuestionnaire">
<item name="colorPrimary">@color/primary_blue_80</item>
<item name="colorOnPrimary">@color/onPrimary_blue_20</item>
Expand Down Expand Up @@ -142,27 +135,12 @@
</style>

<style name="DarkTheme.MyQuestionnaire.DefaultLayout">
<item
name="questionnaireSubmitButtonStyle"
>@style/App.Layout.SubmitButtonStyle
</item>
</style>

<style name="DarkTheme.MyQuestionnaire.PaginatedLayout">
<item
name="questionnaireQuestionTextStyle"
>@style/TextAppearance.Material3.HeadlineMedium
</item>
<item
name="questionnaireSubmitButtonStyle"
>@style/App.Layout.SubmitButtonStyle
</item>
</style>

<style name="DarkTheme.MyQuestionnaire.PaginatedLayout.Component">
<item
name="questionnaireSubmitButtonStyle"
>@style/App.Component.SubmitButtonStyle
</item>
</style>
</resources>
29 changes: 0 additions & 29 deletions catalog/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,12 @@
</style>

<style name="Theme.MyQuestionnaire.DefaultLayout">
<item
name="questionnaireSubmitButtonStyle"
>@style/App.Layout.SubmitButtonStyle
</item>
</style>

<style name="Theme.MyQuestionnaire.PaginatedLayout">
<item name="questionnaireQuestionTextStyle">
@style/TextAppearance.Material3.HeadlineMedium
</item>
<item
name="questionnaireSubmitButtonStyle"
>@style/App.Layout.SubmitButtonStyle
</item>
</style>

<style name="Theme.MyQuestionnaire.PaginatedLayout.Component">
<item
name="questionnaireSubmitButtonStyle"
>@style/App.Component.SubmitButtonStyle
</item>
</style>

<style
name="App.Layout.SubmitButtonStyle"
parent="Questionnaire.SubmitButtonStyle"
>
<item name="android:visibility">visible</item>
</style>

<style
name="App.Component.SubmitButtonStyle"
parent="Questionnaire.SubmitButtonStyle"
>
<item name="android:visibility">gone</item>
</style>

<style
Expand Down
7 changes: 0 additions & 7 deletions catalog/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,4 @@
>@style/Theme.MyQuestionnaire.PaginatedLayout</item>
</style>

<style name="Theme.Androidfhir.Component">
<!-- Customize theme for questionnaires in this application. -->
<item
name="questionnaire_theme"
>@style/Theme.MyQuestionnaire.PaginatedLayout.Component</item>
</style>

</resources>
2 changes: 0 additions & 2 deletions datacapture/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,12 @@
parent="Widget.Material3.Button"
>
<item name="android:textAllCaps">false</item>
<item name="android:visibility">visible</item>
</style>
<style
name="Questionnaire.CancelButtonStyle"
parent="Widget.Material3.Button.TextButton"
>
<item name="android:textAllCaps">false</item>
<item name="android:visibility">visible</item>
</style>

<style
Expand Down

0 comments on commit 4db4464

Please sign in to comment.