aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2023-06-15 16:39:24 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2023-06-15 16:53:21 +0530
commite875047899af00f47eec32d5415ae5f1a607947e (patch)
tree9a44c0f44a3f4b565372f78f5d88b26ba0d91452 /app/src/main
parent5dac84c3c882ee42bc541042684de18d7166fdd3 (diff)
feat: adopt Kotlin 1.9 Enum entries feature
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/app/passwordstore/Application.kt3
-rw-r--r--app/src/main/java/app/passwordstore/ui/dialogs/PasswordGeneratorDialogFragment.kt8
-rw-r--r--app/src/main/java/app/passwordstore/util/features/Feature.kt5
-rw-r--r--app/src/main/java/app/passwordstore/util/settings/GitSettings.kt10
4 files changed, 10 insertions, 16 deletions
diff --git a/app/src/main/java/app/passwordstore/Application.kt b/app/src/main/java/app/passwordstore/Application.kt
index 2f1aca88..45bdc5e6 100644
--- a/app/src/main/java/app/passwordstore/Application.kt
+++ b/app/src/main/java/app/passwordstore/Application.kt
@@ -33,6 +33,7 @@ import logcat.LogPriority.VERBOSE
import logcat.LogcatLogger
import logcat.logcat
+@OptIn(ExperimentalStdlibApi::class)
@Suppress("Unused")
@HiltAndroidApp
class Application : android.app.Application(), SharedPreferences.OnSharedPreferenceChangeListener {
@@ -68,7 +69,7 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
Sentry.configureScope { scope ->
val user = User()
user.data =
- Feature.VALUES.associate { feature ->
+ Feature.entries.associate { feature ->
"features.${feature.configKey}" to features.isEnabled(feature).toString()
}
scope.user = user
diff --git a/app/src/main/java/app/passwordstore/ui/dialogs/PasswordGeneratorDialogFragment.kt b/app/src/main/java/app/passwordstore/ui/dialogs/PasswordGeneratorDialogFragment.kt
index 06ce2d92..1130ffd1 100644
--- a/app/src/main/java/app/passwordstore/ui/dialogs/PasswordGeneratorDialogFragment.kt
+++ b/app/src/main/java/app/passwordstore/ui/dialogs/PasswordGeneratorDialogFragment.kt
@@ -37,6 +37,7 @@ import kotlinx.coroutines.flow.onEach
import reactivecircus.flowbinding.android.widget.afterTextChanges
import reactivecircus.flowbinding.android.widget.checkedChanges
+@OptIn(ExperimentalStdlibApi::class)
class PasswordGeneratorDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
@@ -138,10 +139,9 @@ class PasswordGeneratorDialogFragment : DialogFragment() {
*/
private fun setPrefs(ctx: Context, options: List<PasswordOption>, targetLength: Int): Boolean {
ctx.getSharedPreferences("PasswordGenerator", Context.MODE_PRIVATE).edit {
- for (possibleOption in PasswordOption.values()) putBoolean(
- possibleOption.key,
- possibleOption in options
- )
+ for (possibleOption in PasswordOption.entries) {
+ putBoolean(possibleOption.key, possibleOption in options)
+ }
putInt("length", targetLength)
}
return true
diff --git a/app/src/main/java/app/passwordstore/util/features/Feature.kt b/app/src/main/java/app/passwordstore/util/features/Feature.kt
index 55e4eaeb..44af5b70 100644
--- a/app/src/main/java/app/passwordstore/util/features/Feature.kt
+++ b/app/src/main/java/app/passwordstore/util/features/Feature.kt
@@ -25,9 +25,4 @@ enum class Feature(
/** Opt into a cache layer for PGP passphrases. */
EnablePGPPassphraseCache(false, "enable_gpg_passphrase_cache"),
- ;
-
- companion object {
- @JvmField val VALUES = values()
- }
}
diff --git a/app/src/main/java/app/passwordstore/util/settings/GitSettings.kt b/app/src/main/java/app/passwordstore/util/settings/GitSettings.kt
index 00ace530..e01e6317 100644
--- a/app/src/main/java/app/passwordstore/util/settings/GitSettings.kt
+++ b/app/src/main/java/app/passwordstore/util/settings/GitSettings.kt
@@ -26,10 +26,9 @@ enum class Protocol(val pref: String) {
companion object {
- private val map = values().associateBy(Protocol::pref)
-
+ @OptIn(ExperimentalStdlibApi::class)
fun fromString(type: String?): Protocol {
- return map[type ?: return Ssh]
+ return entries.associateBy(Protocol::pref)[type ?: return Ssh]
?: throw IllegalArgumentException("$type is not a valid Protocol")
}
}
@@ -43,10 +42,9 @@ enum class AuthMode(val pref: String) {
companion object {
- private val map = values().associateBy(AuthMode::pref)
-
+ @OptIn(ExperimentalStdlibApi::class)
fun fromString(type: String?): AuthMode {
- return map[type ?: return SshKey]
+ return entries.associateBy(AuthMode::pref)[type ?: return SshKey]
?: throw IllegalArgumentException("$type is not a valid AuthMode")
}
}