diff --git a/datacapture/src/main/java/com/google/android/fhir/datacapture/extensions/MoreQuestionItemStyle.kt b/datacapture/src/main/java/com/google/android/fhir/datacapture/extensions/MoreQuestionItemStyle.kt index 3067d969bd..161e5b4cb4 100644 --- a/datacapture/src/main/java/com/google/android/fhir/datacapture/extensions/MoreQuestionItemStyle.kt +++ b/datacapture/src/main/java/com/google/android/fhir/datacapture/extensions/MoreQuestionItemStyle.kt @@ -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. @@ -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. @@ -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 -> { @@ -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. @@ -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) } /** diff --git a/datacapture/src/main/java/com/google/android/fhir/datacapture/views/compose/Header.kt b/datacapture/src/main/java/com/google/android/fhir/datacapture/views/compose/Header.kt index 481913a4c1..53f16ebccb 100644 --- a/datacapture/src/main/java/com/google/android/fhir/datacapture/views/compose/Header.kt +++ b/datacapture/src/main/java/com/google/android/fhir/datacapture/views/compose/Header.kt @@ -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 @@ -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 @@ -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()) { @@ -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( @@ -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), @@ -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, ) @@ -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 }, ) }