mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Remove rx pref library
This commit is contained in:
parent
80053ce073
commit
b85f133580
37 changed files with 162 additions and 278 deletions
|
@ -126,7 +126,6 @@ dependencies {
|
|||
implementation("io.reactivex:rxandroid:1.2.1")
|
||||
implementation("io.reactivex:rxjava:1.3.8")
|
||||
implementation("com.jakewharton.rxrelay:rxrelay:1.2.0")
|
||||
implementation("com.f2prateek.rx.preferences:rx-preferences:1.0.2")
|
||||
implementation("com.github.pwittchen:reactivenetwork:0.13.0")
|
||||
|
||||
// Coroutines
|
||||
|
|
|
@ -11,7 +11,6 @@ import androidx.multidex.MultiDex
|
|||
import eu.kanade.tachiyomi.data.image.coil.CoilSetup
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||
import org.acra.ACRA
|
||||
import org.acra.config.httpSender
|
||||
|
@ -62,7 +61,7 @@ open class App : Application(), LifecycleObserver {
|
|||
@Suppress("unused")
|
||||
fun onAppBackgrounded() {
|
||||
// App in background
|
||||
if (!SecureActivityDelegate.isAuthenticating && preferences.lockAfter().getOrDefault() >= 0) {
|
||||
if (!SecureActivityDelegate.isAuthenticating && preferences.lockAfter().get() >= 0) {
|
||||
SecureActivityDelegate.locked = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import eu.kanade.tachiyomi.data.download.DownloadProvider
|
|||
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.preference.plusAssign
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
||||
|
@ -35,7 +34,7 @@ object Migrations {
|
|||
prefs.edit {
|
||||
remove(UpdaterService.NOTIFY_ON_INSTALL_KEY)
|
||||
}
|
||||
val oldVersion = preferences.lastVersionCode().getOrDefault()
|
||||
val oldVersion = preferences.lastVersionCode().get()
|
||||
if (oldVersion < BuildConfig.VERSION_CODE) {
|
||||
preferences.lastVersionCode().set(BuildConfig.VERSION_CODE)
|
||||
|
||||
|
|
|
@ -7,9 +7,14 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
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.source.SourceManager
|
||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
@ -46,17 +51,20 @@ class DownloadCache(
|
|||
|
||||
private var mangaFiles: MutableMap<Long, MutableSet<String>> = mutableMapOf()
|
||||
|
||||
val scope = CoroutineScope(Job() + Dispatchers.IO)
|
||||
|
||||
init {
|
||||
preferences.downloadsDirectory().asObservable().skip(1).subscribe {
|
||||
lastRenew = 0L // invalidate cache
|
||||
}
|
||||
preferences.downloadsDirectory().asFlow()
|
||||
.drop(1)
|
||||
.onEach { lastRenew = 0L } // invalidate cache
|
||||
.launchIn(scope)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the downloads directory from the user's preferences.
|
||||
*/
|
||||
private fun getDirectoryFromPreference(): UniFile {
|
||||
val dir = preferences.downloadsDirectory().getOrDefault()
|
||||
val dir = preferences.downloadsDirectory().get()
|
||||
return UniFile.fromUri(context, dir.toUri())
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,11 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
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.source.Source
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
/**
|
||||
|
@ -30,15 +31,16 @@ class DownloadProvider(private val context: Context) {
|
|||
/**
|
||||
* The root directory for downloads.
|
||||
*/
|
||||
private var downloadsDir = preferences.downloadsDirectory().getOrDefault().let {
|
||||
private var downloadsDir = preferences.downloadsDirectory().get().let {
|
||||
val dir = UniFile.fromUri(context, it.toUri())
|
||||
DiskUtil.createNoMediaFile(dir, context)
|
||||
dir
|
||||
}
|
||||
|
||||
init {
|
||||
preferences.downloadsDirectory().asObservable().skip(1)
|
||||
.subscribe { downloadsDir = UniFile.fromUri(context, it.toUri()) }
|
||||
preferences.downloadsDirectory().asFlow().drop(1).onEach {
|
||||
downloadsDir = UniFile.fromUri(context, it.toUri())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,6 @@ import androidx.work.WorkManager
|
|||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
@ -27,7 +26,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
|||
|
||||
fun setupTask(context: Context, prefInterval: Int? = null) {
|
||||
val preferences = Injekt.get<PreferencesHelper>()
|
||||
val interval = prefInterval ?: preferences.libraryUpdateInterval().getOrDefault()
|
||||
val interval = prefInterval ?: preferences.libraryUpdateInterval().get()
|
||||
if (interval > 0) {
|
||||
val restrictions = preferences.libraryUpdateRestriction()!!
|
||||
val acRestriction = "ac" in restrictions
|
||||
|
|
|
@ -25,7 +25,6 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateRanker.rankingScheme
|
|||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.data.track.UnattendedTrackService
|
||||
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
|
||||
|
@ -140,7 +139,7 @@ class LibraryUpdateService(
|
|||
|
||||
instance = this
|
||||
|
||||
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
||||
val selectedScheme = preferences.libraryUpdatePrioritization().get()
|
||||
val savedMangasList = intent.getLongArrayExtra(KEY_MANGAS)?.asList()
|
||||
|
||||
val mangaList = (
|
||||
|
@ -284,14 +283,14 @@ class LibraryUpdateService(
|
|||
}
|
||||
|
||||
private fun addMangaToQueue(categoryId: Int, manga: List<LibraryManga>) {
|
||||
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
||||
val selectedScheme = preferences.libraryUpdatePrioritization().get()
|
||||
val mangas = manga.sortedWith(rankingScheme[selectedScheme])
|
||||
categoryIds.add(categoryId)
|
||||
addManga(mangas)
|
||||
}
|
||||
|
||||
private fun addCategory(categoryId: Int) {
|
||||
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
||||
val selectedScheme = preferences.libraryUpdatePrioritization().get()
|
||||
val mangas =
|
||||
getMangaToUpdate(categoryId, Target.CHAPTERS).sortedWith(
|
||||
rankingScheme[selectedScheme]
|
||||
|
@ -346,7 +345,7 @@ class LibraryUpdateService(
|
|||
if (newUpdates.isNotEmpty()) {
|
||||
notifier.showResultNotification(newUpdates)
|
||||
|
||||
if (preferences.refreshCoversToo().getOrDefault() && job?.isCancelled == false) {
|
||||
if (preferences.refreshCoversToo().get() && job?.isCancelled == false) {
|
||||
updateDetails(newUpdates.keys.toList())
|
||||
notifier.cancelProgressNotification()
|
||||
if (downloadNew && hasDownloads) {
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package eu.kanade.tachiyomi.data.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.f2prateek.rx.preferences.Preference
|
||||
import com.f2prateek.rx.preferences.RxSharedPreferences
|
||||
import com.tfcporciuncula.flow.FlowSharedPreferences
|
||||
import com.tfcporciuncula.flow.Preference
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.track.TrackService
|
||||
|
@ -34,59 +32,40 @@ import java.text.SimpleDateFormat
|
|||
import java.util.Locale
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||
|
||||
fun <T> Preference<T>.getOrDefault(): T = get() ?: defaultValue()!!
|
||||
|
||||
fun <T> com.tfcporciuncula.flow.Preference<T>.asImmediateFlow(block: (value: T) -> Unit): Flow<T> {
|
||||
fun <T> Preference<T>.asImmediateFlow(block: (value: T) -> Unit): Flow<T> {
|
||||
block(get())
|
||||
return asFlow()
|
||||
.onEach { block(it) }
|
||||
}
|
||||
|
||||
fun <T> com.tfcporciuncula.flow.Preference<T>.asImmediateFlowIn(scope: CoroutineScope, block: (value: T) -> Unit): Job {
|
||||
fun <T> Preference<T>.asImmediateFlowIn(scope: CoroutineScope, block: (value: T) -> Unit): Job {
|
||||
block(get())
|
||||
return asFlow()
|
||||
.onEach { block(it) }
|
||||
.launchIn(scope)
|
||||
}
|
||||
|
||||
fun com.tfcporciuncula.flow.Preference<Boolean>.toggle() = set(!get())
|
||||
fun Preference<Boolean>.toggle() = set(!get())
|
||||
|
||||
private class DateFormatConverter : Preference.Adapter<DateFormat> {
|
||||
override fun get(key: String, preferences: SharedPreferences): DateFormat {
|
||||
val dateFormat = preferences.getString(Keys.dateFormat, "")!!
|
||||
|
||||
if (dateFormat != "") {
|
||||
return SimpleDateFormat(dateFormat, Locale.getDefault())
|
||||
}
|
||||
|
||||
return DateFormat.getDateInstance(DateFormat.SHORT)
|
||||
}
|
||||
|
||||
override fun set(key: String, value: DateFormat, editor: SharedPreferences.Editor) {
|
||||
// No-op
|
||||
}
|
||||
}
|
||||
|
||||
operator fun <T> com.tfcporciuncula.flow.Preference<Set<T>>.plusAssign(item: T) {
|
||||
operator fun <T> Preference<Set<T>>.plusAssign(item: T) {
|
||||
set(get() + item)
|
||||
}
|
||||
|
||||
operator fun <T> com.tfcporciuncula.flow.Preference<Set<T>>.minusAssign(item: T) {
|
||||
operator fun <T> Preference<Set<T>>.minusAssign(item: T) {
|
||||
set(get() - item)
|
||||
}
|
||||
|
||||
operator fun <T> com.tfcporciuncula.flow.Preference<Set<T>>.plusAssign(item: Collection<T>) {
|
||||
operator fun <T> Preference<Set<T>>.plusAssign(item: Collection<T>) {
|
||||
set(get() + item)
|
||||
}
|
||||
|
||||
operator fun <T> com.tfcporciuncula.flow.Preference<Set<T>>.minusAssign(item: Collection<T>) {
|
||||
operator fun <T> Preference<Set<T>>.minusAssign(item: Collection<T>) {
|
||||
set(get() - item)
|
||||
}
|
||||
|
||||
class PreferencesHelper(val context: Context) {
|
||||
|
||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
private val rxPrefs = RxSharedPreferences.create(prefs)
|
||||
private val flowPrefs = FlowSharedPreferences(prefs)
|
||||
|
||||
private val defaultDownloadsDir = Uri.fromFile(
|
||||
|
@ -105,9 +84,9 @@ class PreferencesHelper(val context: Context) {
|
|||
)
|
||||
)
|
||||
|
||||
fun getInt(key: String, default: Int?) = rxPrefs.getInteger(key, default)
|
||||
fun getStringPref(key: String, default: String?) = rxPrefs.getString(key, default)
|
||||
fun getStringSet(key: String, default: Set<String>) = rxPrefs.getStringSet(key, default)
|
||||
fun getInt(key: String, default: Int) = flowPrefs.getInt(key, default)
|
||||
fun getStringPref(key: String, default: String) = flowPrefs.getString(key, default)
|
||||
fun getStringSet(key: String, default: Set<String>) = flowPrefs.getStringSet(key, default)
|
||||
|
||||
fun startingTab() = flowPrefs.getInt(Keys.startingTab, 0)
|
||||
fun backReturnsToStart() = flowPrefs.getBoolean(Keys.backToStart, true)
|
||||
|
@ -215,17 +194,17 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun lastUsedCatalogueSource() = flowPrefs.getLong(Keys.lastUsedCatalogueSource, -1)
|
||||
|
||||
fun lastUsedCategory() = rxPrefs.getInteger(Keys.lastUsedCategory, 0)
|
||||
fun lastUsedCategory() = flowPrefs.getInt(Keys.lastUsedCategory, 0)
|
||||
|
||||
fun lastUsedSources() = flowPrefs.getStringSet("last_used_sources", emptySet())
|
||||
|
||||
fun lastVersionCode() = rxPrefs.getInteger("last_version_code", 0)
|
||||
fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0)
|
||||
|
||||
fun browseAsList() = flowPrefs.getBoolean(Keys.catalogueAsList, false)
|
||||
|
||||
fun enabledLanguages() = flowPrefs.getStringSet(Keys.enabledLanguages, setOf("all", "en", Locale.getDefault().language))
|
||||
|
||||
fun sourceSorting() = rxPrefs.getInteger(Keys.sourcesSort, 0)
|
||||
fun sourceSorting() = flowPrefs.getInt(Keys.sourcesSort, 0)
|
||||
|
||||
fun trackUsername(sync: TrackService) = prefs.getString(Keys.trackUsername(sync.id), "")
|
||||
|
||||
|
@ -240,7 +219,7 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun trackToken(sync: TrackService) = flowPrefs.getString(Keys.trackToken(sync.id), "")
|
||||
|
||||
fun anilistScoreType() = rxPrefs.getString("anilist_score_type", "POINT_10")
|
||||
fun anilistScoreType() = flowPrefs.getString("anilist_score_type", "POINT_10")
|
||||
|
||||
fun backupsDirectory() = flowPrefs.getString(Keys.backupDirectory, defaultBackupDir.toString())
|
||||
|
||||
|
@ -249,7 +228,7 @@ class PreferencesHelper(val context: Context) {
|
|||
else -> SimpleDateFormat(format, Locale.getDefault())
|
||||
}
|
||||
|
||||
fun downloadsDirectory() = rxPrefs.getString(Keys.downloadsDirectory, defaultDownloadsDir.toString())
|
||||
fun downloadsDirectory() = flowPrefs.getString(Keys.downloadsDirectory, defaultDownloadsDir.toString())
|
||||
|
||||
fun downloadOnlyOverWifi() = prefs.getBoolean(Keys.downloadOnlyOverWifi, true)
|
||||
|
||||
|
@ -269,14 +248,14 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun removeAfterMarkedAsRead() = prefs.getBoolean(Keys.removeAfterMarkedAsRead, false)
|
||||
|
||||
fun libraryUpdateInterval() = rxPrefs.getInteger(Keys.libraryUpdateInterval, 24)
|
||||
fun libraryUpdateInterval() = flowPrefs.getInt(Keys.libraryUpdateInterval, 24)
|
||||
|
||||
fun libraryUpdateRestriction() = prefs.getStringSet(Keys.libraryUpdateRestriction, emptySet())
|
||||
|
||||
fun libraryUpdateCategories() = flowPrefs.getStringSet(Keys.libraryUpdateCategories, emptySet())
|
||||
fun libraryUpdateCategoriesExclude() = flowPrefs.getStringSet(Keys.libraryUpdateCategoriesExclude, emptySet())
|
||||
|
||||
fun libraryUpdatePrioritization() = rxPrefs.getInteger(Keys.libraryUpdatePrioritization, 0)
|
||||
fun libraryUpdatePrioritization() = flowPrefs.getInt(Keys.libraryUpdatePrioritization, 0)
|
||||
|
||||
fun libraryLayout() = flowPrefs.getInt(Keys.libraryLayout, 2)
|
||||
|
||||
|
@ -284,29 +263,29 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun uniformGrid() = flowPrefs.getBoolean(Keys.uniformGrid, true)
|
||||
|
||||
fun downloadBadge() = rxPrefs.getBoolean(Keys.downloadBadge, false)
|
||||
fun downloadBadge() = flowPrefs.getBoolean(Keys.downloadBadge, false)
|
||||
|
||||
fun filterDownloaded() = rxPrefs.getInteger(Keys.filterDownloaded, 0)
|
||||
fun filterDownloaded() = flowPrefs.getInt(Keys.filterDownloaded, 0)
|
||||
|
||||
fun filterUnread() = rxPrefs.getInteger(Keys.filterUnread, 0)
|
||||
fun filterUnread() = flowPrefs.getInt(Keys.filterUnread, 0)
|
||||
|
||||
fun filterCompleted() = rxPrefs.getInteger(Keys.filterCompleted, 0)
|
||||
fun filterCompleted() = flowPrefs.getInt(Keys.filterCompleted, 0)
|
||||
|
||||
fun filterTracked() = rxPrefs.getInteger(Keys.filterTracked, 0)
|
||||
fun filterTracked() = flowPrefs.getInt(Keys.filterTracked, 0)
|
||||
|
||||
fun filterMangaType() = rxPrefs.getInteger(Keys.filterMangaType, 0)
|
||||
fun filterMangaType() = flowPrefs.getInt(Keys.filterMangaType, 0)
|
||||
|
||||
fun showEmptyCategoriesWhileFiltering() = flowPrefs.getBoolean(Keys.showEmptyCategoriesFiltering, false)
|
||||
|
||||
fun librarySortingMode() = rxPrefs.getInteger(Keys.librarySortingMode, 0)
|
||||
fun librarySortingMode() = flowPrefs.getInt(Keys.librarySortingMode, 0)
|
||||
|
||||
fun librarySortingAscending() = rxPrefs.getBoolean("library_sorting_ascending", true)
|
||||
fun librarySortingAscending() = flowPrefs.getBoolean("library_sorting_ascending", true)
|
||||
|
||||
fun automaticExtUpdates() = flowPrefs.getBoolean(Keys.automaticExtUpdates, true)
|
||||
|
||||
fun installedExtensionsOrder() = flowPrefs.getInt(Keys.installedExtensionsOrder, InstalledExtensionsOrder.Name.value)
|
||||
|
||||
fun collapsedCategories() = rxPrefs.getStringSet("collapsed_categories", mutableSetOf())
|
||||
fun collapsedCategories() = flowPrefs.getStringSet("collapsed_categories", mutableSetOf())
|
||||
|
||||
fun collapsedDynamicCategories() = flowPrefs.getStringSet("collapsed_dynamic_categories", mutableSetOf())
|
||||
|
||||
|
@ -327,34 +306,34 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun skipFiltered() = prefs.getBoolean(Keys.skipFiltered, true)
|
||||
|
||||
fun useBiometrics() = rxPrefs.getBoolean(Keys.useBiometrics, false)
|
||||
fun useBiometrics() = flowPrefs.getBoolean(Keys.useBiometrics, false)
|
||||
|
||||
fun lockAfter() = rxPrefs.getInteger(Keys.lockAfter, 0)
|
||||
fun lockAfter() = flowPrefs.getInt(Keys.lockAfter, 0)
|
||||
|
||||
fun lastUnlock() = rxPrefs.getLong(Keys.lastUnlock, 0)
|
||||
fun lastUnlock() = flowPrefs.getLong(Keys.lastUnlock, 0)
|
||||
|
||||
fun secureScreen() = rxPrefs.getBoolean(Keys.secureScreen, false)
|
||||
fun secureScreen() = flowPrefs.getBoolean(Keys.secureScreen, false)
|
||||
|
||||
fun hideNotificationContent() = prefs.getBoolean(Keys.hideNotificationContent, false)
|
||||
|
||||
fun removeArticles() = rxPrefs.getBoolean(Keys.removeArticles, false)
|
||||
fun removeArticles() = flowPrefs.getBoolean(Keys.removeArticles, false)
|
||||
|
||||
fun migrateFlags() = rxPrefs.getInteger("migrate_flags", Int.MAX_VALUE)
|
||||
fun migrateFlags() = flowPrefs.getInt("migrate_flags", Int.MAX_VALUE)
|
||||
|
||||
fun trustedSignatures() = rxPrefs.getStringSet("trusted_signatures", emptySet())
|
||||
fun trustedSignatures() = flowPrefs.getStringSet("trusted_signatures", emptySet())
|
||||
|
||||
// using string instead of set so it is ordered
|
||||
fun migrationSources() = flowPrefs.getString("migrate_sources", "")
|
||||
|
||||
fun useSourceWithMost() = rxPrefs.getBoolean("use_source_with_most", false)
|
||||
fun useSourceWithMost() = flowPrefs.getBoolean("use_source_with_most", false)
|
||||
|
||||
fun skipPreMigration() = rxPrefs.getBoolean(Keys.skipPreMigration, false)
|
||||
fun skipPreMigration() = flowPrefs.getBoolean(Keys.skipPreMigration, false)
|
||||
|
||||
fun defaultMangaOrder() = rxPrefs.getString("default_manga_order", "")
|
||||
fun defaultMangaOrder() = flowPrefs.getString("default_manga_order", "")
|
||||
|
||||
fun refreshCoversToo() = rxPrefs.getBoolean(Keys.refreshCoversToo, true)
|
||||
fun refreshCoversToo() = flowPrefs.getBoolean(Keys.refreshCoversToo, true)
|
||||
|
||||
fun updateOnRefresh() = rxPrefs.getInteger(Keys.updateOnRefresh, -1)
|
||||
fun updateOnRefresh() = flowPrefs.getInt(Keys.updateOnRefresh, -1)
|
||||
|
||||
fun extensionUpdatesCount() = flowPrefs.getInt("ext_updates_count", 0)
|
||||
|
||||
|
@ -374,7 +353,7 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun showTitleFirstInRecents() = flowPrefs.getBoolean(Keys.showTitleFirstInRecents, false)
|
||||
|
||||
fun lastExtCheck() = rxPrefs.getLong("last_ext_check", 0)
|
||||
fun lastExtCheck() = flowPrefs.getLong("last_ext_check", 0)
|
||||
|
||||
fun lastAppCheck() = flowPrefs.getLong("last_app_check", 0)
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import androidx.annotation.StringRes
|
|||
import com.google.gson.Gson
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Track
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.track.TrackService
|
||||
import eu.kanade.tachiyomi.data.track.updateNewTrackInfo
|
||||
import timber.log.Timber
|
||||
|
@ -72,7 +71,7 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) {
|
|||
}
|
||||
|
||||
override fun getScoreList(): List<String> {
|
||||
return when (scorePreference.getOrDefault()) {
|
||||
return when (scorePreference.get()) {
|
||||
// 10 point
|
||||
POINT_10 -> IntRange(0, 10).map(Int::toString)
|
||||
// 100 point
|
||||
|
@ -88,7 +87,7 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) {
|
|||
}
|
||||
|
||||
override fun indexToScore(index: Int): Float {
|
||||
return when (scorePreference.getOrDefault()) {
|
||||
return when (scorePreference.get()) {
|
||||
// 10 point
|
||||
POINT_10 -> index * 10f
|
||||
// 100 point
|
||||
|
@ -112,7 +111,7 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) {
|
|||
override fun displayScore(track: Track): String {
|
||||
val score = track.score
|
||||
|
||||
return when (scorePreference.getOrDefault()) {
|
||||
return when (scorePreference.get()) {
|
||||
POINT_5 -> when (score) {
|
||||
0f -> "0 ★"
|
||||
else -> "${((score + 10) / 20).toInt()} ★"
|
||||
|
|
|
@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.data.track.anilist
|
|||
|
||||
import eu.kanade.tachiyomi.data.database.models.Track
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
@ -94,7 +93,7 @@ fun Track.toAnilistStatus() = when (status) {
|
|||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
fun Track.toAnilistScore(): String = when (preferences.anilistScoreType().getOrDefault()) {
|
||||
fun Track.toAnilistScore(): String = when (preferences.anilistScoreType().get()) {
|
||||
// 10 point
|
||||
"POINT_10" -> (score.toInt() / 10).toString()
|
||||
// 100 point
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.graphics.drawable.Drawable
|
|||
import android.os.Parcelable
|
||||
import com.jakewharton.rxrelay.BehaviorRelay
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
import eu.kanade.tachiyomi.extension.model.InstallStep
|
||||
|
@ -350,7 +349,7 @@ class ExtensionManager(
|
|||
|
||||
ExtensionLoader.trustedSignatures += signature
|
||||
val preference = preferences.trustedSignatures()
|
||||
preference.set(preference.getOrDefault() + signature)
|
||||
preference.set(preference.get() + signature)
|
||||
|
||||
val nowTrustedExtensions = untrustedExtensions.filter { it.signatureHash == signature }
|
||||
untrustedExtensions -= nowTrustedExtensions
|
||||
|
|
|
@ -8,7 +8,6 @@ import android.os.Build
|
|||
import dalvik.system.PathClassLoader
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
import eu.kanade.tachiyomi.extension.model.LoadResult
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
|
@ -46,7 +45,7 @@ internal object ExtensionLoader {
|
|||
/**
|
||||
* List of the trusted signatures.
|
||||
*/
|
||||
var trustedSignatures = mutableSetOf<String>() + preferences.trustedSignatures().getOrDefault() + officialSignature
|
||||
var trustedSignatures = mutableSetOf<String>() + preferences.trustedSignatures().get() + officialSignature
|
||||
|
||||
/**
|
||||
* Return a list of all the installed extensions initialized concurrently.
|
||||
|
|
|
@ -13,7 +13,6 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
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.databinding.MangaCategoryDialogBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.ui.library.LibrarySort
|
||||
|
@ -112,7 +111,7 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
|||
true -> preferences.downloadNew().set(true)
|
||||
false -> preferences.downloadNew().set(false)
|
||||
}
|
||||
if (preferences.libraryUpdateInterval().getOrDefault() > 0 &&
|
||||
if (preferences.libraryUpdateInterval().get() > 0 &&
|
||||
updatePref(
|
||||
preferences.libraryUpdateCategories(),
|
||||
preferences.libraryUpdateCategoriesExclude(),
|
||||
|
@ -169,7 +168,7 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
|||
binding.includeGlobal,
|
||||
preferences.libraryUpdateCategories(),
|
||||
preferences.libraryUpdateCategoriesExclude(),
|
||||
preferences.libraryUpdateInterval().getOrDefault() > 0
|
||||
preferences.libraryUpdateInterval().get() > 0
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
|
|||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.databinding.ExtensionsBottomSheetBinding
|
||||
import eu.kanade.tachiyomi.databinding.RecyclerWithScrollerBinding
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
|
@ -268,7 +267,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
|||
|
||||
if (item is MangaItem) {
|
||||
PreMigrationController.navigateToMigration(
|
||||
Injekt.get<PreferencesHelper>().skipPreMigration().getOrDefault(),
|
||||
Injekt.get<PreferencesHelper>().skipPreMigration().get(),
|
||||
controller.router,
|
||||
listOf(item.manga.id!!)
|
||||
)
|
||||
|
@ -296,7 +295,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
|||
presenter.mangaItems[item.source.id]?.mapNotNull { it.manga.id }?.toList()
|
||||
?: emptyList()
|
||||
PreMigrationController.navigateToMigration(
|
||||
Injekt.get<PreferencesHelper>().skipPreMigration().getOrDefault(),
|
||||
Injekt.get<PreferencesHelper>().skipPreMigration().get(),
|
||||
controller.router,
|
||||
sourceMangas
|
||||
)
|
||||
|
|
|
@ -7,7 +7,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.source.SourceManager
|
||||
import eu.kanade.tachiyomi.util.lang.chop
|
||||
import eu.kanade.tachiyomi.util.lang.removeArticles
|
||||
|
@ -185,7 +184,7 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
|
|||
category ?: recyclerView.context.getString(R.string.default_value)
|
||||
} else {
|
||||
val title = item.manga.title
|
||||
if (preferences.removeArticles().getOrDefault()) title.removeArticles().chop(15)
|
||||
if (preferences.removeArticles().get()) title.removeArticles().chop(15)
|
||||
else title.take(10)
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +250,7 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
|
|||
}
|
||||
}
|
||||
LibrarySort.Title -> {
|
||||
val title = if (preferences.removeArticles().getOrDefault()) {
|
||||
val title = if (preferences.removeArticles().get()) {
|
||||
item.manga.title.removeArticles()
|
||||
} else {
|
||||
item.manga.title
|
||||
|
|
|
@ -58,7 +58,6 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
|||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.databinding.LibraryControllerBinding
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.ui.base.MaterialMenuSheet
|
||||
|
@ -139,8 +138,8 @@ class LibraryController(
|
|||
/**
|
||||
* Position of the active category.
|
||||
*/
|
||||
private var activeCategory: Int = preferences.lastUsedCategory().getOrDefault()
|
||||
private var lastUsedCategory: Int = preferences.lastUsedCategory().getOrDefault()
|
||||
private var activeCategory: Int = preferences.lastUsedCategory().get()
|
||||
private var lastUsedCategory: Int = preferences.lastUsedCategory().get()
|
||||
|
||||
private var justStarted = true
|
||||
|
||||
|
@ -599,7 +598,7 @@ class LibraryController(
|
|||
presenter.allCategories.size <= 1 || presenter.groupType > BY_DEFAULT -> {
|
||||
updateLibrary()
|
||||
}
|
||||
preferences.updateOnRefresh().getOrDefault() == -1 -> {
|
||||
preferences.updateOnRefresh().get() == -1 -> {
|
||||
var selected = 0
|
||||
activity!!.materialAlertDialog()
|
||||
.setTitle(R.string.what_should_update)
|
||||
|
@ -633,7 +632,7 @@ class LibraryController(
|
|||
}
|
||||
}
|
||||
else -> {
|
||||
when (preferences.updateOnRefresh().getOrDefault()) {
|
||||
when (preferences.updateOnRefresh().get()) {
|
||||
0 -> updateLibrary(presenter.allCategories.first())
|
||||
else -> updateLibrary()
|
||||
}
|
||||
|
@ -1745,7 +1744,7 @@ class LibraryController(
|
|||
destroyActionModeIfNeeded()
|
||||
}
|
||||
R.id.action_migrate -> {
|
||||
val skipPre = preferences.skipPreMigration().getOrDefault()
|
||||
val skipPre = preferences.skipPreMigration().get()
|
||||
PreMigrationController.navigateToMigration(
|
||||
skipPre,
|
||||
router,
|
||||
|
|
|
@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.data.database.models.MangaCategory
|
|||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.data.preference.DelayedLibrarySuggestionsJob
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.preference.minusAssign
|
||||
import eu.kanade.tachiyomi.data.preference.plusAssign
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
|
@ -78,7 +77,7 @@ class LibraryPresenter(
|
|||
var categories: List<Category> = emptyList()
|
||||
private set
|
||||
|
||||
var removeArticles: Boolean = preferences.removeArticles().getOrDefault()
|
||||
var removeArticles: Boolean = preferences.removeArticles().get()
|
||||
|
||||
/** All categories of the library, in case they are hidden because of hide categories is on */
|
||||
var allCategories: List<Category> = emptyList()
|
||||
|
@ -97,15 +96,15 @@ class LibraryPresenter(
|
|||
get() = groupType != UNGROUPED
|
||||
|
||||
var hasActiveFilters: Boolean = run {
|
||||
val filterDownloaded = preferences.filterDownloaded().getOrDefault()
|
||||
val filterDownloaded = preferences.filterDownloaded().get()
|
||||
|
||||
val filterUnread = preferences.filterUnread().getOrDefault()
|
||||
val filterUnread = preferences.filterUnread().get()
|
||||
|
||||
val filterCompleted = preferences.filterCompleted().getOrDefault()
|
||||
val filterCompleted = preferences.filterCompleted().get()
|
||||
|
||||
val filterTracked = preferences.filterTracked().getOrDefault()
|
||||
val filterTracked = preferences.filterTracked().get()
|
||||
|
||||
val filterMangaType = preferences.filterMangaType().getOrDefault()
|
||||
val filterMangaType = preferences.filterMangaType().get()
|
||||
|
||||
!(filterDownloaded == 0 && filterUnread == 0 && filterCompleted == 0 && filterTracked == 0 && filterMangaType == 0)
|
||||
}
|
||||
|
@ -201,7 +200,7 @@ class LibraryPresenter(
|
|||
val show = showAllCategories || !libraryIsGrouped || categories.size == 1
|
||||
sectionedLibraryItems = items.groupBy { it.header.category.id!! }.toMutableMap()
|
||||
if (!show && currentCategory == -1) currentCategory = categories.find {
|
||||
it.order == preferences.lastUsedCategory().getOrDefault()
|
||||
it.order == preferences.lastUsedCategory().get()
|
||||
}?.id ?: 0
|
||||
view.onNextLibraryUpdate(
|
||||
if (!show) sectionedLibraryItems[currentCategory]
|
||||
|
@ -222,7 +221,7 @@ class LibraryPresenter(
|
|||
categories.size <= 1
|
||||
sectionedLibraryItems = items.groupBy { it.header.category.id ?: 0 }.toMutableMap()
|
||||
if (!showAll && currentCategory == -1) currentCategory = categories.find {
|
||||
it.order == preferences.lastUsedCategory().getOrDefault()
|
||||
it.order == preferences.lastUsedCategory().get()
|
||||
}?.id ?: 0
|
||||
withUIContext {
|
||||
view.onNextLibraryUpdate(
|
||||
|
@ -240,15 +239,15 @@ class LibraryPresenter(
|
|||
* @param items the items to filter.
|
||||
*/
|
||||
private fun applyFilters(items: List<LibraryItem>): List<LibraryItem> {
|
||||
val filterDownloaded = preferences.filterDownloaded().getOrDefault()
|
||||
val filterDownloaded = preferences.filterDownloaded().get()
|
||||
|
||||
val filterUnread = preferences.filterUnread().getOrDefault()
|
||||
val filterUnread = preferences.filterUnread().get()
|
||||
|
||||
val filterCompleted = preferences.filterCompleted().getOrDefault()
|
||||
val filterCompleted = preferences.filterCompleted().get()
|
||||
|
||||
val filterTracked = preferences.filterTracked().getOrDefault()
|
||||
val filterTracked = preferences.filterTracked().get()
|
||||
|
||||
val filterMangaType = preferences.filterMangaType().getOrDefault()
|
||||
val filterMangaType = preferences.filterMangaType().get()
|
||||
|
||||
val showEmptyCategoriesWhileFiltering = preferences.showEmptyCategoriesWhileFiltering().get()
|
||||
|
||||
|
@ -381,7 +380,7 @@ class LibraryPresenter(
|
|||
* @param itemList the map of manga.
|
||||
*/
|
||||
private fun setDownloadCount(itemList: List<LibraryItem>) {
|
||||
if (!preferences.downloadBadge().getOrDefault()) {
|
||||
if (!preferences.downloadBadge().get()) {
|
||||
// Unset download count if the preference is not enabled.
|
||||
for (item in itemList) {
|
||||
item.downloadCount = -1
|
||||
|
@ -421,7 +420,7 @@ class LibraryPresenter(
|
|||
if (i1.header.category.id == i2.header.category.id) {
|
||||
val category = i1.header.category
|
||||
if (category.mangaOrder.isNullOrEmpty() && category.mangaSort == null) {
|
||||
category.changeSortTo(preferences.librarySortingMode().getOrDefault())
|
||||
category.changeSortTo(preferences.librarySortingMode().get())
|
||||
if (category.id == 0) preferences.defaultMangaOrder()
|
||||
.set(category.mangaSort.toString())
|
||||
else if (!category.isDynamic) db.insertCategory(category).executeAsBlocking()
|
||||
|
@ -528,7 +527,7 @@ class LibraryPresenter(
|
|||
* @return an list of all the manga in a itemized form.
|
||||
*/
|
||||
private fun getLibraryFromDB(): List<LibraryItem> {
|
||||
removeArticles = preferences.removeArticles().getOrDefault()
|
||||
removeArticles = preferences.removeArticles().get()
|
||||
val categories = db.getCategories().executeAsBlocking().toMutableList()
|
||||
var libraryManga = db.getLibraryMangas().executeAsBlocking()
|
||||
val showAll = showAllCategories
|
||||
|
@ -539,8 +538,8 @@ class LibraryPresenter(
|
|||
val items = if (groupType <= BY_DEFAULT || !libraryIsGrouped) {
|
||||
val categoryAll = Category.createAll(
|
||||
context,
|
||||
preferences.librarySortingMode().getOrDefault(),
|
||||
preferences.librarySortingAscending().getOrDefault()
|
||||
preferences.librarySortingMode().get(),
|
||||
preferences.librarySortingAscending().get()
|
||||
)
|
||||
val catItemAll = LibraryHeaderItem({ categoryAll }, -1)
|
||||
val categorySet = mutableSetOf<Int>()
|
||||
|
@ -561,7 +560,7 @@ class LibraryPresenter(
|
|||
LibraryItem(it, headerItem)
|
||||
}.toMutableList()
|
||||
|
||||
val categoriesHidden = preferences.collapsedCategories().getOrDefault().mapNotNull {
|
||||
val categoriesHidden = preferences.collapsedCategories().get().mapNotNull {
|
||||
it.toIntOrNull()
|
||||
}.toMutableSet()
|
||||
|
||||
|
@ -678,8 +677,8 @@ class LibraryPresenter(
|
|||
var headers = tagItems.map { item ->
|
||||
Category.createCustom(
|
||||
item.key,
|
||||
preferences.librarySortingMode().getOrDefault(),
|
||||
preferences.librarySortingAscending().getOrDefault()
|
||||
preferences.librarySortingMode().get(),
|
||||
preferences.librarySortingAscending().get()
|
||||
).apply {
|
||||
id = item.value.catId
|
||||
if (name.contains(sourceSplitter)) {
|
||||
|
@ -749,7 +748,7 @@ class LibraryPresenter(
|
|||
private fun createDefaultCategory(): Category {
|
||||
val default = Category.createDefault(view.applicationContext ?: context)
|
||||
default.order = -1
|
||||
val defOrder = preferences.defaultMangaOrder().getOrDefault()
|
||||
val defOrder = preferences.defaultMangaOrder().get()
|
||||
if (defOrder.firstOrNull()?.isLetter() == true) default.mangaSort = defOrder.first()
|
||||
else default.mangaOrder = defOrder.split("/").mapNotNull { it.toLongOrNull() }
|
||||
return default
|
||||
|
@ -969,7 +968,7 @@ class LibraryPresenter(
|
|||
fun toggleCategoryVisibility(categoryId: Int) {
|
||||
// if (categories.find { it.id == categoryId }?.isDynamic == true) return
|
||||
if (groupType == BY_DEFAULT) {
|
||||
val categoriesHidden = preferences.collapsedCategories().getOrDefault().mapNotNull {
|
||||
val categoriesHidden = preferences.collapsedCategories().get().mapNotNull {
|
||||
it.toIntOrNull()
|
||||
}.toMutableSet()
|
||||
if (categoryId in categoriesHidden) {
|
||||
|
@ -1027,7 +1026,7 @@ class LibraryPresenter(
|
|||
|
||||
fun allCategoriesExpanded(): Boolean {
|
||||
return if (groupType == BY_DEFAULT) {
|
||||
preferences.collapsedCategories().getOrDefault().isEmpty()
|
||||
preferences.collapsedCategories().get().isEmpty()
|
||||
} else {
|
||||
categories.none { it.isHidden }
|
||||
}
|
||||
|
@ -1042,7 +1041,7 @@ class LibraryPresenter(
|
|||
downloadManager.downloadChapters(it, chapters)
|
||||
}
|
||||
}
|
||||
if (preferences.downloadBadge().getOrDefault()) {
|
||||
if (preferences.downloadBadge().get()) {
|
||||
requestDownloadBadgesUpdate()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,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.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.databinding.FilterBottomSheetBinding
|
||||
import eu.kanade.tachiyomi.ui.library.LibraryController
|
||||
|
@ -249,14 +248,15 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
|
|||
}
|
||||
}
|
||||
|
||||
fun hasActiveFilters() = filterItems.any { it.isActivated }
|
||||
private fun hasActiveFilters() = filterItems.any { it.isActivated }
|
||||
|
||||
private fun hasActiveFiltersFromPref(): Boolean {
|
||||
return preferences.filterDownloaded().getOrDefault() > 0 || preferences.filterUnread()
|
||||
.getOrDefault() > 0 || preferences.filterCompleted()
|
||||
.getOrDefault() > 0 || preferences.filterTracked()
|
||||
.getOrDefault() > 0 || preferences.filterMangaType()
|
||||
.getOrDefault() > 0 || FILTER_TRACKER.isNotEmpty()
|
||||
return preferences.filterDownloaded().get() > 0 ||
|
||||
preferences.filterUnread().get() > 0 ||
|
||||
preferences.filterCompleted().get() > 0 ||
|
||||
preferences.filterTracked().get() > 0 ||
|
||||
preferences.filterMangaType().get() > 0 ||
|
||||
FILTER_TRACKER.isNotEmpty()
|
||||
}
|
||||
|
||||
private fun createTags() {
|
||||
|
@ -312,7 +312,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
|
|||
withContext(Dispatchers.Main) {
|
||||
downloaded.setState(preferences.filterDownloaded())
|
||||
completed.setState(preferences.filterCompleted())
|
||||
val unreadP = preferences.filterUnread().getOrDefault()
|
||||
val unreadP = preferences.filterUnread().get()
|
||||
if (unreadP <= 2) {
|
||||
unread.state = unreadP - 1
|
||||
} else if (unreadP >= 3) {
|
||||
|
@ -320,7 +320,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
|
|||
}
|
||||
tracked?.setState(preferences.filterTracked())
|
||||
mangaType?.setState(
|
||||
when (preferences.filterMangaType().getOrDefault()) {
|
||||
when (preferences.filterMangaType().get()) {
|
||||
Manga.TYPE_MANGA -> context.getString(R.string.manga)
|
||||
Manga.TYPE_MANHUA -> context.getString(R.string.manhua)
|
||||
Manga.TYPE_MANHWA -> context.getString(R.string.manhwa)
|
||||
|
|
|
@ -6,9 +6,8 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.view.isVisible
|
||||
import com.f2prateek.rx.preferences.Preference
|
||||
import com.tfcporciuncula.flow.Preference
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.databinding.FilterTagGroupBinding
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
|
@ -82,7 +81,7 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute
|
|||
set(index) = toggleButton(index, false)
|
||||
|
||||
fun setState(preference: Preference<Int>) {
|
||||
state = preference.getOrDefault() - 1
|
||||
state = preference.get() - 1
|
||||
}
|
||||
|
||||
fun setState(text: String) {
|
||||
|
|
|
@ -53,7 +53,6 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
|||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.updater.UpdateChecker
|
||||
import eu.kanade.tachiyomi.data.updater.UpdateResult
|
||||
import eu.kanade.tachiyomi.data.updater.UpdaterNotifier
|
||||
|
@ -583,7 +582,7 @@ open class MainActivity : BaseActivity<MainActivityBinding>(), DownloadServiceLi
|
|||
|
||||
fun getExtensionUpdates(force: Boolean) {
|
||||
if ((force && extensionManager.availableExtensions.isEmpty()) ||
|
||||
Date().time >= preferences.lastExtCheck().getOrDefault() + TimeUnit.HOURS.toMillis(6)
|
||||
Date().time >= preferences.lastExtCheck().get() + TimeUnit.HOURS.toMillis(6)
|
||||
) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
|
|
|
@ -53,7 +53,6 @@ import eu.kanade.tachiyomi.data.download.DownloadService
|
|||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.data.image.coil.getBestColor
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||
import eu.kanade.tachiyomi.databinding.MangaDetailsControllerBinding
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
|
@ -997,7 +996,7 @@ class MangaDetailsController :
|
|||
R.id.action_migrate ->
|
||||
if (!isNotOnline()) {
|
||||
PreMigrationController.navigateToMigration(
|
||||
presenter.preferences.skipPreMigration().getOrDefault(),
|
||||
presenter.preferences.skipPreMigration().get(),
|
||||
router,
|
||||
listOf(manga!!.id!!)
|
||||
)
|
||||
|
|
|
@ -8,7 +8,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.MigrationControllerBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.ui.migration.manga.design.PreMigrationController
|
||||
|
@ -97,7 +96,7 @@ class MigrationController :
|
|||
|
||||
if (item is MangaItem) {
|
||||
PreMigrationController.navigateToMigration(
|
||||
Injekt.get<PreferencesHelper>().skipPreMigration().getOrDefault(),
|
||||
Injekt.get<PreferencesHelper>().skipPreMigration().get(),
|
||||
router,
|
||||
listOf(item.manga.id!!)
|
||||
)
|
||||
|
@ -118,7 +117,7 @@ class MigrationController :
|
|||
manga.asSequence().filter { it.source == item.source.id }.map { it.id!! }.toList()
|
||||
withContext(Dispatchers.Main) {
|
||||
PreMigrationController.navigateToMigration(
|
||||
Injekt.get<PreferencesHelper>().skipPreMigration().getOrDefault(),
|
||||
Injekt.get<PreferencesHelper>().skipPreMigration().get(),
|
||||
router,
|
||||
sourceMangas
|
||||
)
|
||||
|
|
|
@ -6,7 +6,6 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||
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.LocalSource
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
|
@ -94,7 +93,7 @@ class MigrationPresenter(
|
|||
manga: Manga,
|
||||
replace: Boolean
|
||||
) {
|
||||
val flags = preferences.migrateFlags().getOrDefault()
|
||||
val flags = preferences.migrateFlags().get()
|
||||
val migrateChapters = MigrationFlags.hasChapters(flags)
|
||||
val migrateCategories = MigrationFlags.hasCategories(flags)
|
||||
val migrateTracks = MigrationFlags.hasTracks(flags)
|
||||
|
|
|
@ -12,10 +12,9 @@ import android.widget.Toast
|
|||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.view.isVisible
|
||||
import com.bluelinelabs.conductor.Controller
|
||||
import com.f2prateek.rx.preferences.Preference
|
||||
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.databinding.MigrationBottomSheetBinding
|
||||
import eu.kanade.tachiyomi.ui.migration.MigrationFlags
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
|
@ -91,7 +90,7 @@ class MigrationBottomSheetDialog(
|
|||
* Init general reader preferences.
|
||||
*/
|
||||
private fun initPreferences() {
|
||||
val flags = preferences.migrateFlags().getOrDefault()
|
||||
val flags = preferences.migrateFlags().get()
|
||||
|
||||
binding.migChapters.isChecked = MigrationFlags.hasChapters(flags)
|
||||
binding.migCategories.isChecked = MigrationFlags.hasCategories(flags)
|
||||
|
@ -111,7 +110,7 @@ class MigrationBottomSheetDialog(
|
|||
}
|
||||
binding.sourceGroup.bindToPreference(preferences.useSourceWithMost())
|
||||
|
||||
binding.skipStep.isChecked = preferences.skipPreMigration().getOrDefault()
|
||||
binding.skipStep.isChecked = preferences.skipPreMigration().get()
|
||||
binding.skipStep.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) (listener as? Controller)?.activity?.toast(
|
||||
R.string.to_show_again_setting_sources,
|
||||
|
@ -132,7 +131,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) }
|
||||
}
|
||||
|
||||
|
@ -140,7 +139,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)
|
||||
|
|
|
@ -18,7 +18,6 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.toMangaInfo
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.databinding.MigrationListControllerBinding
|
||||
import eu.kanade.tachiyomi.smartsearch.SmartSearchEngine
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
|
@ -123,7 +122,7 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||
}
|
||||
|
||||
private suspend fun runMigrations(mangas: List<MigratingManga>) {
|
||||
val useSourceWithMost = preferences.useSourceWithMost().getOrDefault()
|
||||
val useSourceWithMost = preferences.useSourceWithMost().get()
|
||||
|
||||
val sources = preferences.migrationSources().get().split("/").mapNotNull {
|
||||
val value = it.toLongOrNull() ?: return
|
||||
|
|
|
@ -7,7 +7,6 @@ import eu.kanade.tachiyomi.data.database.models.History
|
|||
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.ui.migration.MigrationFlags
|
||||
import eu.kanade.tachiyomi.util.system.launchUI
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -106,7 +105,7 @@ class MigrationProcessAdapter(
|
|||
replace: Boolean
|
||||
) {
|
||||
if (controller.config == null) return
|
||||
val flags = preferences.migrateFlags().getOrDefault()
|
||||
val flags = preferences.migrateFlags().get()
|
||||
// Update chapters read
|
||||
if (MigrationFlags.hasChapters(flags)) {
|
||||
val prevMangaChapters = db.getChapters(prevManga).executeAsBlocking()
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.content.Intent
|
|||
import android.view.WindowManager
|
||||
import androidx.biometric.BiometricManager
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.ui.main.SearchActivity
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Date
|
||||
|
@ -18,7 +17,7 @@ object SecureActivityDelegate {
|
|||
var isAuthenticating: Boolean = false
|
||||
|
||||
fun setSecure(activity: Activity?, force: Boolean? = null) {
|
||||
val enabled = force ?: preferences.secureScreen().getOrDefault()
|
||||
val enabled = force ?: preferences.secureScreen().get()
|
||||
if (enabled) {
|
||||
activity?.window?.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_SECURE,
|
||||
|
@ -31,7 +30,7 @@ object SecureActivityDelegate {
|
|||
|
||||
fun promptLockIfNeeded(activity: Activity?) {
|
||||
if (activity == null || isAuthenticating) return
|
||||
val lockApp = preferences.useBiometrics().getOrDefault()
|
||||
val lockApp = preferences.useBiometrics().get()
|
||||
if (lockApp && BiometricManager.from(activity).canAuthenticate(BiometricManager.Authenticators.DEVICE_CREDENTIAL or BiometricManager.Authenticators.BIOMETRIC_WEAK) == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
if (isAppLocked()) {
|
||||
val intent = Intent(activity, BiometricActivity::class.java)
|
||||
|
@ -45,7 +44,7 @@ object SecureActivityDelegate {
|
|||
}
|
||||
|
||||
fun shouldBeLocked(): Boolean {
|
||||
val lockApp = preferences.useBiometrics().getOrDefault()
|
||||
val lockApp = preferences.useBiometrics().get()
|
||||
if (lockApp && isAppLocked()) return true
|
||||
return false
|
||||
}
|
||||
|
@ -53,9 +52,9 @@ object SecureActivityDelegate {
|
|||
private fun isAppLocked(): Boolean {
|
||||
return locked &&
|
||||
(
|
||||
preferences.lockAfter().getOrDefault() <= 0 ||
|
||||
Date().time >= preferences.lastUnlock().getOrDefault() + 60 * 1000 * preferences
|
||||
.lockAfter().getOrDefault()
|
||||
preferences.lockAfter().get() <= 0 ||
|
||||
Date().time >= preferences.lastUnlock().get() + 60 * 1000 * preferences
|
||||
.lockAfter().get()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.R
|
|||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.updater.AutoUpdaterJob
|
||||
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
|
@ -94,7 +93,7 @@ class SettingsBrowseController : SettingsController() {
|
|||
titleRes = R.string.source_migration
|
||||
onClick { router.pushController(MigrationController().withFadeTransaction()) }
|
||||
}
|
||||
if (preferences.skipPreMigration().getOrDefault() || preferences.migrationSources()
|
||||
if (preferences.skipPreMigration().get() || preferences.migrationSources()
|
||||
.isSet()
|
||||
) {
|
||||
switchPreference {
|
||||
|
|
|
@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.util.system.getFilePicker
|
||||
import eu.kanade.tachiyomi.util.system.withOriginalWidth
|
||||
import uy.kohesive.injekt.Injekt
|
||||
|
@ -38,11 +37,10 @@ class SettingsDownloadController : SettingsController() {
|
|||
DownloadDirectoriesDialog(this@SettingsDownloadController).show()
|
||||
}
|
||||
|
||||
preferences.downloadsDirectory().asObservable()
|
||||
.subscribeUntilDestroy { path ->
|
||||
val dir = UniFile.fromUri(context, path.toUri())
|
||||
summary = dir.filePath ?: path
|
||||
}
|
||||
preferences.downloadsDirectory().asImmediateFlowIn(viewScope) { path ->
|
||||
val dir = UniFile.fromUri(context, path.toUri())
|
||||
summary = dir.filePath ?: path
|
||||
}
|
||||
}
|
||||
switchPreference {
|
||||
key = Keys.downloadOnlyOverWifi
|
||||
|
@ -154,7 +152,7 @@ class SettingsDownloadController : SettingsController() {
|
|||
val activity = controller.activity!!
|
||||
|
||||
init {
|
||||
val currentDir = preferences.downloadsDirectory().getOrDefault()
|
||||
val currentDir = preferences.downloadsDirectory().get()
|
||||
val externalDirs =
|
||||
getExternalDirs() + File(activity.getString(R.string.custom_location))
|
||||
val selectedIndex = externalDirs.map(File::toString).indexOfFirst { it in currentDir }
|
||||
|
|
|
@ -6,6 +6,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
||||
import eu.kanade.tachiyomi.data.preference.DelayedLibrarySuggestionsJob
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
|
||||
import eu.kanade.tachiyomi.ui.category.CategoryController
|
||||
import eu.kanade.tachiyomi.ui.library.LibraryPresenter
|
||||
import eu.kanade.tachiyomi.ui.library.display.TabbedLibraryDisplaySheet
|
||||
|
@ -132,8 +133,9 @@ class SettingsLibraryController : SettingsController() {
|
|||
preSummaryRes = R.string.restrictions_
|
||||
noSelectionRes = R.string.none
|
||||
|
||||
preferences.libraryUpdateInterval().asObservable()
|
||||
.subscribeUntilDestroy { isVisible = it > 0 }
|
||||
preferences.libraryUpdateInterval().asImmediateFlowIn(viewScope) {
|
||||
isVisible = it > 0
|
||||
}
|
||||
|
||||
onChange {
|
||||
// Post to event looper to allow the preference to be updated.
|
||||
|
|
|
@ -4,7 +4,6 @@ import androidx.biometric.BiometricManager
|
|||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||
import eu.kanade.tachiyomi.widget.preference.IntListMatPreference
|
||||
|
||||
|
@ -28,7 +27,7 @@ class SettingsSecurityController : SettingsController() {
|
|||
preference = intListPreference(activity) {
|
||||
key = PreferenceKeys.lockAfter
|
||||
titleRes = R.string.lock_when_idle
|
||||
isVisible = preferences.useBiometrics().getOrDefault()
|
||||
isVisible = preferences.useBiometrics().get()
|
||||
val values = listOf(0, 2, 5, 10, 20, 30, 60, 90, 120, -1)
|
||||
entries = values.mapNotNull {
|
||||
when (it) {
|
||||
|
|
|
@ -10,7 +10,6 @@ import androidx.preference.PreferenceGroup
|
|||
import androidx.preference.PreferenceScreen
|
||||
import com.jakewharton.rxbinding.support.v7.widget.queryTextChanges
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.preference.minusAssign
|
||||
import eu.kanade.tachiyomi.data.preference.plusAssign
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
|
@ -38,7 +37,7 @@ class SettingsSourcesController : SettingsController() {
|
|||
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
|
||||
titleRes = R.string.filter
|
||||
sorting = SourcesSort.from(preferences.sourceSorting().getOrDefault()) ?: SourcesSort.Alpha
|
||||
sorting = SourcesSort.from(preferences.sourceSorting().get()) ?: SourcesSort.Alpha
|
||||
activity?.invalidateOptionsMenu()
|
||||
// Get the list of active language codes.
|
||||
val activeLangsCodes = preferences.enabledLanguages().get()
|
||||
|
|
|
@ -5,35 +5,8 @@ import android.widget.CompoundButton
|
|||
import android.widget.RadioButton
|
||||
import android.widget.RadioGroup
|
||||
import android.widget.Spinner
|
||||
import androidx.annotation.ArrayRes
|
||||
import com.f2prateek.rx.preferences.Preference
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import com.tfcporciuncula.flow.Preference
|
||||
import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
inline fun <reified T> SharedPreferences.getKey(key: String, default: T, dispatcher: CoroutineContext = Dispatchers.Default): Flow<T> {
|
||||
val flow: Flow<T> = channelFlow {
|
||||
offer(getItem(key, default))
|
||||
|
||||
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, k ->
|
||||
if (key == k) {
|
||||
offer(getItem(key, default)!!)
|
||||
}
|
||||
}
|
||||
|
||||
registerOnSharedPreferenceChangeListener(listener)
|
||||
awaitClose { unregisterOnSharedPreferenceChangeListener(listener) }
|
||||
}
|
||||
return flow
|
||||
.flowOn(dispatcher)
|
||||
}
|
||||
|
||||
inline fun <reified T> SharedPreferences.getItem(key: String, default: T): T {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
@ -52,22 +25,7 @@ inline fun <reified T> SharedPreferences.getItem(key: String, default: T): T {
|
|||
/**
|
||||
* Binds a checkbox or switch view with a boolean preference.
|
||||
*/
|
||||
fun CompoundButton.bindToPreference(pref: Preference<Boolean>, block: (() -> Unit)? = null) {
|
||||
isChecked = pref.getOrDefault()
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
pref.set(isChecked)
|
||||
block?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a checkbox or switch view with a boolean preference.
|
||||
*/
|
||||
fun CompoundButton.bindToPreference(
|
||||
pref: com.tfcporciuncula.flow
|
||||
.Preference<Boolean>,
|
||||
block: ((Boolean) -> Unit)? = null
|
||||
) {
|
||||
fun CompoundButton.bindToPreference(pref: Preference<Boolean>, block: ((Boolean) -> Unit)? = null) {
|
||||
isChecked = pref.get()
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
pref.set(isChecked)
|
||||
|
@ -79,18 +37,6 @@ fun CompoundButton.bindToPreference(
|
|||
* Binds a radio group with a int preference.
|
||||
*/
|
||||
fun RadioGroup.bindToPreference(pref: Preference<Int>, block: (() -> Unit)? = null) {
|
||||
(getChildAt(pref.getOrDefault()) as RadioButton).isChecked = true
|
||||
setOnCheckedChangeListener { _, checkedId ->
|
||||
val index = indexOfChild(findViewById(checkedId))
|
||||
pref.set(index)
|
||||
block?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a radio group with a int preference.
|
||||
*/
|
||||
fun RadioGroup.bindToPreference(pref: com.tfcporciuncula.flow.Preference<Int>, block: (() -> Unit)? = null) {
|
||||
(getChildAt(pref.get()) as RadioButton).isChecked = true
|
||||
setOnCheckedChangeListener { _, checkedId ->
|
||||
val index = indexOfChild(findViewById(checkedId))
|
||||
|
@ -103,7 +49,7 @@ fun RadioGroup.bindToPreference(pref: com.tfcporciuncula.flow.Preference<Int>, b
|
|||
* Binds a spinner to an int preference with an optional offset for the value.
|
||||
*/
|
||||
fun Spinner.bindToPreference(
|
||||
pref: com.tfcporciuncula.flow.Preference<Int>,
|
||||
pref: Preference<Int>,
|
||||
offset: Int = 0
|
||||
) {
|
||||
onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
|
||||
|
@ -111,16 +57,3 @@ fun Spinner.bindToPreference(
|
|||
}
|
||||
setSelection(pref.get() - offset, false)
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a spinner to an int preference. The position of the spinner item must
|
||||
* correlate with the [intValues] resource item (in arrays.xml), which is a <string-array>
|
||||
* of int values that will be parsed here and applied to the preference.
|
||||
*/
|
||||
fun Spinner.bindToIntPreference(pref: com.tfcporciuncula.flow.Preference<Int>, @ArrayRes intValuesResource: Int) {
|
||||
val intValues = resources.getStringArray(intValuesResource).map { it.toIntOrNull() }
|
||||
onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
|
||||
pref.set(intValues[position] ?: 0)
|
||||
}
|
||||
setSelection(intValues.indexOf(pref.get()), false)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.app.Activity
|
|||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
|
||||
class IntListMatPreference @JvmOverloads constructor(
|
||||
activity: Activity?,
|
||||
|
@ -26,7 +25,7 @@ class IntListMatPreference @JvmOverloads constructor(
|
|||
var customSelectedValue: Int? = null
|
||||
|
||||
override var customSummaryProvider: SummaryProvider<MatPreference>? = SummaryProvider<MatPreference> {
|
||||
val index = entryValues.indexOf(prefs.getInt(key, defValue).getOrDefault())
|
||||
val index = entryValues.indexOf(prefs.getInt(key, defValue).get())
|
||||
if (entries.isEmpty() || index == -1) ""
|
||||
else entries[index]
|
||||
}
|
||||
|
@ -38,7 +37,7 @@ class IntListMatPreference @JvmOverloads constructor(
|
|||
|
||||
override fun dialog(): MaterialAlertDialogBuilder {
|
||||
return super.dialog().apply {
|
||||
val default = entryValues.indexOf(customSelectedValue ?: prefs.getInt(key, defValue).getOrDefault())
|
||||
val default = entryValues.indexOf(customSelectedValue ?: prefs.getInt(key, defValue).get())
|
||||
setSingleChoiceItems(entries.toTypedArray(), default) { dialog, pos ->
|
||||
val value = entryValues[pos]
|
||||
if (key != null) {
|
||||
|
@ -48,14 +47,6 @@ class IntListMatPreference @JvmOverloads constructor(
|
|||
notifyChanged()
|
||||
dialog.dismiss()
|
||||
}
|
||||
// listItemsSingleChoice(
|
||||
// items = entries,
|
||||
// waitForPositiveButton = false,
|
||||
// initialSelection = default
|
||||
// ) {
|
||||
// _, pos, _ ->
|
||||
//
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.Context
|
|||
import android.util.AttributeSet
|
||||
import androidx.preference.Preference
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
|
||||
open class ListMatPreference @JvmOverloads constructor(
|
||||
activity: Activity?,
|
||||
|
@ -31,7 +30,7 @@ open class ListMatPreference @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
override var customSummaryProvider: SummaryProvider<MatPreference>? = SummaryProvider<MatPreference> {
|
||||
val index = entryValues.indexOf(prefs.getStringPref(key, defValue).getOrDefault())
|
||||
val index = entryValues.indexOf(prefs.getStringPref(key, defValue).get())
|
||||
if (entries.isEmpty() || index == -1) ""
|
||||
else entries[index]
|
||||
}
|
||||
|
@ -48,7 +47,7 @@ open class ListMatPreference @JvmOverloads constructor(
|
|||
if (sharedPref != null) {
|
||||
val settings = context.getSharedPreferences(sharedPref, Context.MODE_PRIVATE)
|
||||
settings.getString(key, "")
|
||||
} else prefs.getStringPref(key, defValue).getOrDefault()
|
||||
} else prefs.getStringPref(key, defValue).get()
|
||||
)
|
||||
setSingleChoiceItems(entries.toTypedArray(), default) { dialog, pos ->
|
||||
val value = entryValues[pos]
|
||||
|
|
|
@ -8,7 +8,6 @@ import androidx.appcompat.app.AlertDialog
|
|||
import androidx.appcompat.widget.AppCompatCheckedTextView
|
||||
import androidx.core.view.children
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.util.system.disableItems
|
||||
|
||||
class MultiListMatPreference @JvmOverloads constructor(
|
||||
|
@ -44,7 +43,7 @@ class MultiListMatPreference @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
override var customSummaryProvider: SummaryProvider<MatPreference>? = SummaryProvider<MatPreference> {
|
||||
var values = prefs.getStringSet(key, defValue).getOrDefault().mapNotNull { value ->
|
||||
var values = prefs.getStringSet(key, defValue).get().mapNotNull { value ->
|
||||
entryValues.indexOf(value).takeUnless { it == -1 }
|
||||
}.toIntArray().sorted().map { entries[it] }
|
||||
allSelectionRes?.let { allRes ->
|
||||
|
@ -64,7 +63,7 @@ class MultiListMatPreference @JvmOverloads constructor(
|
|||
|
||||
@SuppressLint("CheckResult")
|
||||
override fun MaterialAlertDialogBuilder.setListItems() {
|
||||
val set = prefs.getStringSet(key, defValue).getOrDefault()
|
||||
val set = prefs.getStringSet(key, defValue).get()
|
||||
val items = if (allSelectionRes != null) {
|
||||
if (showAllLast) entries + listOf(context.getString(allSelectionRes!!))
|
||||
else listOf(context.getString(allSelectionRes!!)) + entries
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.util.AttributeSet
|
|||
import androidx.core.text.buildSpannedString
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.util.system.setTriStateItems
|
||||
import eu.kanade.tachiyomi.widget.TriStateCheckBox
|
||||
|
||||
|
@ -44,7 +43,7 @@ class TriStateListPreference @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
override var customSummaryProvider: SummaryProvider<MatPreference>? = SummaryProvider<MatPreference> {
|
||||
var includedStrings = prefs.getStringSet(key, defValue).getOrDefault().mapNotNull { value ->
|
||||
var includedStrings = prefs.getStringSet(key, defValue).get().mapNotNull { value ->
|
||||
entryValues.indexOf(value).takeUnless { it == -1 }
|
||||
}.toIntArray().sorted().map { entries[it] }
|
||||
allSelectionRes?.let { allRes ->
|
||||
|
@ -57,7 +56,7 @@ class TriStateListPreference @JvmOverloads constructor(
|
|||
}
|
||||
}
|
||||
val excludedStrings = excludeKey?.let {
|
||||
prefs.getStringSet(it, defValue).getOrDefault().mapNotNull { value ->
|
||||
prefs.getStringSet(it, defValue).get().mapNotNull { value ->
|
||||
entryValues.indexOf(value).takeUnless {
|
||||
it == -1
|
||||
}
|
||||
|
@ -73,14 +72,14 @@ class TriStateListPreference @JvmOverloads constructor(
|
|||
|
||||
@SuppressLint("CheckResult")
|
||||
override fun MaterialAlertDialogBuilder.setListItems() {
|
||||
val set = prefs.getStringSet(key, defValue).getOrDefault()
|
||||
val set = prefs.getStringSet(key, defValue).get()
|
||||
val items = if (allSelectionRes != null) {
|
||||
if (showAllLast) entries + listOf(context.getString(allSelectionRes!!))
|
||||
else listOf(context.getString(allSelectionRes!!)) + entries
|
||||
} else entries
|
||||
val allPos = if (showAllLast) items.size - 1 else 0
|
||||
val excludedSet = excludeKey?.let {
|
||||
prefs.getStringSet(it, defValue).getOrDefault()
|
||||
prefs.getStringSet(it, defValue).get()
|
||||
}.orEmpty()
|
||||
val allValue = intArrayOf(
|
||||
if (set.isEmpty()) TriStateCheckBox.State.CHECKED.ordinal
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue