aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-07-23 19:15:36 +0530
committerGitHub <noreply@github.com>2022-07-23 13:45:36 +0000
commit9c5e9c8e4381aaa2886d0ad03070b2a57a937cce (patch)
tree5c1d13d4879c6efe7082b8a987d34aec38a64e10 /app
parent6d0bff144c35c9f2c73f34065e972b3f48a34241 (diff)
Improvements to key list activity (#2030)
Diffstat (limited to 'app')
-rw-r--r--app/build.gradle.kts1
-rw-r--r--app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt53
-rw-r--r--app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt21
-rw-r--r--app/src/main/res/drawable/ic_arrow_back_black_24dp.xml15
4 files changed, 88 insertions, 2 deletions
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<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))
}
}
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 @@
+<!--
+ ~ Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
+ ~ SPDX-License-Identifier: GPL-3.0-only
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="?attr/colorControlNormal"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
+</vector>