From f60c20060db8922c710294396b6a4107b77abdc2 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 29 May 2024 02:43:15 +0530 Subject: refactor(ui): tokenize spacing --- .../app/passwordstore/ui/crypto/EditPasswordScreen.kt | 10 +++++++--- .../app/passwordstore/ui/crypto/ViewPasswordScreen.kt | 16 ++++++++++------ app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt | 7 +++---- .../src/main/kotlin/app/passwordstore/ui/APSAppBar.kt | 6 +++--- .../kotlin/app/passwordstore/ui/compose/PasswordItem.kt | 4 ++-- .../kotlin/app/passwordstore/ui/compose/theme/Spacing.kt | 9 +++++++++ 6 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Spacing.kt diff --git a/app/src/main/java/app/passwordstore/ui/crypto/EditPasswordScreen.kt b/app/src/main/java/app/passwordstore/ui/crypto/EditPasswordScreen.kt index b456fcc5..3c18207d 100644 --- a/app/src/main/java/app/passwordstore/ui/crypto/EditPasswordScreen.kt +++ b/app/src/main/java/app/passwordstore/ui/crypto/EditPasswordScreen.kt @@ -14,12 +14,13 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp import app.passwordstore.R import app.passwordstore.data.passfile.PasswordEntry import app.passwordstore.ui.APSAppBar import app.passwordstore.ui.compose.PasswordField import app.passwordstore.ui.compose.theme.APSTheme +import app.passwordstore.ui.compose.theme.SpacingLarge +import app.passwordstore.ui.compose.theme.SpacingMedium import app.passwordstore.util.time.UserClock import app.passwordstore.util.totp.UriTotpFinder @@ -43,13 +44,16 @@ fun EditPasswordScreen( } ) { paddingValues -> Box(modifier = modifier.padding(paddingValues)) { - Column(modifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp).fillMaxSize()) { + Column( + modifier = + Modifier.padding(vertical = SpacingMedium, horizontal = SpacingLarge).fillMaxSize() + ) { if (entry.password != null) { PasswordField( value = entry.password!!, label = stringResource(R.string.password), initialVisibility = false, - modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(), + modifier = Modifier.padding(bottom = SpacingMedium).fillMaxWidth(), ) } ExtraContent(entry = entry) diff --git a/app/src/main/java/app/passwordstore/ui/crypto/ViewPasswordScreen.kt b/app/src/main/java/app/passwordstore/ui/crypto/ViewPasswordScreen.kt index 18a07893..a141af9c 100644 --- a/app/src/main/java/app/passwordstore/ui/crypto/ViewPasswordScreen.kt +++ b/app/src/main/java/app/passwordstore/ui/crypto/ViewPasswordScreen.kt @@ -18,13 +18,14 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.capitalize import androidx.compose.ui.text.intl.Locale import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp import app.passwordstore.R import app.passwordstore.data.passfile.PasswordEntry import app.passwordstore.ui.APSAppBar import app.passwordstore.ui.compose.CopyButton import app.passwordstore.ui.compose.PasswordField import app.passwordstore.ui.compose.theme.APSTheme +import app.passwordstore.ui.compose.theme.SpacingLarge +import app.passwordstore.ui.compose.theme.SpacingMedium import app.passwordstore.util.time.UserClock import app.passwordstore.util.totp.UriTotpFinder import kotlinx.coroutines.flow.first @@ -49,14 +50,17 @@ fun ViewPasswordScreen( } ) { paddingValues -> Box(modifier = modifier.padding(paddingValues)) { - Column(modifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp).fillMaxSize()) { + Column( + modifier = + Modifier.padding(vertical = SpacingMedium, horizontal = SpacingLarge).fillMaxSize() + ) { if (entry.password != null) { PasswordField( value = entry.password!!, label = stringResource(R.string.password), initialVisibility = false, readOnly = true, - modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(), + modifier = Modifier.padding(bottom = SpacingMedium).fillMaxWidth(), ) } if (entry.hasTotp()) { @@ -67,7 +71,7 @@ fun ViewPasswordScreen( readOnly = true, label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") }, trailingIcon = { CopyButton(totp.value, R.string.copy_label) }, - modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(), + modifier = Modifier.padding(bottom = SpacingMedium).fillMaxWidth(), ) } if (entry.username != null) { @@ -77,7 +81,7 @@ fun ViewPasswordScreen( readOnly = true, label = { Text(stringResource(R.string.username)) }, trailingIcon = { CopyButton(entry.username!!, R.string.copy_label) }, - modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(), + modifier = Modifier.padding(bottom = SpacingMedium).fillMaxWidth(), ) } ExtraContent(entry = entry) @@ -95,7 +99,7 @@ private fun ExtraContent(entry: PasswordEntry, modifier: Modifier = Modifier) { readOnly = true, label = { Text(label.capitalize(Locale.current)) }, trailingIcon = { CopyButton(value, R.string.copy_label) }, - modifier = modifier.padding(bottom = 8.dp).fillMaxWidth(), + modifier = modifier.padding(bottom = SpacingMedium).fillMaxWidth(), ) } } diff --git a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt index dae2ce0b..fa9c2495 100644 --- a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt +++ b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt @@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.requiredSize import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material3.AlertDialog @@ -30,10 +29,10 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp import app.passwordstore.R import app.passwordstore.crypto.PGPIdentifier import app.passwordstore.ui.compose.theme.APSTheme +import app.passwordstore.ui.compose.theme.SpacingLarge import app.passwordstore.util.extensions.conditional import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf @@ -90,7 +89,7 @@ private fun KeyItem( } Row( modifier = - modifier.padding(16.dp).fillMaxWidth().conditional(onKeySelected != null) { + modifier.padding(SpacingLarge).fillMaxWidth().conditional(onKeySelected != null) { clickable { onKeySelected?.invoke(identifier) } }, horizontalArrangement = Arrangement.SpaceBetween, @@ -103,7 +102,7 @@ private fun KeyItem( maxLines = 1, ) if (onKeySelected == null) { - IconButton(onClick = { isDeleting = true }, modifier = Modifier.requiredSize(24.dp)) { + IconButton(onClick = { isDeleting = true }) { Icon( painter = painterResource(R.drawable.ic_delete_24dp), stringResource(id = R.string.delete), diff --git a/ui/compose/src/main/kotlin/app/passwordstore/ui/APSAppBar.kt b/ui/compose/src/main/kotlin/app/passwordstore/ui/APSAppBar.kt index b832ab0f..942f8fc3 100644 --- a/ui/compose/src/main/kotlin/app/passwordstore/ui/APSAppBar.kt +++ b/ui/compose/src/main/kotlin/app/passwordstore/ui/APSAppBar.kt @@ -18,10 +18,10 @@ import androidx.compose.ui.draw.shadow import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.vector.rememberVectorPainter -import androidx.compose.ui.unit.dp import app.passwordstore.ui.compose.preview.DevicePreviews import app.passwordstore.ui.compose.preview.ThemePreviews import app.passwordstore.ui.compose.theme.APSTheme +import app.passwordstore.ui.compose.theme.SpacingMedium @SuppressLint("ComposableLambdaParameterNaming") // The lint doesn't really apply to `actions` @Composable @@ -39,13 +39,13 @@ public fun APSAppBar( navigationIcon = { if (navigationIcon != null) { IconButton(onClick = onNavigationIconClick) { - Icon(painter = navigationIcon, contentDescription = null) + Icon(painter = navigationIcon, contentDescription = "Back navigation button") } } }, actions = actions, colors = TopAppBarDefaults.topAppBarColors(containerColor = backgroundColor), - modifier = modifier.shadow(8.dp), + modifier = modifier.shadow(SpacingMedium), ) } diff --git a/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordItem.kt b/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordItem.kt index 01b42093..d79bbb61 100644 --- a/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordItem.kt +++ b/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordItem.kt @@ -19,10 +19,10 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.rememberVectorPainter -import androidx.compose.ui.unit.dp import app.passwordstore.ui.compose.preview.DevicePreviews import app.passwordstore.ui.compose.preview.ThemePreviews import app.passwordstore.ui.compose.theme.APSTheme +import app.passwordstore.ui.compose.theme.SpacingLarge public enum class ItemType { File, @@ -42,7 +42,7 @@ public fun PasswordItem( .clickable(enabled = true, onClick = onClick) .background(MaterialTheme.colorScheme.background) .minimumInteractiveComponentSize() - .padding(horizontal = 16.dp) + .padding(horizontal = SpacingLarge) .fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically, diff --git a/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Spacing.kt b/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Spacing.kt new file mode 100644 index 00000000..0e8a60e9 --- /dev/null +++ b/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Spacing.kt @@ -0,0 +1,9 @@ +package app.passwordstore.ui.compose.theme + +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp + +public val SpacingSmall: Dp = 4.dp +public val SpacingMedium: Dp = 8.dp +public val SpacingLarge: Dp = 16.dp +public val SpacingLargest: Dp = 24.dp -- cgit v1.2.3