summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt44
-rw-r--r--app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt9
-rw-r--r--app/src/main/java/app/passwordstore/util/extensions/AndroidExtensions.kt3
-rw-r--r--app/src/main/java/app/passwordstore/util/viewmodel/PGPKeyListViewModel.kt46
4 files changed, 101 insertions, 1 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt
new file mode 100644
index 00000000..3cce4060
--- /dev/null
+++ b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt
@@ -0,0 +1,44 @@
+package app.passwordstore.ui.pgp
+
+import android.os.Bundle
+import androidx.activity.ComponentActivity
+import androidx.activity.compose.setContent
+import androidx.activity.viewModels
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.Scaffold
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import app.passwordstore.ui.compose.theme.APSTheme
+import app.passwordstore.util.viewmodel.PGPKeyListViewModel
+import dagger.hilt.android.AndroidEntryPoint
+
+@AndroidEntryPoint
+@OptIn(ExperimentalMaterial3Api::class)
+class PGPKeyListActivity : ComponentActivity() {
+
+ private val viewModel: PGPKeyListViewModel by viewModels()
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContent {
+ APSTheme {
+ Scaffold { paddingValues ->
+ PGPKeyList(viewModel = viewModel, modifier = Modifier.padding(paddingValues))
+ }
+ }
+ }
+ }
+}
+
+@Composable
+fun PGPKeyList(
+ viewModel: PGPKeyListViewModel,
+ modifier: Modifier = Modifier,
+) {
+ KeyList(
+ identifiers = viewModel.keys,
+ onItemClick = viewModel::deleteKey,
+ modifier = modifier,
+ )
+}
diff --git a/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt b/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
index 85e8667b..d44fd365 100644
--- a/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
+++ b/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
@@ -7,6 +7,7 @@ package app.passwordstore.ui.settings
import androidx.fragment.app.FragmentActivity
import app.passwordstore.ui.pgp.PGPKeyImportActivity
+import app.passwordstore.ui.pgp.PGPKeyListActivity
import app.passwordstore.util.extensions.launchActivity
import de.Maxr1998.modernpreferences.PreferenceScreen
import de.Maxr1998.modernpreferences.helpers.onClick
@@ -24,6 +25,14 @@ class PGPSettings(private val activity: FragmentActivity) : SettingsProvider {
false
}
}
+ pref("__") {
+ title = "Key manager"
+ persistent = false
+ onClick {
+ activity.launchActivity(PGPKeyListActivity::class.java)
+ false
+ }
+ }
}
}
}
diff --git a/app/src/main/java/app/passwordstore/util/extensions/AndroidExtensions.kt b/app/src/main/java/app/passwordstore/util/extensions/AndroidExtensions.kt
index 69811e05..ebb24a78 100644
--- a/app/src/main/java/app/passwordstore/util/extensions/AndroidExtensions.kt
+++ b/app/src/main/java/app/passwordstore/util/extensions/AndroidExtensions.kt
@@ -15,6 +15,7 @@ import android.util.Base64
import android.util.TypedValue
import android.view.View
import android.view.autofill.AutofillManager
+import androidx.activity.ComponentActivity
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
@@ -120,7 +121,7 @@ fun FragmentActivity.snackbar(
}
/** Launch an activity denoted by [clazz]. */
-fun <T : FragmentActivity> FragmentActivity.launchActivity(clazz: Class<T>) {
+fun <T : ComponentActivity> ComponentActivity.launchActivity(clazz: Class<T>) {
startActivity(Intent(this, clazz))
}
diff --git a/app/src/main/java/app/passwordstore/util/viewmodel/PGPKeyListViewModel.kt b/app/src/main/java/app/passwordstore/util/viewmodel/PGPKeyListViewModel.kt
new file mode 100644
index 00000000..93e450b4
--- /dev/null
+++ b/app/src/main/java/app/passwordstore/util/viewmodel/PGPKeyListViewModel.kt
@@ -0,0 +1,46 @@
+package app.passwordstore.util.viewmodel
+
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.setValue
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import app.passwordstore.crypto.GpgIdentifier
+import app.passwordstore.crypto.KeyUtils
+import app.passwordstore.crypto.PGPKeyManager
+import com.github.michaelbull.result.Err
+import com.github.michaelbull.result.Ok
+import com.github.michaelbull.result.map
+import dagger.hilt.android.lifecycle.HiltViewModel
+import javax.inject.Inject
+import kotlinx.coroutines.launch
+
+@HiltViewModel
+class PGPKeyListViewModel @Inject constructor(private val keyManager: PGPKeyManager) : ViewModel() {
+ var keys: List<GpgIdentifier> by mutableStateOf(emptyList())
+
+ init {
+ getKeys()
+ }
+
+ private fun getKeys() {
+ viewModelScope.launch {
+ when (
+ val result =
+ keyManager.getAllKeys().map { keys ->
+ keys.mapNotNull { key -> KeyUtils.tryGetEmail(key) }
+ }
+ ) {
+ is Ok -> keys = result.value
+ is Err -> TODO()
+ }
+ }
+ }
+
+ fun deleteKey(identifier: GpgIdentifier) {
+ viewModelScope.launch {
+ keyManager.removeKey(identifier)
+ getKeys()
+ }
+ }
+}