Add KeyList composable

This commit is contained in:
Harsh Shandilya 2022-07-18 22:26:32 +05:30
parent c0f04bec77
commit b92a2ca18b
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 40 additions and 1 deletions

View file

@ -18,7 +18,7 @@ android {
dependencies { dependencies {
api(libs.compose.foundation.core) api(libs.compose.foundation.core)
api(libs.compose.foundation.layout) api(libs.compose.foundation.layout)
api(libs.compose.material)
api(libs.compose.material3) api(libs.compose.material3)
api(libs.compose.ui.core) api(libs.compose.ui.core)
implementation(projects.cryptoPgpainless)
} }

View file

@ -0,0 +1,39 @@
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.unit.dp
import app.passwordstore.crypto.GpgIdentifier
@Composable
public 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) }
}