fix(ui): adjust width of items in PasswordEntryScreen

This commit is contained in:
Harsh Shandilya 2023-07-05 13:57:21 +05:30
parent 0c8bed4e54
commit 4c28098cbb
No known key found for this signature in database

View file

@ -2,8 +2,11 @@ package app.passwordstore.ui.crypto
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
@ -48,32 +51,28 @@ fun PasswordEntryScreen(
entryName: String, entryName: String,
entry: PasswordEntry, entry: PasswordEntry,
readOnly: Boolean, readOnly: Boolean,
onNavigateUp: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
Scaffold( Scaffold(
topBar = { topBar = {
APSAppBar( APSAppBar(
title = "", title = entryName,
navigationIcon = painterResource(R.drawable.ic_arrow_back_black_24dp), navigationIcon = painterResource(R.drawable.ic_arrow_back_black_24dp),
onNavigationIconClick = {}, onNavigationIconClick = onNavigateUp,
backgroundColor = MaterialTheme.colorScheme.surface, backgroundColor = MaterialTheme.colorScheme.surface,
) )
}, },
) { paddingValues -> ) { paddingValues ->
Box(modifier = modifier.fillMaxSize().padding(paddingValues)) { Box(modifier = modifier.padding(paddingValues)) {
Column(modifier = Modifier.padding(8.dp)) { Column(modifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp).fillMaxSize()) {
Text(
text = entryName,
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(bottom = 8.dp),
)
if (entry.password != null) { if (entry.password != null) {
PasswordField( PasswordField(
value = entry.password!!, value = entry.password!!,
label = stringResource(R.string.password), label = stringResource(R.string.password),
initialVisibility = false, initialVisibility = false,
readOnly = readOnly, readOnly = readOnly,
modifier = Modifier.padding(bottom = 8.dp), modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(),
) )
} }
if (entry.hasTotp() && readOnly) { if (entry.hasTotp() && readOnly) {
@ -84,7 +83,7 @@ fun PasswordEntryScreen(
readOnly = true, readOnly = true,
label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") }, label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") },
trailingIcon = { CopyButton({ totp.value }) }, trailingIcon = { CopyButton({ totp.value }) },
modifier = Modifier.padding(bottom = 8.dp), modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(),
) )
} }
if (entry.username != null && readOnly) { if (entry.username != null && readOnly) {
@ -94,7 +93,7 @@ fun PasswordEntryScreen(
readOnly = true, readOnly = true,
label = { Text(stringResource(R.string.username)) }, label = { Text(stringResource(R.string.username)) },
trailingIcon = { CopyButton({ entry.username!! }) }, trailingIcon = { CopyButton({ entry.username!! }) },
modifier = Modifier.padding(bottom = 8.dp), modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(),
) )
} }
ExtraContent(entry = entry, readOnly = readOnly) ExtraContent(entry = entry, readOnly = readOnly)
@ -117,16 +116,16 @@ private fun ExtraContent(
readOnly = true, readOnly = true,
label = { Text(label.capitalize(Locale.current)) }, label = { Text(label.capitalize(Locale.current)) },
trailingIcon = { CopyButton({ value }) }, trailingIcon = { CopyButton({ value }) },
modifier = modifier.padding(bottom = 8.dp), modifier = modifier.padding(bottom = 8.dp).fillMaxWidth(),
) )
} }
} else { } else {
TextField( TextField(
value = entry.extraContentWithoutAuthData, value = entry.extraContentString,
onValueChange = {}, onValueChange = {},
readOnly = false, readOnly = false,
label = { Text("Extra content") }, label = { Text("Extra content") },
modifier = modifier, modifier = modifier.fillMaxWidth(),
) )
} }
} }
@ -152,7 +151,12 @@ private fun CopyButton(
@Composable @Composable
private fun PasswordEntryPreview() { private fun PasswordEntryPreview() {
APSThemePreview { APSThemePreview {
PasswordEntryScreen(entryName = "Test Entry", entry = createTestEntry(), readOnly = true) PasswordEntryScreen(
entryName = "Test Entry",
entry = createTestEntry(),
readOnly = true,
onNavigateUp = {},
)
} }
} }