From d6ba54b8f5d120cf592c086db1fc08655501e8a3 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Fri, 22 Nov 2024 15:31:37 -0500 Subject: [PATCH 1/5] Attempt to use HtmlText --- .../ui/compose/components/text/HtmlTextM3.kt | 35 +++++++++++++++++++ .../main/feedbackform/FeedbackFormScreen.kt | 12 +++++++ WordPress/src/main/res/values/strings.xml | 1 + 3 files changed, 48 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/compose/components/text/HtmlTextM3.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/compose/components/text/HtmlTextM3.kt b/WordPress/src/main/java/org/wordpress/android/ui/compose/components/text/HtmlTextM3.kt new file mode 100644 index 000000000000..f0db0ab4e99c --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/compose/components/text/HtmlTextM3.kt @@ -0,0 +1,35 @@ +import android.util.TypedValue +import android.widget.TextView +import androidx.annotation.ColorRes +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.viewinterop.AndroidView +import androidx.core.text.HtmlCompat +import org.wordpress.android.R + +/** + * Text composables don't support HTML at this time so we get around it by resorting + * to a standard TextView + */ +@Composable +fun HtmlTextM3( + text: String, + modifier: Modifier = Modifier, + @ColorRes color: Int = R.color.text, + @ColorRes linkColor: Int = R.color.link_reader, + fontSize: Float? = null, + alignment: Int? = null, +) { + AndroidView( + modifier = modifier, + factory = { context -> + TextView(context).apply { + fontSize?.let { setTextSize(TypedValue.COMPLEX_UNIT_SP, it) } + alignment?.let { textAlignment = it } + setTextColor(context.getColor(color)) + setText(HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)) + setLinkTextColor(context.getColor(linkColor)) + } + } + ) +} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt index 9cce18e6cae5..2b50fe75bd6a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.main.feedbackform +import HtmlTextM3 import android.content.Context import android.content.res.Configuration import android.net.Uri @@ -42,6 +43,8 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.core.text.HtmlCompat +import androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT import kotlinx.coroutines.flow.MutableStateFlow import org.wordpress.android.R import org.wordpress.android.ui.compose.components.MediaUriPager @@ -102,6 +105,10 @@ private fun MessageSection( messageText: String?, onMessageChanged: (String) -> Unit, ) { + val htmlText = HtmlCompat.fromHtml( + stringResource(id = R.string.feedback_form_not_support), + FROM_HTML_MODE_COMPACT + ) val focusRequester = remember { FocusRequester() } LaunchedEffect(Unit) { focusRequester.requestFocus() @@ -114,6 +121,11 @@ private fun MessageSection( horizontal = H_PADDING.dp ) ) { + HtmlTextM3( + text = stringResource(id = R.string.feedback_form_not_support), + modifier = Modifier + .padding(top = V_PADDING.dp) + ) OutlinedTextField( value = messageText ?: "", placeholder = { diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 577088e2b91e..ae695528a44c 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1149,6 +1149,7 @@ Unable to create temporary file Add attachments If you need support, please get in touch using the \"Contact Support\" screen + Remove item %1$d From 7e4918eb9c6c5e41b7677b3483bec83eab1f7bd9 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Fri, 22 Nov 2024 15:54:04 -0500 Subject: [PATCH 2/5] Drop HtmlText, first pass at annotated string --- .../ui/compose/components/text/HtmlTextM3.kt | 35 --------------- .../main/feedbackform/FeedbackFormScreen.kt | 43 +++++++++++-------- WordPress/src/main/res/values/strings.xml | 4 +- 3 files changed, 26 insertions(+), 56 deletions(-) delete mode 100644 WordPress/src/main/java/org/wordpress/android/ui/compose/components/text/HtmlTextM3.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/compose/components/text/HtmlTextM3.kt b/WordPress/src/main/java/org/wordpress/android/ui/compose/components/text/HtmlTextM3.kt deleted file mode 100644 index f0db0ab4e99c..000000000000 --- a/WordPress/src/main/java/org/wordpress/android/ui/compose/components/text/HtmlTextM3.kt +++ /dev/null @@ -1,35 +0,0 @@ -import android.util.TypedValue -import android.widget.TextView -import androidx.annotation.ColorRes -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.viewinterop.AndroidView -import androidx.core.text.HtmlCompat -import org.wordpress.android.R - -/** - * Text composables don't support HTML at this time so we get around it by resorting - * to a standard TextView - */ -@Composable -fun HtmlTextM3( - text: String, - modifier: Modifier = Modifier, - @ColorRes color: Int = R.color.text, - @ColorRes linkColor: Int = R.color.link_reader, - fontSize: Float? = null, - alignment: Int? = null, -) { - AndroidView( - modifier = modifier, - factory = { context -> - TextView(context).apply { - fontSize?.let { setTextSize(TypedValue.COMPLEX_UNIT_SP, it) } - alignment?.let { textAlignment = it } - setTextColor(context.getColor(color)) - setText(HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)) - setLinkTextColor(context.getColor(linkColor)) - } - } - ) -} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt index 2b50fe75bd6a..e77a8398c5cd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt @@ -1,6 +1,5 @@ package org.wordpress.android.ui.main.feedbackform -import HtmlTextM3 import android.content.Context import android.content.res.Configuration import android.net.Uri @@ -38,13 +37,17 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.LinkAnnotation +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.TextLinkStyles +import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.input.KeyboardCapitalization +import androidx.compose.ui.text.withLink import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import androidx.core.text.HtmlCompat -import androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT import kotlinx.coroutines.flow.MutableStateFlow import org.wordpress.android.R import org.wordpress.android.ui.compose.components.MediaUriPager @@ -105,10 +108,8 @@ private fun MessageSection( messageText: String?, onMessageChanged: (String) -> Unit, ) { - val htmlText = HtmlCompat.fromHtml( - stringResource(id = R.string.feedback_form_not_support), - FROM_HTML_MODE_COMPACT - ) + val linkText = stringResource(id = R.string.feedback_form_note_link) + val focusRequester = remember { FocusRequester() } LaunchedEffect(Unit) { focusRequester.requestFocus() @@ -121,10 +122,21 @@ private fun MessageSection( horizontal = H_PADDING.dp ) ) { - HtmlTextM3( - text = stringResource(id = R.string.feedback_form_not_support), - modifier = Modifier - .padding(top = V_PADDING.dp) + Text( + text = buildAnnotatedString { + append(stringResource(id = R.string.feedback_form_note_text)) + withLink( + LinkAnnotation.Url( + url = "support", + styles = TextLinkStyles( + style = SpanStyle(color = colorResource(id = R.color.primary)) + ) + ) + ) { + append(linkText) + } + append(".") + } ) OutlinedTextField( value = messageText ?: "", @@ -141,15 +153,8 @@ private fun MessageSection( modifier = Modifier .fillMaxWidth() .defaultMinSize(minHeight = 180.dp) - .focusRequester(focusRequester), - ) - Text( - text = stringResource(id = R.string.feedback_form_note), - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier + .focusRequester(focusRequester) .padding(top = V_PADDING.dp) - ) } } diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index ae695528a44c..cfafd635526b 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1148,8 +1148,8 @@ Attachment already added Unable to create temporary file Add attachments - If you need support, please get in touch using the \"Contact Support\" screen - + Thanks for giving us feedback! Please note this is not a support form, and we will not be able to reply. If you need support, please use our " + Contact Support screen Remove item %1$d From aa3a24c2025fc5d0c1e18a10adf8074c61ac08d4 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Fri, 22 Nov 2024 16:03:42 -0500 Subject: [PATCH 3/5] Return to Help screen --- .../main/feedbackform/FeedbackFormActivity.kt | 12 ++++++++++- .../main/feedbackform/FeedbackFormScreen.kt | 21 ++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt index 3440ea68a9bf..1768619cdf89 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt @@ -43,7 +43,10 @@ class FeedbackFormActivity : LocaleAwareActivity() { }, onRemoveMediaClick = { viewModel.onRemoveMediaClick(it) - } + }, + onSupportClick = { + showSupport() + }, ) } } @@ -60,4 +63,11 @@ class FeedbackFormActivity : LocaleAwareActivity() { } } } + + /** + * This will return to the Help screen + */ + private fun showSupport() { + finish() + } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt index e77a8398c5cd..3b3de4cfa848 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt @@ -65,6 +65,7 @@ fun FeedbackFormScreen( onCloseClick: (context: Context) -> Unit, onChooseMediaClick: () -> Unit, onRemoveMediaClick: (uri: Uri) -> Unit, + onSupportClick: () -> Unit, ) { val context = LocalContext.current val message = messageText?.value ?: "" @@ -74,6 +75,7 @@ fun FeedbackFormScreen( onMessageChanged = { onMessageChanged(it) }, + onSupportClick = onSupportClick ) MediaUriPager( mediaUris = attachments.value.map { it.uri }, @@ -107,8 +109,17 @@ fun FeedbackFormScreen( private fun MessageSection( messageText: String?, onMessageChanged: (String) -> Unit, + onSupportClick: () -> Unit ) { val linkText = stringResource(id = R.string.feedback_form_note_link) + val linkAnnotation = LinkAnnotation.Url( + url = "support", + styles = TextLinkStyles( + style = SpanStyle(color = colorResource(id = R.color.primary)) + ) + ) { + onSupportClick() + } val focusRequester = remember { FocusRequester() } LaunchedEffect(Unit) { @@ -126,12 +137,7 @@ private fun MessageSection( text = buildAnnotatedString { append(stringResource(id = R.string.feedback_form_note_text)) withLink( - LinkAnnotation.Url( - url = "support", - styles = TextLinkStyles( - style = SpanStyle(color = colorResource(id = R.color.primary)) - ) - ) + linkAnnotation ) { append(linkText) } @@ -293,7 +299,8 @@ private fun FeedbackFormScreenPreview() { onSubmitClick = {}, onCloseClick = {}, onChooseMediaClick = {}, - onRemoveMediaClick = {} + onRemoveMediaClick = {}, + onSupportClick = {}, ) } From db6a61a14a71ea1af7f2fc7d8a4a64e55912e547 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Fri, 22 Nov 2024 16:07:00 -0500 Subject: [PATCH 4/5] Shortened message --- .../android/ui/main/feedbackform/FeedbackFormActivity.kt | 2 +- .../android/ui/main/feedbackform/FeedbackFormScreen.kt | 4 ++-- WordPress/src/main/res/values/strings.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt index 1768619cdf89..68f63beaa0b5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt @@ -65,7 +65,7 @@ class FeedbackFormActivity : LocaleAwareActivity() { } /** - * This will return to the Help screen + * This will return to the Help screen, where the user can see the contact support link */ private fun showSupport() { finish() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt index 3b3de4cfa848..099ce6e0f4c2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormScreen.kt @@ -141,8 +141,8 @@ private fun MessageSection( ) { append(linkText) } - append(".") - } + }, + modifier = Modifier.padding(bottom = V_PADDING.dp) ) OutlinedTextField( value = messageText ?: "", diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index cfafd635526b..e0efb03e3f17 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1148,8 +1148,8 @@ Attachment already added Unable to create temporary file Add attachments - Thanks for giving us feedback! Please note this is not a support form, and we will not be able to reply. If you need support, please use our " - Contact Support screen + Please note this is not a support form, and we will not be able to reply. If you need support, please use our " + Contact Support screen. Remove item %1$d From b02e3d96bde5acab8798a62e9f06437dcdd9f8e8 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Fri, 22 Nov 2024 16:08:56 -0500 Subject: [PATCH 5/5] Moved fun --- .../ui/main/feedbackform/FeedbackFormActivity.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt index 68f63beaa0b5..c187a28ddc15 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormActivity.kt @@ -45,7 +45,8 @@ class FeedbackFormActivity : LocaleAwareActivity() { viewModel.onRemoveMediaClick(it) }, onSupportClick = { - showSupport() + // This will return to the Help screen, where the user can see the contact support link + finish() }, ) } @@ -63,11 +64,4 @@ class FeedbackFormActivity : LocaleAwareActivity() { } } } - - /** - * This will return to the Help screen, where the user can see the contact support link - */ - private fun showSupport() { - finish() - } }