Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit f60c200

Browse files
committed
refactor(ui): tokenize spacing
1 parent 4939153 commit f60c200

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

app/src/main/java/app/passwordstore/ui/crypto/EditPasswordScreen.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import androidx.compose.ui.Modifier
1414
import androidx.compose.ui.res.painterResource
1515
import androidx.compose.ui.res.stringResource
1616
import androidx.compose.ui.tooling.preview.Preview
17-
import androidx.compose.ui.unit.dp
1817
import app.passwordstore.R
1918
import app.passwordstore.data.passfile.PasswordEntry
2019
import app.passwordstore.ui.APSAppBar
2120
import app.passwordstore.ui.compose.PasswordField
2221
import app.passwordstore.ui.compose.theme.APSTheme
22+
import app.passwordstore.ui.compose.theme.SpacingLarge
23+
import app.passwordstore.ui.compose.theme.SpacingMedium
2324
import app.passwordstore.util.time.UserClock
2425
import app.passwordstore.util.totp.UriTotpFinder
2526

@@ -43,13 +44,16 @@ fun EditPasswordScreen(
4344
}
4445
) { paddingValues ->
4546
Box(modifier = modifier.padding(paddingValues)) {
46-
Column(modifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp).fillMaxSize()) {
47+
Column(
48+
modifier =
49+
Modifier.padding(vertical = SpacingMedium, horizontal = SpacingLarge).fillMaxSize()
50+
) {
4751
if (entry.password != null) {
4852
PasswordField(
4953
value = entry.password!!,
5054
label = stringResource(R.string.password),
5155
initialVisibility = false,
52-
modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(),
56+
modifier = Modifier.padding(bottom = SpacingMedium).fillMaxWidth(),
5357
)
5458
}
5559
ExtraContent(entry = entry)

app/src/main/java/app/passwordstore/ui/crypto/ViewPasswordScreen.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ import androidx.compose.ui.res.stringResource
1818
import androidx.compose.ui.text.capitalize
1919
import androidx.compose.ui.text.intl.Locale
2020
import androidx.compose.ui.tooling.preview.Preview
21-
import androidx.compose.ui.unit.dp
2221
import app.passwordstore.R
2322
import app.passwordstore.data.passfile.PasswordEntry
2423
import app.passwordstore.ui.APSAppBar
2524
import app.passwordstore.ui.compose.CopyButton
2625
import app.passwordstore.ui.compose.PasswordField
2726
import app.passwordstore.ui.compose.theme.APSTheme
27+
import app.passwordstore.ui.compose.theme.SpacingLarge
28+
import app.passwordstore.ui.compose.theme.SpacingMedium
2829
import app.passwordstore.util.time.UserClock
2930
import app.passwordstore.util.totp.UriTotpFinder
3031
import kotlinx.coroutines.flow.first
@@ -49,14 +50,17 @@ fun ViewPasswordScreen(
4950
}
5051
) { paddingValues ->
5152
Box(modifier = modifier.padding(paddingValues)) {
52-
Column(modifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp).fillMaxSize()) {
53+
Column(
54+
modifier =
55+
Modifier.padding(vertical = SpacingMedium, horizontal = SpacingLarge).fillMaxSize()
56+
) {
5357
if (entry.password != null) {
5458
PasswordField(
5559
value = entry.password!!,
5660
label = stringResource(R.string.password),
5761
initialVisibility = false,
5862
readOnly = true,
59-
modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(),
63+
modifier = Modifier.padding(bottom = SpacingMedium).fillMaxWidth(),
6064
)
6165
}
6266
if (entry.hasTotp()) {
@@ -67,7 +71,7 @@ fun ViewPasswordScreen(
6771
readOnly = true,
6872
label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") },
6973
trailingIcon = { CopyButton(totp.value, R.string.copy_label) },
70-
modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(),
74+
modifier = Modifier.padding(bottom = SpacingMedium).fillMaxWidth(),
7175
)
7276
}
7377
if (entry.username != null) {
@@ -77,7 +81,7 @@ fun ViewPasswordScreen(
7781
readOnly = true,
7882
label = { Text(stringResource(R.string.username)) },
7983
trailingIcon = { CopyButton(entry.username!!, R.string.copy_label) },
80-
modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(),
84+
modifier = Modifier.padding(bottom = SpacingMedium).fillMaxWidth(),
8185
)
8286
}
8387
ExtraContent(entry = entry)
@@ -95,7 +99,7 @@ private fun ExtraContent(entry: PasswordEntry, modifier: Modifier = Modifier) {
9599
readOnly = true,
96100
label = { Text(label.capitalize(Locale.current)) },
97101
trailingIcon = { CopyButton(value, R.string.copy_label) },
98-
modifier = modifier.padding(bottom = 8.dp).fillMaxWidth(),
102+
modifier = modifier.padding(bottom = SpacingMedium).fillMaxWidth(),
99103
)
100104
}
101105
}

app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.Row
1010
import androidx.compose.foundation.layout.fillMaxSize
1111
import androidx.compose.foundation.layout.fillMaxWidth
1212
import androidx.compose.foundation.layout.padding
13-
import androidx.compose.foundation.layout.requiredSize
1413
import androidx.compose.foundation.lazy.LazyColumn
1514
import androidx.compose.foundation.lazy.items
1615
import androidx.compose.material3.AlertDialog
@@ -30,10 +29,10 @@ import androidx.compose.ui.res.painterResource
3029
import androidx.compose.ui.res.stringResource
3130
import androidx.compose.ui.text.style.TextOverflow
3231
import androidx.compose.ui.tooling.preview.Preview
33-
import androidx.compose.ui.unit.dp
3432
import app.passwordstore.R
3533
import app.passwordstore.crypto.PGPIdentifier
3634
import app.passwordstore.ui.compose.theme.APSTheme
35+
import app.passwordstore.ui.compose.theme.SpacingLarge
3736
import app.passwordstore.util.extensions.conditional
3837
import kotlinx.collections.immutable.ImmutableList
3938
import kotlinx.collections.immutable.persistentListOf
@@ -90,7 +89,7 @@ private fun KeyItem(
9089
}
9190
Row(
9291
modifier =
93-
modifier.padding(16.dp).fillMaxWidth().conditional(onKeySelected != null) {
92+
modifier.padding(SpacingLarge).fillMaxWidth().conditional(onKeySelected != null) {
9493
clickable { onKeySelected?.invoke(identifier) }
9594
},
9695
horizontalArrangement = Arrangement.SpaceBetween,
@@ -103,7 +102,7 @@ private fun KeyItem(
103102
maxLines = 1,
104103
)
105104
if (onKeySelected == null) {
106-
IconButton(onClick = { isDeleting = true }, modifier = Modifier.requiredSize(24.dp)) {
105+
IconButton(onClick = { isDeleting = true }) {
107106
Icon(
108107
painter = painterResource(R.drawable.ic_delete_24dp),
109108
stringResource(id = R.string.delete),

ui/compose/src/main/kotlin/app/passwordstore/ui/APSAppBar.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import androidx.compose.ui.draw.shadow
1818
import androidx.compose.ui.graphics.Color
1919
import androidx.compose.ui.graphics.painter.Painter
2020
import androidx.compose.ui.graphics.vector.rememberVectorPainter
21-
import androidx.compose.ui.unit.dp
2221
import app.passwordstore.ui.compose.preview.DevicePreviews
2322
import app.passwordstore.ui.compose.preview.ThemePreviews
2423
import app.passwordstore.ui.compose.theme.APSTheme
24+
import app.passwordstore.ui.compose.theme.SpacingMedium
2525

2626
@SuppressLint("ComposableLambdaParameterNaming") // The lint doesn't really apply to `actions`
2727
@Composable
@@ -39,13 +39,13 @@ public fun APSAppBar(
3939
navigationIcon = {
4040
if (navigationIcon != null) {
4141
IconButton(onClick = onNavigationIconClick) {
42-
Icon(painter = navigationIcon, contentDescription = null)
42+
Icon(painter = navigationIcon, contentDescription = "Back navigation button")
4343
}
4444
}
4545
},
4646
actions = actions,
4747
colors = TopAppBarDefaults.topAppBarColors(containerColor = backgroundColor),
48-
modifier = modifier.shadow(8.dp),
48+
modifier = modifier.shadow(SpacingMedium),
4949
)
5050
}
5151

ui/compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordItem.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import androidx.compose.runtime.Composable
1919
import androidx.compose.ui.Alignment
2020
import androidx.compose.ui.Modifier
2121
import androidx.compose.ui.graphics.vector.rememberVectorPainter
22-
import androidx.compose.ui.unit.dp
2322
import app.passwordstore.ui.compose.preview.DevicePreviews
2423
import app.passwordstore.ui.compose.preview.ThemePreviews
2524
import app.passwordstore.ui.compose.theme.APSTheme
25+
import app.passwordstore.ui.compose.theme.SpacingLarge
2626

2727
public enum class ItemType {
2828
File,
@@ -42,7 +42,7 @@ public fun PasswordItem(
4242
.clickable(enabled = true, onClick = onClick)
4343
.background(MaterialTheme.colorScheme.background)
4444
.minimumInteractiveComponentSize()
45-
.padding(horizontal = 16.dp)
45+
.padding(horizontal = SpacingLarge)
4646
.fillMaxWidth(),
4747
horizontalArrangement = Arrangement.SpaceBetween,
4848
verticalAlignment = Alignment.CenterVertically,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package app.passwordstore.ui.compose.theme
2+
3+
import androidx.compose.ui.unit.Dp
4+
import androidx.compose.ui.unit.dp
5+
6+
public val SpacingSmall: Dp = 4.dp
7+
public val SpacingMedium: Dp = 8.dp
8+
public val SpacingLarge: Dp = 16.dp
9+
public val SpacingLargest: Dp = 24.dp

0 commit comments

Comments
 (0)