From 87f6a139cae9f7660c6e4438c0f57ecf1d9c82dc Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Tue, 18 Jun 2024 14:25:08 +1000 Subject: [PATCH] Cleaning up more dimensions --- .../start/InviteFriendFragment.kt | 40 +++++++++---------- .../securesms/home/SeedReminder.kt | 2 +- .../onboarding/loadaccount/LoadAccount.kt | 2 +- .../securesms/onboarding/loading/Loading.kt | 3 ++ .../MessageNotifications.kt | 2 +- .../securesms/preferences/SettingsActivity.kt | 2 +- .../recoverypassword/RecoveryPassword.kt | 4 +- .../thoughtcrime/securesms/ui/AlertDialog.kt | 28 +++++++++---- .../thoughtcrime/securesms/ui/Dimensions.kt | 5 ++- .../securesms/ui/components/Button.kt | 12 +++--- .../securesms/ui/components/ButtonType.kt | 6 ++- .../securesms/ui/components/QR.kt | 8 ++-- .../securesms/ui/components/SessionTabRow.kt | 3 +- .../securesms/ui/components/Text.kt | 2 +- 14 files changed, 72 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/InviteFriendFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/InviteFriendFragment.kt index cfdc1ce425..0a6d25a69e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/InviteFriendFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/InviteFriendFragment.kt @@ -10,7 +10,9 @@ import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.shape.RoundedCornerShape @@ -39,6 +41,7 @@ import org.thoughtcrime.securesms.ui.components.SlimOutlineButton import org.thoughtcrime.securesms.ui.components.SlimOutlineCopyButton import org.thoughtcrime.securesms.ui.contentDescription import org.thoughtcrime.securesms.ui.createThemedComposeView +import org.thoughtcrime.securesms.ui.extraSmallMonospace import org.thoughtcrime.securesms.ui.small @AndroidEntryPoint @@ -78,39 +81,36 @@ private fun InviteFriend( Column(modifier = Modifier.background(LocalColors.current.backgroundSecondary)) { AppBar(stringResource(R.string.invite_a_friend), onBack = onBack, onClose = onClose) Column( - modifier = Modifier.padding(horizontal = 24.dp), - verticalArrangement = spacedBy(10.dp) + modifier = Modifier.padding(horizontal = LocalDimensions.current.itemSpacingMedium), ) { - Box( + Text( + accountId, modifier = Modifier + .contentDescription(R.string.AccessibilityId_recovery_password_container) + .fillMaxWidth() .border( - width = 1.dp, - color = LocalColors.current.textSecondary, + width = LocalDimensions.current.borderStroke, + color = LocalColors.current.borders, shape = MaterialTheme.shapes.small ) - .fillMaxWidth() - .wrapContentHeight() - ) { - Text( - accountId, - modifier = Modifier - .contentDescription("Your account ID") - .align(Alignment.Center) - .padding(22.dp), - textAlign = TextAlign.Center, - style = base - ) - } + .padding(LocalDimensions.current.marginSmall), + textAlign = TextAlign.Center, + style = base + ) + + Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingXSmall)) Text( stringResource(R.string.invite_your_friend_to_chat_with_you_on_session_by_sharing_your_account_id_with_them), textAlign = TextAlign.Center, style = small, color = LocalColors.current.textSecondary, - modifier = Modifier.padding(horizontal = 8.dp) + modifier = Modifier.padding(horizontal = LocalDimensions.current.itemSpacingSmall) ) - Row(horizontalArrangement = spacedBy(20.dp)) { + Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingSmall)) + + Row(horizontalArrangement = spacedBy(LocalDimensions.current.itemSpacingSmall)) { SlimOutlineButton( stringResource(R.string.share), modifier = Modifier diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/SeedReminder.kt b/app/src/main/java/org/thoughtcrime/securesms/home/SeedReminder.kt index 1f2aec7c53..aac34065bb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/SeedReminder.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/SeedReminder.kt @@ -37,7 +37,7 @@ internal fun SeedReminder(startRecoveryPasswordActivity: () -> Unit) { Box( Modifier .fillMaxWidth() - .height(4.dp) + .height(LocalDimensions.current.indicatorHeight) .background(LocalColors.current.primary) ) Row( diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccount.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccount.kt index fb801fb501..1ee47d37d8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccount.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccount.kt @@ -80,7 +80,7 @@ private fun RecoveryPassword(state: State, onChange: (String) -> Unit = {}, onCo stringResource(R.string.sessionRecoveryPassword), style = h4 ) - Spacer(Modifier.width(6.dp)) + Spacer(Modifier.width(LocalDimensions.current.itemSpacingXXSmall)) Icon( painter = painterResource(id = R.drawable.ic_shield_outline), contentDescription = null, diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt index 7313c7662f..53a7338080 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt @@ -4,6 +4,7 @@ import androidx.compose.animation.core.Animatable import androidx.compose.animation.core.TweenSpec import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -12,6 +13,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import network.loki.messenger.R +import org.thoughtcrime.securesms.ui.LocalDimensions import org.thoughtcrime.securesms.ui.ProgressArc import org.thoughtcrime.securesms.ui.base import org.thoughtcrime.securesms.ui.contentDescription @@ -39,6 +41,7 @@ internal fun LoadingScreen(state: State) { stringResource(R.string.waitOneMoment), style = h7 ) + Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingTiny)) Text( stringResource(R.string.loadAccountProgressMessage), style = base diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt index b3a5ceb1f8..f64a826b4e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt @@ -99,7 +99,7 @@ private fun NotificationRadioButton( shape = RoundedCornerShape(8.dp) ) { Column( - verticalArrangement = Arrangement.spacedBy(6.dp) + verticalArrangement = Arrangement.spacedBy(LocalDimensions.current.itemSpacingXXSmall) ) { Text(stringResource(title), style = h8) Text(stringResource(explanation), style = small) 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 a81f39dfc3..ada05e67b9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt @@ -403,7 +403,7 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { ) } - Spacer(modifier = Modifier.height(24.dp)) + Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingMedium)) var hasPaths by remember { mutableStateOf(false) diff --git a/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt b/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt index 8fb834a68e..79f610caeb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt @@ -104,7 +104,7 @@ private fun RecoveryPasswordCell(seed: String, copySeed:() -> Unit = {}) { AnimatedVisibility(!showQr) { Row( - horizontalArrangement = Arrangement.spacedBy(LocalDimensions.current.marginMedium), + horizontalArrangement = Arrangement.spacedBy(LocalDimensions.current.itemSpacingSmall), verticalAlignment = Alignment.CenterVertically ) { SlimOutlineCopyButton( @@ -136,7 +136,7 @@ private fun RecoveryPassword(seed: String) { .contentDescription(R.string.AccessibilityId_recovery_password_container) .padding(vertical = LocalDimensions.current.marginSmall) .border( - width = 1.dp, + width = LocalDimensions.current.borderStroke, color = LocalColors.current.borders, shape = MaterialTheme.shapes.small ) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt index e301d19062..998c7b570a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt @@ -44,7 +44,11 @@ fun AlertDialog( onClick = onDismissRequest, modifier = Modifier.align(Alignment.TopEnd) ) { - Icon(painter = painterResource(id = R.drawable.ic_dialog_x), tint = LocalColors.current.text, contentDescription = "back") + Icon( + painter = painterResource(id = R.drawable.ic_dialog_x), + tint = LocalColors.current.text, + contentDescription = "back" + ) } Column(modifier = Modifier.fillMaxWidth()) { @@ -52,14 +56,24 @@ fun AlertDialog( horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier .fillMaxWidth() - .padding(top = 24.dp) - .padding(horizontal = 24.dp) + .padding(top = LocalDimensions.current.itemSpacingSmall) + .padding(horizontal = LocalDimensions.current.itemSpacingSmall) ) { title?.let { - Text(it, textAlign = TextAlign.Center, style = h7, modifier = Modifier.padding(bottom = 8.dp)) + Text( + it, + textAlign = TextAlign.Center, + style = h7, + modifier = Modifier.padding(bottom = LocalDimensions.current.itemSpacingXXSmall) + ) } text?.let { - Text(it, textAlign = TextAlign.Center, style = large, modifier = Modifier.padding(bottom = 8.dp)) + Text( + it, + textAlign = TextAlign.Center, + style = large, + modifier = Modifier.padding(bottom = LocalDimensions.current.itemSpacingXXSmall) + ) } } buttons?.takeIf { it.isNotEmpty() }?.let { @@ -95,8 +109,8 @@ fun DialogButton(text: String, modifier: Modifier, onClick: () -> Unit) { color = LocalColors.current.text, style = largeBold, modifier = Modifier.padding( - top = 16.dp, - bottom = 24.dp + top = LocalDimensions.current.itemSpacingSmall, + bottom = LocalDimensions.current.itemSpacingMedium ) ) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Dimensions.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Dimensions.kt index 92a7336838..77fb5318f4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Dimensions.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Dimensions.kt @@ -23,5 +23,8 @@ data class Dimensions( val dividerIndent: Dp = 80.dp, val appBarHeight: Dp = 64.dp, val minScrollableViewHeight: Dp = 200.dp, - val marginHomeEmptyView: Dp = 50.dp + val marginHomeEmptyView: Dp = 50.dp, + + val indicatorHeight: Dp = 4.dp, + val borderStroke: Dp = 1.dp ) 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 a1b4088590..16204f1c68 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 @@ -60,17 +60,17 @@ fun Button( type: ButtonType, modifier: Modifier = Modifier, enabled: Boolean = true, - size: ButtonStyle = ButtonStyle.Large, + style: ButtonStyle = ButtonStyle.Large, shape: Shape = MaterialTheme.shapes.large, border: BorderStroke? = type.border(color, enabled), colors: ButtonColors = type.buttonColors(color), interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, content: @Composable RowScope.() -> Unit ) { - size.applyButtonConstraints { + style.applyButtonConstraints { androidx.compose.material.Button( onClick, - modifier.heightIn(min = size.minHeight), + modifier.heightIn(min = style.minHeight), enabled, interactionSource, elevation = null, @@ -79,7 +79,7 @@ fun Button( colors ) { // Button sets LocalTextStyle, so text style is applied inside to override that. - size.applyTextConstraints { + style.applyTextConstraints { content() } } @@ -158,7 +158,7 @@ fun SlimOutlineCopyButton( @Composable fun OutlineCopyButton( modifier: Modifier = Modifier, - size: ButtonStyle = ButtonStyle.Large, + style: ButtonStyle = ButtonStyle.Large, color: Color = LocalColors.current.buttonOutline, onClick: () -> Unit ) { @@ -167,7 +167,7 @@ fun OutlineCopyButton( Button( modifier = modifier.contentDescription(R.string.AccessibilityId_copy_button), interactionSource = interactionSource, - size = size, + style = style, type = ButtonType.Outline, color = color, onClick = onClick diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonType.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonType.kt index 5c5df4caf9..ccc6e8aaf9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonType.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonType.kt @@ -6,6 +6,7 @@ import androidx.compose.material.ButtonDefaults import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp +import org.thoughtcrime.securesms.ui.LocalDimensions import org.thoughtcrime.securesms.ui.color.LocalColors interface ButtonType { @@ -17,7 +18,10 @@ interface ButtonType { object Outline: ButtonType { @Composable override fun border(color: Color, enabled: Boolean) = - BorderStroke(1.dp, if (enabled) color else LocalColors.current.disabled) + BorderStroke( + width = LocalDimensions.current.borderStroke, + color = if (enabled) color else LocalColors.current.disabled + ) @Composable override fun buttonColors(color: Color) = ButtonDefaults.buttonColors( contentColor = color, diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt index 9f3c08ca19..810ebe7b16 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt @@ -95,7 +95,7 @@ fun MaybeScanQrCode( style = base, textAlign = TextAlign.Center ) - Spacer(modifier = Modifier.size(20.dp)) + Spacer(modifier = Modifier.size(LocalDimensions.current.itemSpacingMedium)) OutlineButton( stringResource(R.string.sessionSettings), modifier = Modifier.align(Alignment.CenterHorizontally), @@ -163,11 +163,11 @@ fun ScanQrCode(errors: Flow, onScan: (String) -> Unit) { snackbarHost = { SnackbarHost( hostState = scaffoldState.snackbarHostState, - modifier = Modifier.padding(16.dp) + modifier = Modifier.padding(LocalDimensions.current.itemSpacingSmall) ) { data -> Snackbar( snackbarData = data, - modifier = Modifier.padding(16.dp) + modifier = Modifier.padding(LocalDimensions.current.itemSpacingSmall) ) } } @@ -181,7 +181,7 @@ fun ScanQrCode(errors: Flow, onScan: (String) -> Unit) { Box( Modifier .aspectRatio(1f) - .padding(20.dp) + .padding(LocalDimensions.current.itemSpacingMedium) .clip(shape = RoundedCornerShape(26.dp)) .background(Color(0x33ffffff)) .align(Alignment.Center) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/SessionTabRow.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/SessionTabRow.kt index 88a8cb2715..5a3956922e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/SessionTabRow.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/SessionTabRow.kt @@ -19,6 +19,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import kotlinx.coroutines.launch import network.loki.messenger.R +import org.thoughtcrime.securesms.ui.LocalDimensions import org.thoughtcrime.securesms.ui.color.LocalColors import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.color.Colors @@ -39,7 +40,7 @@ fun SessionTabRow(pagerState: PagerState, titles: List) { TabRowDefaults.Indicator( Modifier.tabIndicatorOffset(tabPositions[pagerState.currentPage]), color = LocalColors.current.primary, - height = 5.dp + height = LocalDimensions.current.indicatorHeight ) }, divider = { TabRowDefaults.Divider(color = LocalColors.current.divider) }, diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Text.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Text.kt index 6e177d6387..083f75a126 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Text.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Text.kt @@ -66,7 +66,7 @@ fun SessionOutlinedTextField( shape = MaterialTheme.shapes.small ) error?.let { - Spacer(modifier = Modifier.height(14.dp)) + Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingXSmall)) Text( it, modifier = Modifier.fillMaxWidth(),