Convert EH settings to FlowPrefrences

This commit is contained in:
Jobobby04 2020-05-10 19:22:10 -04:00
parent 60a0303d7f
commit 6e1da22353
22 changed files with 123 additions and 146 deletions

View File

@ -7,12 +7,16 @@ import com.google.gson.Gson
import com.jakewharton.disklrucache.DiskLruCache
import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.util.storage.DiskUtil
import eu.kanade.tachiyomi.util.storage.saveTo
import java.io.File
import java.io.IOException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import okhttp3.Response
import okio.buffer
import okio.sink
@ -41,6 +45,8 @@ class ChapterCache(private val context: Context) {
const val PARAMETER_VALUE_COUNT = 1
}
private val scope = CoroutineScope(Job() + Dispatchers.Main)
/** Google Json class used for parsing JSON files. */
private val gson: Gson by injectLazy()
@ -50,15 +56,17 @@ class ChapterCache(private val context: Context) {
/** Cache class used for cache management. */
// --> EH
private var diskCache = setupDiskCache(prefs.eh_cacheSize().getOrDefault().toLong())
private var diskCache = setupDiskCache(prefs.eh_cacheSize().get().toLong())
init {
prefs.eh_cacheSize().asObservable().skip(1).subscribe {
// Save old cache for destruction later
val oldCache = diskCache
diskCache = setupDiskCache(it.toLong())
oldCache.close()
}
prefs.eh_cacheSize().asFlow()
.onEach {
// Save old cache for destruction later
val oldCache = diskCache
diskCache = setupDiskCache(it.toLong())
oldCache.close()
}
.launchIn(scope)
}
// <-- EH

View File

@ -240,16 +240,16 @@ class PreferencesHelper(val context: Context) {
fun migrationSources() = flowPrefs.getString("migrate_sources", "")
fun smartMigration() = rxPrefs.getBoolean("smart_migrate", false)
fun smartMigration() = flowPrefs.getBoolean("smart_migrate", false)
fun useSourceWithMost() = rxPrefs.getBoolean("use_source_with_most", false)
fun useSourceWithMost() = flowPrefs.getBoolean("use_source_with_most", false)
fun skipPreMigration() = flowPrefs.getBoolean(Keys.skipPreMigration, false)
fun upgradeFilters() {
val filterDl = rxPrefs.getBoolean(Keys.filterDownloaded, false).getOrDefault()
val filterUn = rxPrefs.getBoolean(Keys.filterUnread, false).getOrDefault()
val filterCm = rxPrefs.getBoolean(Keys.filterCompleted, false).getOrDefault()
val filterDl = flowPrefs.getBoolean(Keys.filterDownloaded, false).get()
val filterUn = flowPrefs.getBoolean(Keys.filterUnread, false).get()
val filterCm = flowPrefs.getBoolean(Keys.filterCompleted, false).get()
filterDownloaded().set(if (filterDl) 1 else 0)
filterUnread().set(if (filterUn) 1 else 0)
filterCompleted().set(if (filterCm) 1 else 0)
@ -258,91 +258,80 @@ class PreferencesHelper(val context: Context) {
// <--
// --> EH
fun enableExhentai() = rxPrefs.getBoolean(Keys.eh_enableExHentai, false)
fun enableExhentai() = flowPrefs.getBoolean(Keys.eh_enableExHentai, false)
fun secureEXH() = rxPrefs.getBoolean("secure_exh", true)
fun secureEXH() = flowPrefs.getBoolean("secure_exh", true)
fun imageQuality() = rxPrefs.getString("ehentai_quality", "auto")
fun imageQuality() = flowPrefs.getString("ehentai_quality", "auto")
fun useHentaiAtHome() = rxPrefs.getBoolean("enable_hah", true)
fun useHentaiAtHome() = flowPrefs.getBoolean("enable_hah", true)
fun useJapaneseTitle() = rxPrefs.getBoolean("use_jp_title", false)
fun useJapaneseTitle() = flowPrefs.getBoolean("use_jp_title", false)
fun eh_useOriginalImages() = rxPrefs.getBoolean(Keys.eh_useOrigImages, false)
fun eh_useOriginalImages() = flowPrefs.getBoolean(Keys.eh_useOrigImages, false)
fun ehSearchSize() = rxPrefs.getString("ex_search_size", "rc_0")
fun ehSearchSize() = flowPrefs.getString("ex_search_size", "rc_0")
fun thumbnailRows() = rxPrefs.getString("ex_thumb_rows", "tr_2")
fun thumbnailRows() = flowPrefs.getString("ex_thumb_rows", "tr_2")
fun hasPerformedURLMigration() = rxPrefs.getBoolean("performed_url_migration", false)
fun hasPerformedURLMigration() = flowPrefs.getBoolean("performed_url_migration", false)
// EH Cookies
fun memberIdVal() = rxPrefs.getString("eh_ipb_member_id", "")
fun memberIdVal() = flowPrefs.getString("eh_ipb_member_id", "")
fun passHashVal() = rxPrefs.getString("eh_ipb_pass_hash", "")
fun igneousVal() = rxPrefs.getString("eh_igneous", "")
fun eh_ehSettingsProfile() = rxPrefs.getInteger(Keys.eh_ehSettingsProfile, -1)
fun eh_exhSettingsProfile() = rxPrefs.getInteger(Keys.eh_exhSettingsProfile, -1)
fun eh_settingsKey() = rxPrefs.getString(Keys.eh_settingsKey, "")
fun eh_sessionCookie() = rxPrefs.getString(Keys.eh_sessionCookie, "")
fun eh_hathPerksCookies() = rxPrefs.getString(Keys.eh_hathPerksCookie, "")
fun passHashVal() = flowPrefs.getString("eh_ipb_pass_hash", "")
fun igneousVal() = flowPrefs.getString("eh_igneous", "")
fun eh_ehSettingsProfile() = flowPrefs.getInt(Keys.eh_ehSettingsProfile, -1)
fun eh_exhSettingsProfile() = flowPrefs.getInt(Keys.eh_exhSettingsProfile, -1)
fun eh_settingsKey() = flowPrefs.getString(Keys.eh_settingsKey, "")
fun eh_sessionCookie() = flowPrefs.getString(Keys.eh_sessionCookie, "")
fun eh_hathPerksCookies() = flowPrefs.getString(Keys.eh_hathPerksCookie, "")
// Lock
fun eh_lockHash() = rxPrefs.getString(Keys.eh_lock_hash, null)
fun eh_lockSalt() = rxPrefs.getString(Keys.eh_lock_salt, null)
fun eh_lockLength() = rxPrefs.getInteger(Keys.eh_lock_length, -1)
fun eh_lockUseFingerprint() = rxPrefs.getBoolean(Keys.eh_lock_finger, false)
fun eh_lockManually() = rxPrefs.getBoolean(Keys.eh_lock_manually, false)
fun eh_nh_useHighQualityThumbs() = rxPrefs.getBoolean(Keys.eh_nh_useHighQualityThumbs, false)
fun eh_nh_useHighQualityThumbs() = flowPrefs.getBoolean(Keys.eh_nh_useHighQualityThumbs, false)
fun eh_showSyncIntro() = flowPrefs.getBoolean(Keys.eh_showSyncIntro, true)
fun eh_readOnlySync() = rxPrefs.getBoolean(Keys.eh_readOnlySync, false)
fun eh_readOnlySync() = flowPrefs.getBoolean(Keys.eh_readOnlySync, false)
fun eh_lenientSync() = rxPrefs.getBoolean(Keys.eh_lenientSync, false)
fun eh_lenientSync() = flowPrefs.getBoolean(Keys.eh_lenientSync, false)
fun eh_ts_aspNetCookie() = rxPrefs.getString(Keys.eh_ts_aspNetCookie, "")
fun eh_ts_aspNetCookie() = flowPrefs.getString(Keys.eh_ts_aspNetCookie, "")
fun eh_showSettingsUploadWarning() = flowPrefs.getBoolean(Keys.eh_showSettingsUploadWarning, true)
fun eh_expandFilters() = rxPrefs.getBoolean(Keys.eh_expandFilters, false)
fun eh_expandFilters() = flowPrefs.getBoolean(Keys.eh_expandFilters, false)
fun eh_readerThreads() = rxPrefs.getInteger(Keys.eh_readerThreads, 2)
fun eh_readerThreads() = flowPrefs.getInt(Keys.eh_readerThreads, 2)
fun eh_readerInstantRetry() = rxPrefs.getBoolean(Keys.eh_readerInstantRetry, true)
fun eh_readerInstantRetry() = flowPrefs.getBoolean(Keys.eh_readerInstantRetry, true)
fun eh_utilAutoscrollInterval() = flowPrefs.getFloat(Keys.eh_utilAutoscrollInterval, 3f)
fun eh_cacheSize() = rxPrefs.getString(Keys.eh_cacheSize, "75")
fun eh_cacheSize() = flowPrefs.getString(Keys.eh_cacheSize, "75")
fun eh_preserveReadingPosition() = flowPrefs.getBoolean(Keys.eh_preserveReadingPosition, false)
fun eh_autoSolveCaptchas() = rxPrefs.getBoolean(Keys.eh_autoSolveCaptchas, false)
fun eh_autoSolveCaptchas() = flowPrefs.getBoolean(Keys.eh_autoSolveCaptchas, false)
fun eh_delegateSources() = rxPrefs.getBoolean(Keys.eh_delegateSources, true)
fun eh_delegateSources() = flowPrefs.getBoolean(Keys.eh_delegateSources, true)
fun eh_lastVersionCode() = rxPrefs.getInteger("eh_last_version_code", 0)
fun eh_lastVersionCode() = flowPrefs.getInt("eh_last_version_code", 0)
fun eh_savedSearches() = rxPrefs.getStringSet("eh_saved_searches", emptySet())
fun eh_savedSearches() = flowPrefs.getStringSet("eh_saved_searches", emptySet())
fun eh_logLevel() = rxPrefs.getInteger(Keys.eh_logLevel, 0)
fun eh_logLevel() = flowPrefs.getInt(Keys.eh_logLevel, 0)
fun eh_enableSourceBlacklist() = flowPrefs.getBoolean(Keys.eh_enableSourceBlacklist, true)
fun eh_autoUpdateFrequency() = rxPrefs.getInteger(Keys.eh_autoUpdateFrequency, 1)
fun eh_autoUpdateFrequency() = flowPrefs.getInt(Keys.eh_autoUpdateFrequency, 1)
fun eh_autoUpdateRequirements() = prefs.getStringSet(Keys.eh_autoUpdateRestrictions, emptySet())
fun eh_autoUpdateStats() = rxPrefs.getString(Keys.eh_autoUpdateStats, "")
fun eh_autoUpdateStats() = flowPrefs.getString(Keys.eh_autoUpdateStats, "")
fun eh_aggressivePageLoading() = rxPrefs.getBoolean(Keys.eh_aggressivePageLoading, false)
fun eh_aggressivePageLoading() = flowPrefs.getBoolean(Keys.eh_aggressivePageLoading, false)
fun eh_hl_useHighQualityThumbs() = rxPrefs.getBoolean(Keys.eh_hl_useHighQualityThumbs, false)
fun eh_hl_useHighQualityThumbs() = flowPrefs.getBoolean(Keys.eh_hl_useHighQualityThumbs, false)
fun eh_preload_size() = rxPrefs.getInteger(Keys.eh_preload_size, 4)
fun eh_preload_size() = flowPrefs.getInt(Keys.eh_preload_size, 4)
}

View File

@ -4,7 +4,6 @@ import android.content.Context
import com.elvishew.xlog.XLog
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
@ -28,6 +27,11 @@ import exh.source.BlacklistedSources
import exh.source.DelegatedHttpSource
import exh.source.EnhancedHttpSource
import kotlin.reflect.KClass
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import rx.Observable
import uy.kohesive.injekt.injectLazy
@ -39,22 +43,15 @@ open class SourceManager(private val context: Context) {
private val stubSourcesMap = mutableMapOf<Long, StubSource>()
private val scope = CoroutineScope(Job() + Dispatchers.Main)
init {
createInternalSources().forEach { registerSource(it) }
// Recreate sources when they change
val prefEntries = arrayOf(
prefs.enableExhentai(),
prefs.imageQuality(),
prefs.useHentaiAtHome(),
prefs.useJapaneseTitle(),
prefs.ehSearchSize(),
prefs.thumbnailRows()
).map { it.asObservable() }
Observable.merge(prefEntries).skip(prefEntries.size - 1).subscribe {
prefs.enableExhentai().asFlow().onEach {
createEHSources().forEach { registerSource(it) }
}
}.launchIn(scope)
registerSource(MergedSource())
}
@ -112,7 +109,7 @@ open class SourceManager(private val context: Context) {
val exSrcs = mutableListOf<HttpSource>(
EHentai(EH_SOURCE_ID, false, context)
)
if (prefs.enableExhentai().getOrDefault()) {
if (prefs.enableExhentai().get()) {
exSrcs += EHentai(EXH_SOURCE_ID, true, context)
}
exSrcs += PervEden(PERV_EDEN_EN_SOURCE_ID, PervEdenLang.en)

View File

@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.source.online
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.network.asObservableSuccess
@ -377,7 +376,7 @@ abstract class HttpSource : CatalogueSource {
// EXH -->
private var delegate: DelegatedHttpSource? = null
get() = if (Injekt.get<PreferencesHelper>().eh_delegateSources().getOrDefault()) {
get() = if (Injekt.get<PreferencesHelper>().eh_delegateSources().get()) {
field
} else {
null

View File

@ -14,7 +14,6 @@ import com.google.gson.JsonObject
import com.google.gson.JsonParser
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.model.Filter
@ -73,7 +72,7 @@ class EHentai(
override val metaClass = EHentaiSearchMetadata::class
val schema: String
get() = if (prefs.secureEXH().getOrDefault()) {
get() = if (prefs.secureEXH().get()) {
"https"
} else {
"http"
@ -567,23 +566,23 @@ class EHentai(
fun rawCookies(sp: Int): Map<String, String> {
val cookies: MutableMap<String, String> = mutableMapOf()
if (prefs.enableExhentai().getOrDefault()) {
if (prefs.enableExhentai().get()) {
cookies[LoginController.MEMBER_ID_COOKIE] = prefs.memberIdVal().get()!!
cookies[LoginController.PASS_HASH_COOKIE] = prefs.passHashVal().get()!!
cookies[LoginController.IGNEOUS_COOKIE] = prefs.igneousVal().get()!!
cookies["sp"] = sp.toString()
val sessionKey = prefs.eh_settingsKey().getOrDefault()
val sessionKey = prefs.eh_settingsKey().get()
if (sessionKey != null) {
cookies["sk"] = sessionKey
}
val sessionCookie = prefs.eh_sessionCookie().getOrDefault()
val sessionCookie = prefs.eh_sessionCookie().get()
if (sessionCookie != null) {
cookies["s"] = sessionCookie
}
val hathPerksCookie = prefs.eh_hathPerksCookies().getOrDefault()
val hathPerksCookie = prefs.eh_hathPerksCookies().get()
if (hathPerksCookie != null) {
cookies["hath_perks"] = hathPerksCookie
}
@ -598,7 +597,7 @@ class EHentai(
return cookies
}
fun cookiesHeader(sp: Int = spPref().getOrDefault()) = buildCookies(rawCookies(sp))
fun cookiesHeader(sp: Int = spPref().get()) = buildCookies(rawCookies(sp))
// Headers
override fun headersBuilder() = super.headersBuilder().add("Cookie", cookiesHeader())

View File

@ -7,7 +7,6 @@ import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.string
import com.google.gson.JsonParser
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.model.FilterList
@ -303,7 +302,7 @@ class Hitomi : HttpSource(), LewdSource<HitomiSearchMetadata, Document>, UrlImpo
return SManga.create().apply {
val titleElement = doc.selectFirst("h1")
title = titleElement.text()
thumbnail_url = "https:" + if (prefs.eh_hl_useHighQualityThumbs().getOrDefault()) {
thumbnail_url = "https:" + if (prefs.eh_hl_useHighQualityThumbs().get()) {
doc.selectFirst("img").attr("data-srcset").substringBefore(' ')
} else {
doc.selectFirst("img").attr("data-src")

View File

@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.MangaCategory
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.Filter
@ -413,7 +412,7 @@ open class BrowseSourcePresenter(
// EXH -->
private val filterSerializer = FilterSerializer()
fun saveSearches(searches: List<EXHSavedSearch>) {
val otherSerialized = prefs.eh_savedSearches().getOrDefault().filter {
val otherSerialized = prefs.eh_savedSearches().get().filter {
!it.startsWith("${source.id}:")
}
val newSerialized = searches.map {
@ -427,7 +426,7 @@ open class BrowseSourcePresenter(
}
fun loadSearches(): List<EXHSavedSearch> {
val loaded = prefs.eh_savedSearches().getOrDefault()
val loaded = prefs.eh_savedSearches().get()
return loaded.map {
try {
val id = it.substringBefore(':').toLong()

View File

@ -11,7 +11,6 @@ import eu.davidea.flexibleadapter.items.ISectionable
import eu.davidea.viewholders.ExpandableViewHolder
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.util.view.setVectorCompat
import uy.kohesive.injekt.Injekt
@ -21,7 +20,7 @@ class GroupItem(val filter: Filter.Group<*>) : AbstractExpandableHeaderItem<Grou
init {
// --> EH
isExpanded = Injekt.get<PreferencesHelper>().eh_expandFilters().getOrDefault()
isExpanded = Injekt.get<PreferencesHelper>().eh_expandFilters().get()
// <-- EH
}

View File

@ -19,7 +19,6 @@ import com.google.android.material.behavior.HideBottomViewOnScrollBehavior
import com.google.android.material.tabs.TabLayout
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.databinding.MainActivityBinding
import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
@ -181,7 +180,7 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
initWhenIdle {
// Upload settings
if (preferences.enableExhentai().getOrDefault() &&
if (preferences.enableExhentai().get() &&
preferences.eh_showSettingsUploadWarning().get()
) {
WarnConfigureDialogController.uploadSettings(router)

View File

@ -9,11 +9,10 @@ import android.widget.RadioButton
import android.widget.RadioGroup
import android.widget.Toast
import com.bluelinelabs.conductor.Controller
import com.f2prateek.rx.preferences.Preference
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.tfcporciuncula.flow.Preference
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.ui.migration.MigrationFlags
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.gone
@ -122,7 +121,7 @@ class MigrationBottomSheetDialog(
* Binds a checkbox or switch view with a boolean preference.
*/
private fun CompoundButton.bindToPreference(pref: Preference<Boolean>) {
isChecked = pref.getOrDefault()
isChecked = pref.get()
setOnCheckedChangeListener { _, isChecked -> pref.set(isChecked) }
}
@ -130,7 +129,7 @@ class MigrationBottomSheetDialog(
* Binds a radio group with a boolean preference.
*/
private fun RadioGroup.bindToPreference(pref: Preference<Boolean>) {
(getChildAt(pref.getOrDefault().toInt()) as RadioButton).isChecked = true
(getChildAt(pref.get().toInt()) as RadioButton).isChecked = true
setOnCheckedChangeListener { _, value ->
val index = indexOfChild(findViewById(value))
pref.set(index == 1)

View File

@ -19,7 +19,6 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.databinding.MigrationListControllerBinding
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.Source
@ -125,8 +124,8 @@ class MigrationListController(bundle: Bundle? = null) :
}
private suspend fun runMigrations(mangas: List<MigratingManga>) {
val useSourceWithMost = preferences.useSourceWithMost().getOrDefault()
val useSmartSearch = preferences.smartMigration().getOrDefault()
val useSourceWithMost = preferences.useSourceWithMost().get()
val useSmartSearch = preferences.smartMigration().get()
val sources = preferences.migrationSources().get().split("/").mapNotNull {
val value = it.toLongOrNull() ?: return

View File

@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.reader.loader
import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
@ -46,11 +45,11 @@ class HttpPageLoader(
*/
private val subscriptions = CompositeSubscription()
private val preloadSize = prefs.eh_preload_size().getOrDefault()
private val preloadSize = prefs.eh_preload_size().get()
init {
// EXH -->
repeat(prefs.eh_readerThreads().getOrDefault()) {
repeat(prefs.eh_readerThreads().get()) {
// EXH <--
subscriptions += Observable.defer { Observable.just(queue.take().page) }
.filter { it.status == Page.QUEUE }
@ -107,7 +106,7 @@ class HttpPageLoader(
// Don't trust sources and use our own indexing
ReaderPage(index, page.url, page.imageUrl)
}
if (prefs.eh_aggressivePageLoading().getOrDefault()) {
if (prefs.eh_aggressivePageLoading().get()) {
rp.mapNotNull {
if (it.status == Page.QUEUE) {
PriorityPage(it, 0)
@ -189,7 +188,7 @@ class HttpPageLoader(
page.imageUrl = null
}
if (prefs.eh_readerInstantRetry().getOrDefault()) // EXH <--
if (prefs.eh_readerInstantRetry().get()) // EXH <--
{
boostPage(page)
} else {

View File

@ -6,16 +6,15 @@ import androidx.preference.PreferenceScreen
import com.afollestad.materialdialogs.MaterialDialog
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.f2prateek.rx.preferences.Preference
import com.github.salomonbrys.kotson.fromJson
import com.google.gson.Gson
import com.kizitonwose.time.Interval
import com.kizitonwose.time.days
import com.kizitonwose.time.hours
import com.tfcporciuncula.flow.Preference
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.util.preference.defaultValue
import eu.kanade.tachiyomi.util.preference.entriesRes
import eu.kanade.tachiyomi.util.preference.intListPreference
@ -46,10 +45,11 @@ import humanize.Humanize
import java.util.Date
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import uy.kohesive.injekt.injectLazy
/**
@ -62,14 +62,13 @@ class SettingsEhController : SettingsController() {
private fun Preference<*>.reconfigure(): Boolean {
// Listen for change commit
asObservable()
.skip(1) // Skip first as it is emitted immediately
asFlow()
.take(1) // Only listen for first commit
.observeOn(AndroidSchedulers.mainThread())
.subscribeUntilDestroy {
.onEach {
// Only listen for first change commit
WarnConfigureDialogController.uploadSettings(router)
}
.launchIn(scope)
// Always return true to save changes
return true
@ -85,12 +84,11 @@ class SettingsEhController : SettingsController() {
isPersistent = false
defaultValue = false
preferences.enableExhentai()
.asObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeUntilDestroy {
.asFlow()
.onEach {
isChecked = it
}
.launchIn(scope)
onChange { newVal ->
newVal as Boolean
@ -243,8 +241,8 @@ class SettingsEhController : SettingsController() {
entryValues = arrayOf("0", "1", "2", "3", "6", "12", "24", "48")
defaultValue = "0"
preferences.eh_autoUpdateFrequency().asObservable()
.subscribeUntilDestroy { newVal ->
preferences.eh_autoUpdateFrequency().asFlow()
.onEach { newVal ->
summary = if (newVal == 0) {
"${context.getString(R.string.app_name)} will currently never check galleries in your library for updates."
} else {
@ -253,6 +251,7 @@ class SettingsEhController : SettingsController() {
" wait $newVal hour(s), check ${EHentaiUpdateWorkerConstants.UPDATES_PER_ITERATION} and so on..."
}
}
.launchIn(scope)
onChange { newValue ->
val interval = (newValue as String).toInt()
@ -268,8 +267,9 @@ class SettingsEhController : SettingsController() {
entryValues = arrayOf("wifi", "ac")
summaryRes = R.string.pref_library_update_restriction_summary
preferences.eh_autoUpdateFrequency().asObservable()
.subscribeUntilDestroy { isVisible = it > 0 }
preferences.eh_autoUpdateFrequency().asFlow()
.onEach { isVisible = it > 0 }
.launchIn(scope)
onChange {
// Post to event looper to allow the preference to be updated.
@ -290,7 +290,7 @@ class SettingsEhController : SettingsController() {
GlobalScope.launch(Dispatchers.IO) {
val updateInfo = try {
val stats =
preferences.eh_autoUpdateStats().getOrDefault().nullIfBlank()?.let {
preferences.eh_autoUpdateStats().get().nullIfBlank()?.let {
gson.fromJson<EHentaiUpdaterStats>(it)
}

View File

@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.data.database.models.MangaImpl
import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.data.updater.UpdaterJob
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
import exh.source.BlacklistedSources
@ -33,7 +32,7 @@ object EXHMigrations {
*/
fun upgrade(preferences: PreferencesHelper): Boolean {
val context = preferences.context
val oldVersion = preferences.eh_lastVersionCode().getOrDefault()
val oldVersion = preferences.eh_lastVersionCode().get()
try {
if (oldVersion < BuildConfig.VERSION_CODE) {
// Fresh install

View File

@ -16,7 +16,6 @@ import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.library.LibraryUpdateNotifier
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.all.EHentai
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
@ -350,7 +349,7 @@ class EHentaiUpdateWorker : JobService(), CoroutineScope {
cancelBackground(context)
val preferences = Injekt.get<PreferencesHelper>()
val interval = prefInterval ?: preferences.eh_autoUpdateFrequency().getOrDefault()
val interval = prefInterval ?: preferences.eh_autoUpdateFrequency().get()
if (interval > 0) {
val restrictions = preferences.eh_autoUpdateRequirements()!!
val acRestriction = "ac" in restrictions

View File

@ -9,7 +9,6 @@ import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.MangaCategory
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.all.EHentai
import eu.kanade.tachiyomi.util.lang.launchUI
@ -68,7 +67,7 @@ class FavoritesSyncHelper(val context: Context) {
private fun beginSync() {
// Check if logged in
if (!prefs.enableExhentai().getOrDefault()) {
if (!prefs.enableExhentai().get()) {
status.onNext(FavoritesSyncStatus.Error("Please log in!"))
return
}
@ -130,7 +129,7 @@ class FavoritesSyncHelper(val context: Context) {
db.inTransaction {
status.onNext(FavoritesSyncStatus.Processing("Calculating remote changes"))
val remoteChanges = storage.getChangedRemoteEntries(realm, favorites.first)
val localChanges = if (prefs.eh_readOnlySync().getOrDefault()) {
val localChanges = if (prefs.eh_readOnlySync().get()) {
null // Do not build local changes if they are not going to be applied
} else {
status.onNext(FavoritesSyncStatus.Processing("Calculating local changes"))
@ -248,7 +247,7 @@ class FavoritesSyncHelper(val context: Context) {
if (!explicitlyRetryExhRequest(10, request)) {
val errorString = "Unable to add gallery to remote server: '${gallery.title}' (GID: ${gallery.gid})!"
if (prefs.eh_lenientSync().getOrDefault()) {
if (prefs.eh_lenientSync().get()) {
errorList += errorString
} else {
status.onNext(FavoritesSyncStatus.Error(errorString))
@ -298,7 +297,7 @@ class FavoritesSyncHelper(val context: Context) {
if (!explicitlyRetryExhRequest(10, request)) {
val errorString = "Unable to delete galleries from the remote servers!"
if (prefs.eh_lenientSync().getOrDefault()) {
if (prefs.eh_lenientSync().get()) {
errorList += errorString
} else {
status.onNext(FavoritesSyncStatus.Error(errorString))
@ -386,7 +385,7 @@ class FavoritesSyncHelper(val context: Context) {
is GalleryAddEvent.Fail.UnknownType -> "'${it.title}' (${result.galleryUrl}) is not a valid gallery!"
}
if (prefs.eh_lenientSync().getOrDefault()) {
if (prefs.eh_lenientSync().get()) {
errorList += errorString
} else {
status.onNext(FavoritesSyncStatus.Error(errorString))

View File

@ -2,7 +2,6 @@ package exh.metadata.metadata
import android.net.Uri
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.model.SManga
import exh.metadata.EX_DATE_FORMAT
import exh.metadata.ONGOING_SUFFIX
@ -50,7 +49,7 @@ class EHentaiSearchMetadata : RaisedSearchMetadata() {
thumbnailUrl?.let { manga.thumbnail_url = it }
// No title bug?
val titleObj = if (Injekt.get<PreferencesHelper>().useJapaneseTitle().getOrDefault()) {
val titleObj = if (Injekt.get<PreferencesHelper>().useJapaneseTitle().get()) {
altTitle ?: title
} else {
title

View File

@ -1,7 +1,6 @@
package exh.metadata.metadata
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.model.SManga
import exh.metadata.EX_DATE_FORMAT
import exh.metadata.ONGOING_SUFFIX
@ -42,7 +41,7 @@ class NHentaiSearchMetadata : RaisedSearchMetadata() {
nhId?.let { manga.url = nhIdToPath(it) }
if (mediaId != null) {
val hqThumbs = Injekt.get<PreferencesHelper>().eh_nh_useHighQualityThumbs().getOrDefault()
val hqThumbs = Injekt.get<PreferencesHelper>().eh_nh_useHighQualityThumbs().get()
typeToExtension(if (hqThumbs) coverImageType else thumbnailImageType)?.let {
manga.thumbnail_url = "https://t.nhentai.net/galleries/$mediaId/${if (hqThumbs) {
"cover"

View File

@ -1,7 +1,6 @@
package exh.source
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.Page
@ -217,7 +216,7 @@ class EnhancedHttpSource(
override fun getFilterList() = source().getFilterList()
private fun source(): HttpSource {
return if (prefs.eh_delegateSources().getOrDefault()) {
return if (prefs.eh_delegateSources().get()) {
enchancedSource
} else {
originalSource

View File

@ -1,7 +1,6 @@
package exh.uconfig
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import okhttp3.FormBody
import uy.kohesive.injekt.injectLazy
@ -13,7 +12,7 @@ class EhUConfigBuilder {
configItems += when (
prefs.imageQuality()
.getOrDefault()
.get()
.toLowerCase()
) {
"ovrs_2400" -> Entry.ImageSize.`2400`
@ -25,19 +24,19 @@ class EhUConfigBuilder {
else -> Entry.ImageSize.AUTO
}
configItems += if (prefs.useHentaiAtHome().getOrDefault()) {
configItems += if (prefs.useHentaiAtHome().get()) {
Entry.UseHentaiAtHome.YES
} else {
Entry.UseHentaiAtHome.NO
}
configItems += if (prefs.useJapaneseTitle().getOrDefault()) {
configItems += if (prefs.useJapaneseTitle().get()) {
Entry.TitleDisplayLanguage.JAPANESE
} else {
Entry.TitleDisplayLanguage.DEFAULT
}
configItems += if (prefs.eh_useOriginalImages().getOrDefault()) {
configItems += if (prefs.eh_useOriginalImages().get()) {
Entry.UseOriginalImages.YES
} else {
Entry.UseOriginalImages.NO

View File

@ -16,7 +16,6 @@ import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.string
import com.google.gson.JsonParser
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.Source
@ -121,7 +120,7 @@ class BrowserActionActivity : AppCompatActivity() {
// Wait for both inner scripts to be loaded
if (loadedInners >= 2) {
// Attempt to autosolve captcha
if (preferencesHelper.eh_autoSolveCaptchas().getOrDefault()) {
if (preferencesHelper.eh_autoSolveCaptchas().get()) {
webview.post {
// 10 seconds to auto-solve captcha
strictValidationStartTime = System.currentTimeMillis() + 1000 * 10
@ -140,7 +139,7 @@ class BrowserActionActivity : AppCompatActivity() {
}
}
webview.webViewClient = if (actionName == null && preferencesHelper.eh_autoSolveCaptchas().getOrDefault()) {
webview.webViewClient = if (actionName == null && preferencesHelper.eh_autoSolveCaptchas().get()) {
// Fetch auto-solve credentials early for speed
credentialsObservable = httpClient.newCall(
Request.Builder()

View File

@ -161,9 +161,9 @@ class LoginController : NucleusController<EhActivityLoginBinding, LoginPresenter
if (memberId == null || passHash == null || igneous == null) return false
// Update prefs
preferenceManager.memberIdVal().set(memberId)
preferenceManager.passHashVal().set(passHash)
preferenceManager.igneousVal().set(igneous)
preferenceManager.memberIdVal().set(memberId!!)
preferenceManager.passHashVal().set(passHash!!)
preferenceManager.igneousVal().set(igneous!!)
return true
}