Inline putPasswdToArchivePasswds

This commit is contained in:
tarsin committed 2023-06-01 21:08:26 +08:00
1 parent 9f1ec2be7e
commit a2f0b4a64f
2 files changed
+5 -10

No files matched your search

@@ -107,7 +107,6 @@ object Settings : DefaultPreferences() {
private const val KEY_FAV_COUNT_7 = "fav_count_7"
private const val KEY_FAV_COUNT_8 = "fav_count_8"
private const val KEY_FAV_COUNT_9 = "fav_count_9"
private const val KEY_ARCHIVE_PASSWDS = "archive_passwds"
private lateinit var sSettingsPre: SharedPreferences
fun initialize() {
@@ -275,16 +274,12 @@ object Settings : DefaultPreferences() {
.apply()
}
var archivePasswds by stringSetOrNullPref(KEY_ARCHIVE_PASSWDS)
fun putPasswdToArchivePasswds(value: String) {
archivePasswds = archivePasswds?.toMutableSet()?.apply { add(value) } ?: setOf(value)
}
private val _listThumbSize by intPref(KEY_LIST_THUMB_SIZE, 40)
val listThumbSize: Int
get() = 3 * _listThumbSize
var archivePasswds by stringSetOrNullPref("archive_passwds")
val downloadDelay by intFromStrPref("download_delay", 0)
var gallerySite by intFromStrPref(KEY_GALLERY_SITE, 0)
val multiThreadDownload by intFromStrPref("download_thread", 3)
@@ -20,7 +20,7 @@ import android.graphics.ImageDecoder
import android.net.Uri
import android.os.ParcelFileDescriptor
import android.util.Log
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.Settings.archivePasswds
import com.hippo.ehviewer.image.Image
import com.hippo.ehviewer.image.rewriteGifSource
import com.hippo.ehviewer.yorozuya.FileUtils
@@ -51,13 +51,13 @@ class ArchivePageLoader(context: Context, private val uri: Uri, passwdFlow: Flow
return@launch
}
if (needPassword()) {
Settings.archivePasswds?.forEach {
archivePasswds?.forEach {
it ?: return@forEach
if (providePassword(it)) return@launch
}
passwdFlow.collect {
if (providePassword(it)) {
Settings.putPasswdToArchivePasswds(it)
archivePasswds = archivePasswds?.toMutableSet()?.apply { add(it) } ?: setOf(it)
currentCoroutineContext().cancel()
}
}