Skip to content

Commit 372ed61

Browse files
committed
Incorporated review feedback.
1 parent 7403e73 commit 372ed61

File tree

4 files changed

+83
-25
lines changed

4 files changed

+83
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.android.fhir.catalog
18+
19+
import androidx.annotation.DrawableRes
20+
import androidx.annotation.StringRes
21+
22+
data class LayoutConfig(
23+
@DrawableRes val iconId: Int,
24+
@StringRes val textId: Int,
25+
val questionnaireFileName: String,
26+
val enableReviewMode: Boolean,
27+
) {
28+
class Builder {
29+
@DrawableRes var iconId: Int = 0
30+
31+
@StringRes var textId: Int = 0
32+
var questionnaireFileName: String = ""
33+
var enableReviewMode: Boolean = false
34+
35+
fun build(): LayoutConfig {
36+
return LayoutConfig(iconId, textId, questionnaireFileName, enableReviewMode)
37+
}
38+
}
39+
}
40+
41+
fun layoutConfig(block: LayoutConfig.Builder.() -> Unit): LayoutConfig {
42+
val builder = LayoutConfig.Builder()
43+
builder.block()
44+
return builder.build()
45+
}

catalog/src/main/java/com/google/android/fhir/catalog/LayoutListFragment.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class LayoutListFragment : Fragment(R.layout.layout_list_fragment) {
6363
private fun onItemClick(layout: LayoutListViewModel.Layout) {
6464
// TODO Remove check when all layout questionnaire json are updated.
6565
// https://github.com/google/android-fhir/issues/1079
66-
if (layout.questionnaireFileName.isEmpty()) {
66+
if (layout.config.questionnaireFileName.isEmpty()) {
6767
return
6868
}
6969
launchQuestionnaireFragment(layout)
@@ -74,14 +74,14 @@ class LayoutListFragment : Fragment(R.layout.layout_list_fragment) {
7474
findNavController()
7575
.navigate(
7676
MainNavGraphDirections.actionGlobalGalleryQuestionnaireFragment(
77-
questionnaireTitleKey = context?.getString(layout.textId) ?: "",
77+
questionnaireTitleKey = context?.getString(layout.config.textId) ?: "",
7878
questionnaireJsonStringKey =
7979
getQuestionnaireJsonStringFromAssets(
8080
context = requireContext(),
8181
backgroundContext = coroutineContext,
82-
fileName = layout.questionnaireFileName,
82+
fileName = layout.config.questionnaireFileName,
8383
),
84-
enableReviewMode = layout.enableReviewMode,
84+
enableReviewMode = layout.config.enableReviewMode,
8585
),
8686
)
8787
}

catalog/src/main/java/com/google/android/fhir/catalog/LayoutListViewModel.kt

+31-18
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package com.google.android.fhir.catalog
1818

1919
import android.app.Application
2020
import android.content.Context
21-
import androidx.annotation.DrawableRes
22-
import androidx.annotation.StringRes
2321
import androidx.lifecycle.AndroidViewModel
2422
import androidx.lifecycle.SavedStateHandle
2523

@@ -31,30 +29,45 @@ class LayoutListViewModel(application: Application, private val state: SavedStat
3129
}
3230

3331
enum class Layout(
34-
@DrawableRes val iconId: Int,
35-
@StringRes val textId: Int,
36-
val questionnaireFileName: String,
37-
val enableReviewMode: Boolean,
32+
val config: LayoutConfig,
3833
) {
3934
DEFAULT(
40-
R.drawable.ic_defaultlayout,
41-
R.string.layout_name_default_text,
42-
"layout_default.json",
43-
false,
35+
layoutConfig {
36+
iconId = R.drawable.ic_defaultlayout
37+
textId = R.string.layout_name_default_text
38+
questionnaireFileName = "layout_default.json"
39+
enableReviewMode = false
40+
},
4441
),
4542
PAGINATED(
46-
R.drawable.ic_paginatedlayout,
47-
R.string.layout_name_paginated,
48-
"layout_paginated.json",
49-
false,
43+
layoutConfig {
44+
iconId = R.drawable.ic_paginatedlayout
45+
textId = R.string.layout_name_paginated
46+
questionnaireFileName = "layout_paginated.json"
47+
enableReviewMode = false
48+
},
49+
),
50+
REVIEW(
51+
layoutConfig {
52+
iconId = R.drawable.ic_reviewlayout
53+
textId = R.string.layout_name_review
54+
questionnaireFileName = "layout_review.json"
55+
enableReviewMode = true
56+
},
57+
),
58+
READ_ONLY(
59+
layoutConfig {
60+
iconId = R.drawable.ic_readonlylayout
61+
textId = R.string.layout_name_read_only
62+
questionnaireFileName = ""
63+
enableReviewMode = false
64+
},
5065
),
51-
REVIEW(R.drawable.ic_reviewlayout, R.string.layout_name_review, "layout_review.json", true),
52-
READ_ONLY(R.drawable.ic_readonlylayout, R.string.layout_name_read_only, "", false),
5366
}
5467

5568
fun isDefaultLayout(context: Context, title: String) =
56-
context.getString(Layout.DEFAULT.textId) == title
69+
context.getString(Layout.DEFAULT.config.textId) == title
5770

5871
fun isPaginatedLayout(context: Context, title: String) =
59-
context.getString(Layout.PAGINATED.textId) == title
72+
context.getString(Layout.PAGINATED.config.textId) == title
6073
}

catalog/src/main/java/com/google/android/fhir/catalog/LayoutsRecyclerViewAdapter.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 Google LLC
2+
* Copyright 2021-2025 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,9 +42,9 @@ class LayoutViewHolder(
4242
private val onItemClick: (LayoutListViewModel.Layout) -> Unit,
4343
) : RecyclerView.ViewHolder(binding.root) {
4444
fun bind(layout: LayoutListViewModel.Layout) {
45-
binding.componentLayoutIconImageview.setImageResource(layout.iconId)
45+
binding.componentLayoutIconImageview.setImageResource(layout.config.iconId)
4646
binding.componentLayoutTextView.text =
47-
binding.componentLayoutTextView.context.getString(layout.textId)
47+
binding.componentLayoutTextView.context.getString(layout.config.textId)
4848
binding.root.setOnClickListener { onItemClick(layout) }
4949
}
5050
}

0 commit comments

Comments
 (0)