Cleanup archivePasswds pref

This commit is contained in:
tarsin committed 2023-06-01 18:48:33 +08:00
1 parent 2fed610470
commit 1a01caee2c
2 files changed
+3 -15

No files matched your search

@@ -178,18 +178,6 @@ object Settings : DefaultPreferences() {
sSettingsPre.edit().putString(key, value).apply()
}
private fun getStringSet(key: String): MutableSet<String>? {
return sSettingsPre.getStringSet(key, null)
}
private fun putStringToStringSet(key: String, value: String) {
var set = getStringSet(key)
if (set == null) {
set = mutableSetOf(value)
} else if (set.contains(value)) return else set.add(value)
sSettingsPre.edit().putStringSet(key, set).apply()
}
private fun getIntFromStr(key: String, defValue: Int): Int {
return try {
NumberUtils.parseIntSafely(
@@ -337,11 +325,10 @@ object Settings : DefaultPreferences() {
val readCacheSize: Int
get() = getIntFromStr(KEY_READ_CACHE_SIZE, DEFAULT_READ_CACHE_SIZE)
val archivePasswds: Set<String>?
get() = getStringSet(KEY_ARCHIVE_PASSWDS)
var archivePasswds by stringSetOrNullPref(KEY_ARCHIVE_PASSWDS)
fun putPasswdToArchivePasswds(value: String) {
putStringToStringSet(KEY_ARCHIVE_PASSWDS, value)
archivePasswds = archivePasswds?.toMutableSet()?.apply { add(value) } ?: setOf(value)
}
private val _listThumbSize by intPref(KEY_LIST_THUMB_SIZE, 40)
@@ -52,6 +52,7 @@ class ArchivePageLoader(context: Context, private val uri: Uri, passwdFlow: Flow
}
if (needPassword()) {
Settings.archivePasswds?.forEach {
it ?: return@forEach
if (providePassword(it)) return@launch
}
passwdFlow.collect {