backend preference wrapper

This commit is contained in:
rebelonion 2024-01-30 00:39:12 -06:00
parent eb5b83564f
commit 8020b32541
66 changed files with 482 additions and 458 deletions

View file

@ -3,6 +3,8 @@ package ani.dantotsu.parsers
import android.content.Context
import ani.dantotsu.Lazier
import ani.dantotsu.lazyList
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import eu.kanade.tachiyomi.extension.anime.model.AnimeExtension
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
@ -12,9 +14,7 @@ object AnimeSources : WatchSources() {
var pinnedAnimeSources: Set<String> = emptySet()
suspend fun init(fromExtensions: StateFlow<List<AnimeExtension.Installed>>, context: Context) {
val sharedPrefs = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
pinnedAnimeSources =
sharedPrefs.getStringSet("pinned_anime_sources", emptySet()) ?: emptySet()
pinnedAnimeSources = PrefWrapper.getVal(PrefName.PinnedAnimeSources, emptySet())
// Initialize with the first value from StateFlow
val initialExtensions = fromExtensions.first()

View file

@ -3,6 +3,8 @@ package ani.dantotsu.parsers
import android.content.Context
import ani.dantotsu.Lazier
import ani.dantotsu.lazyList
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import eu.kanade.tachiyomi.extension.manga.model.MangaExtension
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
@ -11,10 +13,8 @@ object MangaSources : MangaReadSources() {
override var list: List<Lazier<BaseParser>> = emptyList()
var pinnedMangaSources: Set<String> = emptySet()
suspend fun init(fromExtensions: StateFlow<List<MangaExtension.Installed>>, context: Context) {
val sharedPrefs = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
pinnedMangaSources =
sharedPrefs.getStringSet("pinned_manga_sources", emptySet()) ?: emptySet()
suspend fun init(fromExtensions: StateFlow<List<MangaExtension.Installed>>) {
pinnedMangaSources = PrefWrapper.getVal(PrefName.PinnedMangaSources, emptySet())
// Initialize with the first value from StateFlow
val initialExtensions = fromExtensions.first()

View file

@ -4,6 +4,8 @@ package ani.dantotsu.parsers.novel
import android.content.Context
import ani.dantotsu.currContext
import ani.dantotsu.logger
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import eu.kanade.tachiyomi.extension.ExtensionUpdateNotifier
import eu.kanade.tachiyomi.extension.anime.model.AnimeExtension
import eu.kanade.tachiyomi.extension.anime.model.AnimeLoadResult
@ -26,9 +28,7 @@ class NovelExtensionGithubApi {
private val novelExtensionManager: NovelExtensionManager by injectLazy()
private val json: Json by injectLazy()
private val lastExtCheck: Long =
currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getLong("last_ext_check", 0) ?: 0
private val lastExtCheck: Long = PrefWrapper.getVal(PrefName.NovelLastExtCheck, 0L)
private var requiresFallbackSource = false
@ -86,8 +86,7 @@ class NovelExtensionGithubApi {
novelExtensionManager.availableExtensionsFlow.value
} else {
findExtensions().also {
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit()
?.putLong("last_ext_check", Date().time)?.apply()
PrefWrapper.setVal(PrefName.NovelLastExtCheck, Date().time)
}
}