From 9c5e9c8e4381aaa2886d0ad03070b2a57a937cce Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 23 Jul 2022 19:15:36 +0530 Subject: Improvements to key list activity (#2030) --- app/build.gradle.kts | 1 + .../java/app/passwordstore/ui/pgp/PGPKeyList.kt | 53 ++++++++++++++++++++++ .../app/passwordstore/ui/pgp/PGPKeyListActivity.kt | 21 ++++++++- .../main/res/drawable/ic_arrow_back_black_24dp.xml | 15 ++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt create mode 100644 app/src/main/res/drawable/ic_arrow_back_black_24dp.xml (limited to 'app') diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8d0bc6f6..32291d33 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -76,6 +76,7 @@ dependencies { implementation(libs.androidx.recyclerviewSelection) implementation(libs.androidx.security) implementation(libs.androidx.swiperefreshlayout) + implementation(libs.compose.ui.tooling) implementation(libs.dagger.hilt.android) implementation(libs.kotlin.coroutines.android) 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, + 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)) } } diff --git a/app/src/main/res/drawable/ic_arrow_back_black_24dp.xml b/app/src/main/res/drawable/ic_arrow_back_black_24dp.xml new file mode 100644 index 00000000..6cf467d6 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_back_black_24dp.xml @@ -0,0 +1,15 @@ + + + + + -- cgit v1.2.3