From 8fd653c9d4c9b634127ef520f02ad986b58a7685 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 17 Jun 2024 13:41:28 +0930 Subject: [PATCH] Fix ItemButton contentDescriptions --- .../start/NewConversationHomeFragment.kt | 2 +- .../conversation/v2/MessageDetailActivity.kt | 6 ++-- .../securesms/onboarding/LandingActivity.kt | 4 +-- .../securesms/preferences/SettingsActivity.kt | 21 +++++------ .../thoughtcrime/securesms/ui/Components.kt | 35 ++++++++++--------- .../securesms/ui/components/Button.kt | 3 +- .../securesms/ui/components/ButtonSize.kt | 5 +-- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt index a60e08d18a..63d19b5f84 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt @@ -111,7 +111,7 @@ fun ColumnScope.Items( Divider(startIndent = LocalDimensions.current.dividerIndent) ItemButton(textId = R.string.dialog_join_community_title, icon = R.drawable.ic_globe, onClick = delegate::onJoinCommunitySelected) Divider(startIndent = LocalDimensions.current.dividerIndent) - ItemButton(textId = R.string.activity_settings_invite_button_title, icon = R.drawable.ic_invite_friend, contentDescription = R.string.AccessibilityId_invite_friend_button, onClick = delegate::onInviteFriend) + ItemButton(textId = R.string.activity_settings_invite_button_title, icon = R.drawable.ic_invite_friend, Modifier.contentDescription(R.string.AccessibilityId_invite_friend_button), onClick = delegate::onInviteFriend) Column( modifier = Modifier .padding(horizontal = LocalDimensions.current.marginMedium) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt index f272b86584..8647a538ec 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt @@ -218,7 +218,7 @@ fun CellButtons( Column { onReply?.let { ItemButton( - stringResource(R.string.reply), + R.string.reply, R.drawable.ic_message_details__reply, onClick = it ) @@ -226,14 +226,14 @@ fun CellButtons( } onResend?.let { ItemButton( - stringResource(R.string.resend), + R.string.resend, R.drawable.ic_message_details__refresh, onClick = it ) Divider() } ItemButton( - stringResource(R.string.delete), + R.string.delete, R.drawable.ic_message_details__trash, colors = destructiveButtonColors(), onClick = onDelete diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt index 880380c707..0cefbfcd2c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt @@ -117,7 +117,7 @@ class LandingActivity: BaseActionBarActivity() { } Column { - /*Column(modifier = Modifier + Column(modifier = Modifier .weight(1f) .padding(horizontal = LocalDimensions.current.marginMedium)) { Spacer(modifier = Modifier.weight(1f)) @@ -149,7 +149,7 @@ class LandingActivity: BaseActionBarActivity() { } Spacer(modifier = Modifier.weight(1f)) - }*/ + } Column(modifier = Modifier.padding(horizontal = LocalDimensions.current.marginLarge)) { PrimaryFillButton( diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt index e6c00b23b8..807d978d18 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt @@ -81,6 +81,7 @@ import org.thoughtcrime.securesms.ui.LocalDimensions import org.thoughtcrime.securesms.ui.components.OutlineButton import org.thoughtcrime.securesms.ui.components.OutlineCopyButton import org.thoughtcrime.securesms.ui.color.destructiveButtonColors +import org.thoughtcrime.securesms.ui.contentDescription import org.thoughtcrime.securesms.ui.setThemedContent import org.thoughtcrime.securesms.util.BitmapDecodingException import org.thoughtcrime.securesms.util.BitmapUtil @@ -412,27 +413,27 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { Cell { Column { - ItemButtonWithDrawable(R.string.activity_path_title, icon = if (hasPaths) R.drawable.ic_status else R.drawable.ic_path_yellow) { show() } + ItemButtonWithDrawable(R.string.activity_path_title, if (hasPaths) R.drawable.ic_status else R.drawable.ic_path_yellow) { show() } Divider() - ItemButton(R.string.activity_settings_privacy_button_title, icon = R.drawable.ic_privacy_icon) { show() } + ItemButton(R.string.activity_settings_privacy_button_title, R.drawable.ic_privacy_icon) { show() } Divider() - ItemButton(R.string.activity_settings_notifications_button_title, icon = R.drawable.ic_speaker, contentDescription = R.string.AccessibilityId_notifications) { show() } + ItemButton(R.string.activity_settings_notifications_button_title, R.drawable.ic_speaker, Modifier.contentDescription(R.string.AccessibilityId_notifications)) { show() } Divider() - ItemButton(R.string.activity_settings_conversations_button_title, icon = R.drawable.ic_conversations, contentDescription = R.string.AccessibilityId_conversations) { show() } + ItemButton(R.string.activity_settings_conversations_button_title, R.drawable.ic_conversations, Modifier.contentDescription(R.string.AccessibilityId_conversations)) { show() } Divider() - ItemButton(R.string.activity_settings_message_requests_button_title, icon = R.drawable.ic_message_requests, contentDescription = R.string.AccessibilityId_message_requests) { show() } + ItemButton(R.string.activity_settings_message_requests_button_title, R.drawable.ic_message_requests, Modifier.contentDescription(R.string.AccessibilityId_message_requests)) { show() } Divider() - ItemButton(R.string.activity_settings_message_appearance_button_title, icon = R.drawable.ic_appearance, contentDescription = R.string.AccessibilityId_appearance) { show() } + ItemButton(R.string.activity_settings_message_appearance_button_title, R.drawable.ic_appearance, Modifier.contentDescription(R.string.AccessibilityId_appearance)) { show() } Divider() - ItemButton(R.string.activity_settings_invite_button_title, icon = R.drawable.ic_invite_friend, contentDescription = R.string.AccessibilityId_invite_friend) { sendInvitationToUseSession() } + ItemButton(R.string.activity_settings_invite_button_title, R.drawable.ic_invite_friend, Modifier.contentDescription(R.string.AccessibilityId_invite_friend)) { sendInvitationToUseSession() } Divider() if (!prefs.getHidePassword()) { - ItemButton(R.string.sessionRecoveryPassword, icon = R.drawable.ic_recovery_phrase, contentDescription = R.string.AccessibilityId_recovery_password_menu_item) { show() } + ItemButton(R.string.sessionRecoveryPassword, R.drawable.ic_recovery_phrase, Modifier.contentDescription(R.string.AccessibilityId_recovery_password_menu_item)) { show() } Divider() } - ItemButton(R.string.activity_settings_help_button, icon = R.drawable.ic_help, contentDescription = R.string.AccessibilityId_help) { show() } + ItemButton(R.string.activity_settings_help_button, R.drawable.ic_help, Modifier.contentDescription(R.string.AccessibilityId_help)) { show() } Divider() - ItemButton(R.string.activity_settings_clear_all_data_button_title, colors = destructiveButtonColors(), icon = R.drawable.ic_clear_data, contentDescription = R.string.AccessibilityId_clear_data) { ClearAllDataDialog().show(supportFragmentManager, "Clear All Data Dialog") } + ItemButton(R.string.activity_settings_clear_all_data_button_title, R.drawable.ic_clear_data, Modifier.contentDescription(R.string.AccessibilityId_clear_data), destructiveButtonColors()) { ClearAllDataDialog().show(supportFragmentManager, "Clear All Data Dialog") } } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt index d48ad75b2d..b347cea7db 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt @@ -109,21 +109,11 @@ fun OptionsCard(card: OptionsCard, callbacks: Callbacks) { } } -@Composable -fun ItemButton( - @StringRes textId: Int, - @DrawableRes icon: Int, - colors: ButtonColors = transparentButtonColors(), - @StringRes contentDescription: Int = textId, - onClick: () -> Unit -) { - ItemButton(stringResource(textId), icon, colors, stringResource(contentDescription), onClick) -} - @Composable fun ItemButtonWithDrawable( @StringRes textId: Int, @DrawableRes icon: Int, + modifier: Modifier = Modifier, colors: ButtonColors = transparentButtonColors(), onClick: () -> Unit ) { @@ -131,6 +121,7 @@ fun ItemButtonWithDrawable( ItemButton( text = stringResource(textId), + modifier = modifier, icon = { Image( painter = rememberDrawablePainter(drawable = AppCompatResources.getDrawable(context, icon)), @@ -143,20 +134,24 @@ fun ItemButtonWithDrawable( ) } +/** + * Courtesy [ItemButton] implementation that takes a [DrawableRes] for the [icon] + */ @Composable fun ItemButton( - text: String, + @StringRes textId: Int, @DrawableRes icon: Int, + modifier: Modifier = Modifier, colors: ButtonColors = transparentButtonColors(), - contentDescription: String = text, onClick: () -> Unit ) { ItemButton( - text = text, + text = stringResource(textId), + modifier = modifier, icon = { Icon( painter = painterResource(id = icon), - contentDescription = contentDescription, + contentDescription = null, modifier = Modifier.align(Alignment.Center) ) }, @@ -165,15 +160,21 @@ fun ItemButton( ) } +/** +* Base [ItemButton] implementation. + * + * A button to be used in a list of buttons, usually in a [Cell] or [Card] +*/ @Composable fun ItemButton( text: String, - icon: @Composable() (BoxScope.() -> Unit), + icon: @Composable (BoxScope.() -> Unit), + modifier: Modifier = Modifier, colors: ButtonColors = transparentButtonColors(), onClick: () -> Unit ) { TextButton( - modifier = Modifier + modifier = modifier .fillMaxWidth() .height(60.dp), colors = colors, diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt index 47582f2d18..330021bba6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt @@ -38,7 +38,6 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.filter @@ -47,9 +46,9 @@ import org.thoughtcrime.securesms.ui.GetString import org.thoughtcrime.securesms.ui.LaunchedEffectAsync import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider -import org.thoughtcrime.securesms.ui.color.LocalColors import org.thoughtcrime.securesms.ui.baseBold import org.thoughtcrime.securesms.ui.color.Colors +import org.thoughtcrime.securesms.ui.color.LocalColors import org.thoughtcrime.securesms.ui.color.radioButtonColors import org.thoughtcrime.securesms.ui.color.slimOutlineButton import org.thoughtcrime.securesms.ui.contentDescription diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonSize.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonSize.kt index ef3b2a6e7c..2f5baf0f7e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonSize.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonSize.kt @@ -7,6 +7,7 @@ import androidx.compose.material.LocalTextStyle import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import org.thoughtcrime.securesms.ui.baseBold @@ -34,12 +35,12 @@ interface ButtonSize { val minHeight: Dp object Large: ButtonSize { - override val textStyle = baseBold + override val textStyle = baseBold.copy(textAlign = TextAlign.Center) override val minHeight = 41.dp } object Slim: ButtonSize { - override val textStyle = extraSmallBold + override val textStyle = extraSmallBold.copy(textAlign = TextAlign.Center) override val minHeight = 29.dp }