passwords: extract TOTP card from PasswordScreen
- Commit
9c8ca120f44ba4165ad9dc46f129a54a488bb7e3- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 03:38 UTC (17 days ago)
- Parents
c5b8f59
PasswordScreen.kt is 351 lines by the FileLength count (350-line ui limit), so the TOTP card section moves verbatim into its own file as PasswordTotpCard in the same ui package: one public @Composable named for the file. The screen passes password, state.now and a copy callback that keeps the original copyToClipboard totp call, so behaviour is identical; imports only the extracted section used are dropped from PasswordScreen.kt, which is now 314 lines by the same count. Verified: ./gradlew :passwords:lintDev :passwords:testDevUnitTest passes.
Diff
passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordScreen.kt
diff --git a/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordScreen.kt b/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordScreen.ktindex 8a704d32f6..d385f772a2 100644--- a/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordScreen.kt+++ b/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordScreen.kt@@ -31,8 +31,6 @@ import androidx.core.net.toUri import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.util.sharedText-import com.vayunmathur.library.util.tryOrDefault-import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.ExternalIntents import com.vayunmathur.library.ui.FloatingActionButton@@ -55,7 +53,6 @@ import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.passwords.R import com.vayunmathur.passwords.data.Password import com.vayunmathur.passwords.data.Passkey-import com.vayunmathur.passwords.domain.TOTP import com.vayunmathur.passwords.platform.PasswordUiState import com.vayunmathur.passwords.platform.PasswordsActions @@ -209,45 +206,11 @@ fun PasswordScreen( // TOTP card: show generated code and circular timer item {- Card(shape = RoundedCornerShape(8.dp), modifier = Modifier.fillMaxWidth()) {- Column(Modifier.padding(12.dp)) {- Text(stringResource(R.string.section_totp), style = MaterialTheme.typography.titleMedium)- Spacer(Modifier.height(8.dp))-- val secret = password.totpSecret- if (secret.isNullOrBlank()) {- Text(stringResource(R.string.totp_not_configured))- } else {- val timeStep = state.now() / 1000 / 30- // Imported/synced secrets may not decode to a key; show placeholder, not a crash.- val currentCode = remember(secret, timeStep) {- tryOrDefault("----") { TOTP.generate(secret, timeStep * 30) }- }- val secondsRemaining = ((30000 - state.now() % 30000) / 1000).toInt()-- Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {- Column {- Text(currentCode, style = MaterialTheme.typography.displayMedium)- Spacer(Modifier.height(4.dp))- Text(stringResource(R.string.totp_refreshes_in, secondsRemaining), style = MaterialTheme.typography.bodySmall)- }-- // Circular progress showing proportion of time remaining- Box(contentAlignment = Alignment.Center) {- CircularProgressIndicator(- { (30000L - state.now() % 30000L) / 30000f },- Modifier.size(56.dp),- )- IconButton({- actions.copyToClipboard("totp", currentCode, "TOTP copied")- }) {- IconCopy()- }- }- }- }- }- }+ PasswordTotpCard(+ password = password,+ now = state.now,+ onCopy = { code -> actions.copyToClipboard("totp", code, "TOTP copied") },+ ) } // Passkeys merged into this entry
passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordTotpCard.kt
diff --git a/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordTotpCard.kt b/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordTotpCard.ktnew file mode 100644index 0000000000..7f2374d5cf--- /dev/null+++ b/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordTotpCard.kt@@ -0,0 +1,72 @@+package com.vayunmathur.passwords.ui++import androidx.compose.foundation.layout.Arrangement+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.size+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.CircularProgressIndicator+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconCopy+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.util.tryOrDefault+import com.vayunmathur.passwords.R+import com.vayunmathur.passwords.data.Password+import com.vayunmathur.passwords.domain.TOTP++/** TOTP card for the password detail screen: generated code with a countdown ring. */+@Composable+fun PasswordTotpCard(password: Password, now: () -> Long, onCopy: (String) -> Unit) {+ Card(shape = RoundedCornerShape(8.dp), modifier = Modifier.fillMaxWidth()) {+ Column(Modifier.padding(12.dp)) {+ Text(stringResource(R.string.section_totp), style = MaterialTheme.typography.titleMedium)+ Spacer(Modifier.height(8.dp))++ val secret = password.totpSecret+ if (secret.isNullOrBlank()) {+ Text(stringResource(R.string.totp_not_configured))+ } else {+ val timeStep = now() / 1000 / 30+ // Imported/synced secrets may not decode to a key; show placeholder, not a crash.+ val currentCode = remember(secret, timeStep) {+ tryOrDefault("----") { TOTP.generate(secret, timeStep * 30) }+ }+ val secondsRemaining = ((30000 - now() % 30000) / 1000).toInt()++ Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {+ Column {+ Text(currentCode, style = MaterialTheme.typography.displayMedium)+ Spacer(Modifier.height(4.dp))+ Text(stringResource(R.string.totp_refreshes_in, secondsRemaining), style = MaterialTheme.typography.bodySmall)+ }++ // Circular progress showing proportion of time remaining+ Box(contentAlignment = Alignment.Center) {+ CircularProgressIndicator(+ { (30000L - now() % 30000L) / 30000f },+ Modifier.size(56.dp),+ )+ IconButton({+ onCopy(currentCode)+ }) {+ IconCopy()+ }+ }+ }+ }+ }+ }+}