From e875047899af00f47eec32d5415ae5f1a607947e Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 15 Jun 2023 16:39:24 +0530 Subject: feat: adopt Kotlin 1.9 Enum entries feature --- app/src/main/java/app/passwordstore/Application.kt | 3 ++- .../ui/dialogs/PasswordGeneratorDialogFragment.kt | 8 ++++---- app/src/main/java/app/passwordstore/util/features/Feature.kt | 5 ----- .../main/java/app/passwordstore/util/settings/GitSettings.kt | 10 ++++------ 4 files changed, 10 insertions(+), 16 deletions(-) (limited to 'app') 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, 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") } } -- cgit v1.2.3