Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Google LLC
* Copyright 2024-2025 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 @@ -29,8 +29,7 @@ import com.google.android.fhir.datacapture.R
*
* If the custom style resource name is valid, it applies the custom style to the view. If the
* custom style resource name is not valid or not found, it falls back to applying the default style
* defined by the given style resource ID. It sets the view's tag to resourceId to indicate that the
* custom style has been applied.
* defined by the given style resource ID.
*
* @param context the context used to access resources.
* @param view the view to which the style should be applied.
Expand All @@ -46,7 +45,6 @@ internal fun applyCustomOrDefaultStyle(
val customStyleResId = customStyleName?.let { getStyleResIdByName(context, it) } ?: 0
when {
customStyleResId != 0 -> {
view.tag = customStyleResId
QuestionItemCustomStyle().applyStyle(context, view, customStyleResId)
}
defaultStyleResId != 0 -> {
Expand All @@ -58,11 +56,6 @@ internal fun applyCustomOrDefaultStyle(
/**
* Applies the default style to the given view if the default style has not already been applied.
*
* This function checks the `view`'s tag to determine if a style has been previously applied. If the
* tag is an integer, it will apply the default style specified by `defaultStyleResId`. After
* applying the style, it resets the view's tag to `null` to indicate that the default style has
* been applied.
*
* @param context The context used to access resources and themes.
* @param view The view to which the default style will be applied.
* @param defaultStyleResId The resource ID of the default style to apply.
Expand All @@ -72,10 +65,7 @@ private fun applyDefaultStyleIfNotApplied(
view: View,
defaultStyleResId: Int,
) {
(view.tag as? Int)?.let {
QuestionItemDefaultStyle().applyStyle(context, view, defaultStyleResId)
view.tag = null
}
QuestionItemDefaultStyle().applyStyle(context, view, defaultStyleResId)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
Expand All @@ -43,9 +44,9 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import com.google.android.fhir.datacapture.R
import com.google.android.fhir.datacapture.extensions.QuestionItemDefaultStyle
import com.google.android.fhir.datacapture.extensions.StyleUrl
import com.google.android.fhir.datacapture.extensions.appendAsteriskToQuestionText
import com.google.android.fhir.datacapture.extensions.applyCustomOrDefaultStyle
Expand Down Expand Up @@ -135,14 +136,16 @@ internal fun Header(
) {
PrefixQuestionTitle(prefixLocalizedText, questionLocalizedText, readCustomStyleName)

Help(
hintLocalizedText,
readCustomStyleName,
isHelpCardOpen,
isHelpButtonVisible,
helpButtonOnClick,
helpCardLocalizedText,
)
if (!hintLocalizedText.isNullOrBlank() || isHelpButtonVisible || isHelpCardOpen) {
Help(
hintLocalizedText,
readCustomStyleName,
isHelpCardOpen,
isHelpButtonVisible,
helpButtonOnClick,
helpCardLocalizedText,
)
}

// Required/Optional Text
if (showRequiredOrOptionalText && !requiredOptionalText.isNullOrBlank()) {
Expand Down Expand Up @@ -224,28 +227,31 @@ internal fun Help(
var isCardOpen by remember { mutableStateOf(isHelpCardInitiallyOpen) }

Row(
modifier = Modifier.padding(vertical = dimensionResource(R.dimen.help_container_margin_top)),
modifier = Modifier.padding(top = dimensionResource(R.dimen.help_container_margin_top)),
verticalAlignment = Alignment.CenterVertically,
) {
AndroidView(
factory = {
TextView(it).apply {
id = R.id.hint
movementMethod = LinkMovementMethod.getInstance()
applyCustomOrDefaultStyle(
context = it,
view = this,
customStyleName =
readCustomStyleName(
StyleUrl.SUBTITLE_TEXT_VIEW,
),
defaultStyleResId =
getStyleResIdFromAttribute(it, R.attr.questionnaireSubtitleTextStyle),
)
}
},
update = { it.text = hintLocalizedText },
)
hintLocalizedText?.let {
AndroidView(
modifier = Modifier.weight(0.7f),
factory = {
TextView(it).apply {
id = R.id.hint
movementMethod = LinkMovementMethod.getInstance()
applyCustomOrDefaultStyle(
context = it,
view = this,
customStyleName =
readCustomStyleName(
StyleUrl.SUBTITLE_TEXT_VIEW,
),
defaultStyleResId =
getStyleResIdFromAttribute(it, R.attr.questionnaireSubtitleTextStyle),
)
}
},
update = { it.text = hintLocalizedText },
)
}

if (isHelpButtonVisible) {
IconButton(
Expand All @@ -254,8 +260,10 @@ internal fun Help(
helpButtonOnClick(isCardOpen)
},
modifier =
Modifier.padding(start = dimensionResource(R.dimen.help_button_margin_start))
Modifier.padding(dimensionResource(R.dimen.help_icon_padding))
.padding(start = dimensionResource(R.dimen.help_button_margin_start))
.testTag(HELP_BUTTON_TAG)
.weight(0.3f)
.size(
width = dimensionResource(R.dimen.help_button_width),
height = dimensionResource(R.dimen.help_button_height),
Expand All @@ -270,12 +278,22 @@ internal fun Help(
}

if (isCardOpen) {
Card(modifier = Modifier.padding(top = 8.dp).testTag(HELP_CARD_TAG)) {
Column(modifier = Modifier.padding(8.dp)) {
Card(
modifier =
Modifier.padding(top = dimensionResource(R.dimen.help_card_margin_top))
.testTag(HELP_CARD_TAG),
colors =
CardDefaults.cardColors().copy(containerColor = MaterialTheme.colorScheme.surfaceVariant),
) {
Column {
Text(
text = stringResource(id = R.string.help),
modifier =
Modifier.padding(horizontal = dimensionResource(R.dimen.help_header_margin_horizontal)),
Modifier.padding(horizontal = dimensionResource(R.dimen.help_header_margin_horizontal))
.padding(
top = dimensionResource(R.dimen.help_header_margin_top),
bottom = dimensionResource(R.dimen.help_header_margin_bottom),
),
style = MaterialTheme.typography.titleSmall,
)

Expand All @@ -284,10 +302,18 @@ internal fun Help(
TextView(it).apply {
id = R.id.helpText
movementMethod = LinkMovementMethod.getInstance()

QuestionItemDefaultStyle()
.applyStyle(
context,
this,
getStyleResIdFromAttribute(it, R.attr.questionnaireHelpTextStyle),
)
}
},
modifier =
Modifier.padding(horizontal = dimensionResource(R.dimen.help_text_margin_horizontal)),
Modifier.padding(horizontal = dimensionResource(R.dimen.help_text_margin_horizontal))
.padding(bottom = dimensionResource(R.dimen.help_text_margin_bottom)),
update = { it.text = helpCardLocalizedText },
)
}
Expand Down
Loading