From b63f63585b0582c95ca23466e33f4810af4d4230 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 14 Jun 2024 15:18:41 +0930 Subject: [PATCH] Cleanup --- .../RecoveryPasswordActivity.kt | 5 +- .../securesms/ui/SessionTypography.kt | 4 +- .../securesms/ui/components/ButtonSize.kt | 9 +- .../ui/components/SessionOutlinedButton.kt | 176 +++++++----------- 4 files changed, 69 insertions(+), 125 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/recoverypassword/RecoveryPasswordActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/recoverypassword/RecoveryPasswordActivity.kt index a7e1b06ab2..227a96c1ce 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/recoverypassword/RecoveryPasswordActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/recoverypassword/RecoveryPasswordActivity.kt @@ -165,9 +165,8 @@ fun RecoveryPasswordCell(seed: String, copySeed:() -> Unit = {}) { ) SlimOutlineButton( stringResource(R.string.qrView), - modifier = Modifier.weight(1f), - onClick = { showQr = !showQr } - ) + Modifier.weight(1f), + ) { showQr = !showQr } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/SessionTypography.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/SessionTypography.kt index 232734bd70..210286c8d8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/SessionTypography.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/SessionTypography.kt @@ -9,8 +9,9 @@ import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.sp fun boldStyle(size: TextUnit) = TextStyle.Default.copy( + fontSize = size, + lineHeight = size * 1.2, fontWeight = FontWeight.Bold, - fontSize = size ) fun defaultStyle(size: TextUnit, fontFamily: FontFamily? = TextStyle.Default.fontFamily) = TextStyle.Default.copy( @@ -20,6 +21,7 @@ fun defaultStyle(size: TextUnit, fontFamily: FontFamily? = TextStyle.Default.fon ) val xl = defaultStyle(18.sp) + val large = defaultStyle(16.sp) val base = defaultStyle(14.sp) 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 d4e5eca4a2..deb51e0898 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 @@ -4,16 +4,14 @@ import android.annotation.SuppressLint import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.LocalMinimumInteractiveComponentEnforcement import androidx.compose.material.LocalTextStyle -import androidx.compose.material.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import org.thoughtcrime.securesms.ui.baseBold -import org.thoughtcrime.securesms.ui.extraSmall import org.thoughtcrime.securesms.ui.extraSmallBold -import org.thoughtcrime.securesms.ui.smallBold interface ButtonSize { @OptIn(ExperimentalMaterialApi::class) @@ -36,11 +34,6 @@ object LargeButtonSize: ButtonSize { override val minHeight = 41.dp } -object MediumButtonSize: ButtonSize { - override val textStyle @Composable get() = smallBold - override val minHeight = 34.dp -} - object SlimButtonSize: ButtonSize { override val textStyle @Composable get() = extraSmallBold override val minHeight = 29.dp diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/SessionOutlinedButton.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/SessionOutlinedButton.kt index 804486ddde..0832131d5a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/SessionOutlinedButton.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/SessionOutlinedButton.kt @@ -33,119 +33,6 @@ import org.thoughtcrime.securesms.ui.contentDescription import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds -//@Composable -//fun OutlineButton( -// text: String, -// modifier: Modifier = Modifier, -// size: ButtonSize = LargeButtonSize, -// color: Color = LocalPalette.current.buttonOutline, -// onClick: () -> Unit -//) { -// OutlineButton( -// modifier = modifier, -// size = size, -// color = color, -// onClick = onClick -// ) { -// SessionButtonText(text = text, style = size.textStyle, color = color) -// } -//} -// -///** -// * Base implementation of [SessionOutlinedButton] -// */ -//@Composable -//fun OutlineButton( -// modifier: Modifier = Modifier, -// size: ButtonSize = LargeButtonSize, -// enabled: Boolean = true, -// interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, -// color: Color = LocalPalette.current.buttonOutline, -// border: BorderStroke = BorderStroke(1.dp, if (enabled) color else LocalPalette.current.disabled), -// shape: Shape = MaterialTheme.shapes.small, -// onClick: () -> Unit, -// content: @Composable () -> Unit = {} -//) { -// Button( -// modifier = modifier.heightIn(min = size.minHeight), -// enabled = enabled, -// interactionSource = interactionSource, -// onClick = onClick, -// border = border, -// shape = shape, -// type = ButtonType.Outline, -// color = color -// ) { -// size.applyTextStyle { -// content() -// } -// } -//} - -@Composable -fun SlimOutlineCopyButton( - modifier: Modifier = Modifier, - color: Color = LocalPalette.current.buttonOutline, - onClick: () -> Unit -) { - OutlineCopyButton(modifier, SlimButtonSize, color, onClick) -} - -@Composable -fun OutlineCopyButton( - modifier: Modifier = Modifier, - size: ButtonSize = LargeButtonSize, - color: Color = LocalPalette.current.buttonOutline, - onClick: () -> Unit -) { - val interactionSource = remember { MutableInteractionSource() } - - Button( - modifier = modifier.contentDescription(R.string.AccessibilityId_copy_button), - interactionSource = interactionSource, - size = size, - type = ButtonType.Outline, - color = color, - onClick = onClick - ) { - TemporaryClickedContent( - interactionSource = interactionSource, - content = { Text(stringResource(R.string.copy)) }, - temporaryContent = { Text(stringResource(R.string.copied)) } - ) - } -} - -@Composable -fun TemporaryClickedContent( - modifier: Modifier = Modifier, - interactionSource: MutableInteractionSource, - content: @Composable () -> Unit, - temporaryContent: @Composable () -> Unit, - temporaryDelay: Duration = 2.seconds -) { - var clicked by remember { mutableStateOf(false) } - - LaunchedEffectAsync { - interactionSource.releases.collectLatest { - clicked = true - delay(temporaryDelay) - clicked = false - } - } - - // Using a Box because the Buttons add children in a Row - // and they will jank as they are added and removed. - Box(contentAlignment = Alignment.Center) { - AnimatedVisibility(!clicked, enter = fadeIn(), exit = fadeOut()) { - content() - } - AnimatedVisibility(clicked, enter = fadeIn(), exit = fadeOut()) { - temporaryContent() - } - } -} - interface ButtonType { @Composable fun border(color: Color, enabled: Boolean): BorderStroke? @Composable fun buttonColors(color: Color): ButtonColors @@ -252,3 +139,66 @@ fun Button( @Composable fun SlimOutlineButton(onClick: () -> Unit, modifier: Modifier = Modifier, color: Color = LocalPalette.current.buttonOutline, enabled: Boolean = true, content: @Composable () -> Unit) { Button(onClick, color, ButtonType.Outline, modifier, enabled, SlimButtonSize) { content() } } + +@Composable +fun SlimOutlineCopyButton( + modifier: Modifier = Modifier, + color: Color = LocalPalette.current.buttonOutline, + onClick: () -> Unit +) { + OutlineCopyButton(modifier, SlimButtonSize, color, onClick) +} + +@Composable +fun OutlineCopyButton( + modifier: Modifier = Modifier, + size: ButtonSize = LargeButtonSize, + color: Color = LocalPalette.current.buttonOutline, + onClick: () -> Unit +) { + val interactionSource = remember { MutableInteractionSource() } + + Button( + modifier = modifier.contentDescription(R.string.AccessibilityId_copy_button), + interactionSource = interactionSource, + size = size, + type = ButtonType.Outline, + color = color, + onClick = onClick + ) { + TemporaryClickedContent( + interactionSource = interactionSource, + content = { Text(stringResource(R.string.copy)) }, + temporaryContent = { Text(stringResource(R.string.copied)) } + ) + } +} + +@Composable +fun TemporaryClickedContent( + interactionSource: MutableInteractionSource, + content: @Composable () -> Unit, + temporaryContent: @Composable () -> Unit, + temporaryDelay: Duration = 2.seconds +) { + var clicked by remember { mutableStateOf(false) } + + LaunchedEffectAsync { + interactionSource.releases.collectLatest { + clicked = true + delay(temporaryDelay) + clicked = false + } + } + + // Using a Box because the Buttons add children in a Row + // and they will jank as they are added and removed. + Box(contentAlignment = Alignment.Center) { + AnimatedVisibility(!clicked, enter = fadeIn(), exit = fadeOut()) { + content() + } + AnimatedVisibility(clicked, enter = fadeIn(), exit = fadeOut()) { + temporaryContent() + } + } +}