diff options
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt | 53 | ||||
-rw-r--r-- | app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt | 21 |
2 files changed, 72 insertions, 2 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt new file mode 100644 index 00000000..fd2369e0 --- /dev/null +++ b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt @@ -0,0 +1,53 @@ +package app.passwordstore.ui.pgp + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import app.passwordstore.crypto.GpgIdentifier + +@Composable +fun KeyList( + identifiers: List<GpgIdentifier>, + onItemClick: (identifier: GpgIdentifier) -> Unit, + modifier: Modifier = Modifier, +) { + LazyColumn(modifier = modifier) { + items(identifiers) { identifier -> + KeyItem(identifier = identifier, modifier = Modifier.clickable { onItemClick(identifier) }) + } + } +} + +@Composable +private fun KeyItem( + identifier: GpgIdentifier, + modifier: Modifier = Modifier, +) { + val label = + when (identifier) { + is GpgIdentifier.KeyId -> identifier.id.toString() + is GpgIdentifier.UserId -> identifier.email + } + Box(modifier = modifier.padding(16.dp).fillMaxWidth()) { Text(text = label) } +} + +@Preview +@Composable +private fun KeyListPreview() { + KeyList( + identifiers = + listOfNotNull( + GpgIdentifier.fromString("john.doe@example.com"), + GpgIdentifier.fromString("0xB950AE2813841585") + ), + onItemClick = {} + ) +} diff --git a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt index 3cce4060..4394cff6 100644 --- a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt @@ -6,10 +6,17 @@ import androidx.activity.compose.setContent import androidx.activity.viewModels import androidx.compose.foundation.layout.padding import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import app.passwordstore.R +import app.passwordstore.ui.APSAppBar import app.passwordstore.ui.compose.theme.APSTheme +import app.passwordstore.ui.compose.theme.decideColorScheme import app.passwordstore.util.viewmodel.PGPKeyListViewModel import dagger.hilt.android.AndroidEntryPoint @@ -22,8 +29,18 @@ class PGPKeyListActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { - APSTheme { - Scaffold { paddingValues -> + val context = LocalContext.current + APSTheme(colors = decideColorScheme(context)) { + Scaffold( + topBar = { + APSAppBar( + title = stringResource(R.string.activity_label_pgp_key_manager), + navigationIcon = painterResource(R.drawable.ic_arrow_back_black_24dp), + onNavigationIconClick = { finish() }, + backgroundColor = MaterialTheme.colorScheme.surface, + ) + }, + ) { paddingValues -> PGPKeyList(viewModel = viewModel, modifier = Modifier.padding(paddingValues)) } } |