feat: adopt Kotlin 1.9 Enum entries feature

This commit is contained in:
Harsh Shandilya 2023-06-15 16:39:24 +05:30
parent 5dac84c3c8
commit e875047899
No known key found for this signature in database
6 changed files with 13 additions and 18 deletions

View file

@ -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

View file

@ -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

View file

@ -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()
}
}

View file

@ -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")
}
}

View file

@ -26,7 +26,7 @@ class KotlinCommonPlugin : Plugin<Project> {
withType<KotlinCompile>().configureEach task@{
compilerOptions {
allWarningsAsErrors.set(true)
languageVersion.set(KotlinVersion.KOTLIN_1_8)
languageVersion.set(KotlinVersion.KOTLIN_1_9)
freeCompilerArgs.addAll(ADDITIONAL_COMPILER_ARGS)
if (!this@task.name.contains("test", ignoreCase = true) && !isAppModule) {
freeCompilerArgs.add("-Xexplicit-api=strict")

View file

@ -7,6 +7,7 @@ package app.passwordstore.passgen.random
import app.passwordstore.passgen.random.util.clearFlag
import app.passwordstore.passgen.random.util.hasFlag
@OptIn(ExperimentalStdlibApi::class)
public object PasswordGenerator {
public const val DEFAULT_LENGTH: Int = 16
@ -39,7 +40,7 @@ public object PasswordGenerator {
var phonemes = true
var pwgenFlags = DIGITS or UPPERS or LOWERS
for (option in PasswordOption.values()) {
for (option in PasswordOption.entries) {
if (option in passwordOptions) {
when (option) {
PasswordOption.NoDigits -> pwgenFlags = pwgenFlags.clearFlag(DIGITS)