More FlowPreference migration

This commit is contained in:
arkon 2020-04-23 23:21:44 -04:00
parent 77cca1ce84
commit d98b7275d1
12 changed files with 78 additions and 74 deletions

View file

@ -30,7 +30,7 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
fun setupTask(context: Context, prefInterval: Int? = null) { fun setupTask(context: Context, prefInterval: Int? = null) {
val preferences = Injekt.get<PreferencesHelper>() val preferences = Injekt.get<PreferencesHelper>()
val interval = prefInterval ?: preferences.backupInterval().getOrDefault() val interval = prefInterval ?: preferences.backupInterval().get()
if (interval > 0) { if (interval > 0) {
val request = PeriodicWorkRequestBuilder<BackupCreatorJob>( val request = PeriodicWorkRequestBuilder<BackupCreatorJob>(
interval.toLong(), TimeUnit.HOURS, interval.toLong(), TimeUnit.HOURS,

View file

@ -45,7 +45,6 @@ import eu.kanade.tachiyomi.data.database.models.MangaImpl
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.database.models.TrackImpl import eu.kanade.tachiyomi.data.database.models.TrackImpl
import eu.kanade.tachiyomi.data.preference.PreferencesHelper 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.TrackManager
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
@ -499,5 +498,5 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
* *
* @return number of backups selected by user * @return number of backups selected by user
*/ */
fun numberOfBackups(): Int = preferences.numberOfBackups().getOrDefault() fun numberOfBackups(): Int = preferences.numberOfBackups().get()
} }

View file

@ -9,7 +9,6 @@ import androidx.work.WorkManager
import androidx.work.Worker import androidx.work.Worker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -27,7 +26,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
fun setupTask(context: Context, prefInterval: Int? = null) { fun setupTask(context: Context, prefInterval: Int? = null) {
val preferences = Injekt.get<PreferencesHelper>() val preferences = Injekt.get<PreferencesHelper>()
val interval = prefInterval ?: preferences.libraryUpdateInterval().getOrDefault() val interval = prefInterval ?: preferences.libraryUpdateInterval().get()
if (interval > 0) { if (interval > 0) {
val restrictions = preferences.libraryUpdateRestriction()!! val restrictions = preferences.libraryUpdateRestriction()!!
val acRestriction = "ac" in restrictions val acRestriction = "ac" in restrictions

View file

@ -28,7 +28,6 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper 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.TrackManager
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
@ -227,7 +226,7 @@ class LibraryUpdateService(
// Update favorite manga. Destroy service when completed or in case of an error. // Update favorite manga. Destroy service when completed or in case of an error.
subscription = Observable subscription = Observable
.defer { .defer {
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault() val selectedScheme = preferences.libraryUpdatePrioritization().get()
val mangaList = getMangaToUpdate(intent, target) val mangaList = getMangaToUpdate(intent, target)
.sortedWith(rankingScheme[selectedScheme]) .sortedWith(rankingScheme[selectedScheme])
@ -263,7 +262,7 @@ class LibraryUpdateService(
var listToUpdate = if (categoryId != -1) var listToUpdate = if (categoryId != -1)
db.getLibraryMangas().executeAsBlocking().filter { it.category == categoryId } db.getLibraryMangas().executeAsBlocking().filter { it.category == categoryId }
else { else {
val categoriesToUpdate = preferences.libraryUpdateCategories().getOrDefault().map(String::toInt) val categoriesToUpdate = preferences.libraryUpdateCategories().get().map(String::toInt)
if (categoriesToUpdate.isNotEmpty()) if (categoriesToUpdate.isNotEmpty())
db.getLibraryMangas().executeAsBlocking() db.getLibraryMangas().executeAsBlocking()
.filter { it.category in categoriesToUpdate } .filter { it.category in categoriesToUpdate }
@ -295,9 +294,9 @@ class LibraryUpdateService(
// List containing failed updates // List containing failed updates
val failedUpdates = ArrayList<Manga>() val failedUpdates = ArrayList<Manga>()
// List containing categories that get included in downloads. // List containing categories that get included in downloads.
val categoriesToDownload = preferences.downloadNewCategories().getOrDefault().map(String::toInt) val categoriesToDownload = preferences.downloadNewCategories().get().map(String::toInt)
// Boolean to determine if user wants to automatically download new chapters. // Boolean to determine if user wants to automatically download new chapters.
val downloadNew = preferences.downloadNew().getOrDefault() val downloadNew = preferences.downloadNew().get()
// Boolean to determine if DownloadManager has downloads // Boolean to determine if DownloadManager has downloads
var hasDownloads = false var hasDownloads = false

View file

@ -165,37 +165,37 @@ class PreferencesHelper(val context: Context) {
fun downloadOnlyOverWifi() = prefs.getBoolean(Keys.downloadOnlyOverWifi, true) fun downloadOnlyOverWifi() = prefs.getBoolean(Keys.downloadOnlyOverWifi, true)
fun numberOfBackups() = rxPrefs.getInteger(Keys.numberOfBackups, 1) fun numberOfBackups() = flowPrefs.getInt(Keys.numberOfBackups, 1)
fun backupInterval() = rxPrefs.getInteger(Keys.backupInterval, 0) fun backupInterval() = flowPrefs.getInt(Keys.backupInterval, 0)
fun removeAfterReadSlots() = prefs.getInt(Keys.removeAfterReadSlots, -1) fun removeAfterReadSlots() = prefs.getInt(Keys.removeAfterReadSlots, -1)
fun removeAfterMarkedAsRead() = prefs.getBoolean(Keys.removeAfterMarkedAsRead, false) fun removeAfterMarkedAsRead() = prefs.getBoolean(Keys.removeAfterMarkedAsRead, false)
fun libraryUpdateInterval() = rxPrefs.getInteger(Keys.libraryUpdateInterval, 0) fun libraryUpdateInterval() = flowPrefs.getInt(Keys.libraryUpdateInterval, 0)
fun libraryUpdateRestriction() = prefs.getStringSet(Keys.libraryUpdateRestriction, emptySet()) fun libraryUpdateRestriction() = prefs.getStringSet(Keys.libraryUpdateRestriction, emptySet())
fun libraryUpdateCategories() = rxPrefs.getStringSet(Keys.libraryUpdateCategories, emptySet()) fun libraryUpdateCategories() = flowPrefs.getStringSet(Keys.libraryUpdateCategories, emptySet())
fun libraryUpdatePrioritization() = rxPrefs.getInteger(Keys.libraryUpdatePrioritization, 0) fun libraryUpdatePrioritization() = flowPrefs.getInt(Keys.libraryUpdatePrioritization, 0)
fun libraryAsList() = rxPrefs.getBoolean(Keys.libraryAsList, false) fun libraryAsList() = flowPrefs.getBoolean(Keys.libraryAsList, false)
fun downloadBadge() = rxPrefs.getBoolean(Keys.downloadBadge, false) fun downloadBadge() = flowPrefs.getBoolean(Keys.downloadBadge, false)
fun downloadedOnly() = flowPrefs.getBoolean(Keys.downloadedOnly, false) fun downloadedOnly() = flowPrefs.getBoolean(Keys.downloadedOnly, false)
fun filterDownloaded() = rxPrefs.getBoolean(Keys.filterDownloaded, false) fun filterDownloaded() = flowPrefs.getBoolean(Keys.filterDownloaded, false)
fun filterUnread() = rxPrefs.getBoolean(Keys.filterUnread, false) fun filterUnread() = flowPrefs.getBoolean(Keys.filterUnread, false)
fun filterCompleted() = rxPrefs.getBoolean(Keys.filterCompleted, false) fun filterCompleted() = flowPrefs.getBoolean(Keys.filterCompleted, 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 automaticUpdates() = prefs.getBoolean(Keys.automaticUpdates, true) fun automaticUpdates() = prefs.getBoolean(Keys.automaticUpdates, true)
@ -209,9 +209,9 @@ class PreferencesHelper(val context: Context) {
fun pinnedCatalogues() = flowPrefs.getStringSet("pinned_catalogues", emptySet()) fun pinnedCatalogues() = flowPrefs.getStringSet("pinned_catalogues", emptySet())
fun downloadNew() = rxPrefs.getBoolean(Keys.downloadNew, false) fun downloadNew() = flowPrefs.getBoolean(Keys.downloadNew, false)
fun downloadNewCategories() = rxPrefs.getStringSet(Keys.downloadNewCategories, emptySet()) fun downloadNewCategories() = flowPrefs.getStringSet(Keys.downloadNewCategories, emptySet())
fun lang() = prefs.getString(Keys.lang, "") fun lang() = prefs.getString(Keys.lang, "")

View file

@ -13,7 +13,6 @@ import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.library.LibraryUpdateService
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.util.lang.plusAssign import eu.kanade.tachiyomi.util.lang.plusAssign
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.inflate import eu.kanade.tachiyomi.util.view.inflate
@ -67,7 +66,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
fun onCreate(controller: LibraryController) { fun onCreate(controller: LibraryController) {
this.controller = controller this.controller = controller
recycler = if (preferences.libraryAsList().getOrDefault()) { recycler = if (preferences.libraryAsList().get()) {
(swipe_refresh.inflate(R.layout.library_list_recycler) as RecyclerView).apply { (swipe_refresh.inflate(R.layout.library_list_recycler) as RecyclerView).apply {
layoutManager = LinearLayoutManager(context) layoutManager = LinearLayoutManager(context)
} }

View file

@ -5,14 +5,13 @@ import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.f2prateek.rx.preferences.Preference import com.tfcporciuncula.flow.Preference
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFilterable import eu.davidea.flexibleadapter.items.IFilterable
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.LibraryManga
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.widget.AutofitRecyclerView import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import kotlinx.android.synthetic.main.source_grid_item.view.card import kotlinx.android.synthetic.main.source_grid_item.view.card
@ -28,7 +27,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference
var downloadCount = -1 var downloadCount = -1
override fun getLayoutRes(): Int { override fun getLayoutRes(): Int {
return if (libraryAsList.getOrDefault()) return if (libraryAsList.get())
R.layout.source_list_item R.layout.source_list_item
else else
R.layout.source_grid_item R.layout.source_grid_item

View file

@ -9,7 +9,6 @@ import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.MangaCategory import eu.kanade.tachiyomi.data.database.models.MangaCategory
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.preference.PreferencesHelper 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.LocalSource
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
@ -111,9 +110,9 @@ class LibraryPresenter(
* @param map the map to filter. * @param map the map to filter.
*/ */
private fun applyFilters(map: LibraryMap): LibraryMap { private fun applyFilters(map: LibraryMap): LibraryMap {
val filterDownloaded = preferences.downloadedOnly().get() || preferences.filterDownloaded().getOrDefault() val filterDownloaded = preferences.downloadedOnly().get() || preferences.filterDownloaded().get()
val filterUnread = preferences.filterUnread().getOrDefault() val filterUnread = preferences.filterUnread().get()
val filterCompleted = preferences.filterCompleted().getOrDefault() val filterCompleted = preferences.filterCompleted().get()
val filterFn: (LibraryItem) -> Boolean = f@{ item -> val filterFn: (LibraryItem) -> Boolean = f@{ item ->
// Filter when there isn't unread chapters. // Filter when there isn't unread chapters.
@ -150,7 +149,7 @@ class LibraryPresenter(
* @param map the map of manga. * @param map the map of manga.
*/ */
private fun setDownloadCount(map: LibraryMap) { private fun setDownloadCount(map: LibraryMap) {
if (!preferences.downloadBadge().getOrDefault()) { if (!preferences.downloadBadge().get()) {
// Unset download count if the preference is not enabled. // Unset download count if the preference is not enabled.
for ((_, itemList) in map) { for ((_, itemList) in map) {
for (item in itemList) { for (item in itemList) {
@ -173,7 +172,7 @@ class LibraryPresenter(
* @param map the map to sort. * @param map the map to sort.
*/ */
private fun applySort(map: LibraryMap): LibraryMap { private fun applySort(map: LibraryMap): LibraryMap {
val sortingMode = preferences.librarySortingMode().getOrDefault() val sortingMode = preferences.librarySortingMode().get()
val lastReadManga by lazy { val lastReadManga by lazy {
var counter = 0 var counter = 0
@ -215,7 +214,7 @@ class LibraryPresenter(
} }
} }
val comparator = if (preferences.librarySortingAscending().getOrDefault()) val comparator = if (preferences.librarySortingAscending().get())
Comparator(sortFn) Comparator(sortFn)
else else
Collections.reverseOrder(sortFn) Collections.reverseOrder(sortFn)

View file

@ -6,7 +6,6 @@ import android.util.AttributeSet
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.widget.ExtendedNavigationView import eu.kanade.tachiyomi.widget.ExtendedNavigationView
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -96,10 +95,10 @@ class LibrarySettingsSheet(
override val footer = Item.Separator() override val footer = Item.Separator()
override fun initModels() { override fun initModels() {
downloaded.checked = preferences.downloadedOnly().get() || preferences.filterDownloaded().getOrDefault() downloaded.checked = preferences.downloadedOnly().get() || preferences.filterDownloaded().get()
downloaded.enabled = !preferences.downloadedOnly().get() downloaded.enabled = !preferences.downloadedOnly().get()
unread.checked = preferences.filterUnread().getOrDefault() unread.checked = preferences.filterUnread().get()
completed.checked = preferences.filterCompleted().getOrDefault() completed.checked = preferences.filterCompleted().get()
} }
override fun onItemClicked(item: Item) { override fun onItemClicked(item: Item) {
@ -140,8 +139,8 @@ class LibrarySettingsSheet(
override val footer = Item.Separator() override val footer = Item.Separator()
override fun initModels() { override fun initModels() {
val sorting = preferences.librarySortingMode().getOrDefault() val sorting = preferences.librarySortingMode().get()
val order = if (preferences.librarySortingAscending().getOrDefault()) val order = if (preferences.librarySortingAscending().get())
Item.MultiSort.SORT_ASC else Item.MultiSort.SORT_DESC Item.MultiSort.SORT_ASC else Item.MultiSort.SORT_DESC
alphabetically.state = alphabetically.state =
@ -196,7 +195,7 @@ class LibrarySettingsSheet(
override val footer = null override val footer = null
override val items = listOf(downloadBadge) override val items = listOf(downloadBadge)
override fun initModels() { override fun initModels() {
downloadBadge.checked = preferences.downloadBadge().getOrDefault() downloadBadge.checked = preferences.downloadBadge().get()
} }
override fun onItemClicked(item: Item) { override fun onItemClicked(item: Item) {
@ -223,7 +222,7 @@ class LibrarySettingsSheet(
override val footer = null override val footer = null
override fun initModels() { override fun initModels() {
val asList = preferences.libraryAsList().getOrDefault() val asList = preferences.libraryAsList().get()
grid.checked = !asList grid.checked = !asList
list.checked = asList list.checked = asList
} }

View file

@ -39,6 +39,8 @@ import eu.kanade.tachiyomi.util.system.getFilePicker
import eu.kanade.tachiyomi.util.system.registerLocalReceiver import eu.kanade.tachiyomi.util.system.registerLocalReceiver
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.system.unregisterLocalReceiver import eu.kanade.tachiyomi.util.system.unregisterLocalReceiver
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
class SettingsBackupController : SettingsController() { class SettingsBackupController : SettingsController() {
@ -148,11 +150,12 @@ class SettingsBackupController : SettingsController() {
summary = "%s" summary = "%s"
} }
preferences.backupInterval().asObservable() preferences.backupInterval().asFlow()
.subscribeUntilDestroy { .onEach {
backupDir.isVisible = it > 0 backupDir.isVisible = it > 0
backupNumber.isVisible = it > 0 backupNumber.isVisible = it > 0
} }
.launchIn(scope)
} }
} }

View file

@ -30,6 +30,8 @@ import eu.kanade.tachiyomi.util.preference.switchPreference
import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.preference.titleRes
import eu.kanade.tachiyomi.util.system.getFilePicker import eu.kanade.tachiyomi.util.system.getFilePicker
import java.io.File import java.io.File
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -98,20 +100,22 @@ class SettingsDownloadController : SettingsController() {
entries = categories.map { it.name }.toTypedArray() entries = categories.map { it.name }.toTypedArray()
entryValues = categories.map { it.id.toString() }.toTypedArray() entryValues = categories.map { it.id.toString() }.toTypedArray()
preferences.downloadNew().asObservable() preferences.downloadNew().asFlow()
.subscribeUntilDestroy { isVisible = it } .onEach { isVisible = it }
.launchIn(scope)
preferences.downloadNewCategories().asObservable() preferences.downloadNewCategories().asFlow()
.subscribeUntilDestroy { mutableSet -> .onEach { mutableSet ->
val selectedCategories = mutableSet val selectedCategories = mutableSet
.mapNotNull { id -> categories.find { it.id == id.toInt() } } .mapNotNull { id -> categories.find { it.id == id.toInt() } }
.sortedBy { it.order } .sortedBy { it.order }
summary = if (selectedCategories.isEmpty()) summary = if (selectedCategories.isEmpty())
resources?.getString(R.string.all) resources?.getString(R.string.all)
else else
selectedCategories.joinToString { it.name } selectedCategories.joinToString { it.name }
} }
.launchIn(scope)
} }
} }
} }

View file

@ -30,6 +30,8 @@ import eu.kanade.tachiyomi.util.preference.switchPreference
import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.preference.titleRes
import kotlinx.android.synthetic.main.pref_library_columns.view.landscape_columns import kotlinx.android.synthetic.main.pref_library_columns.view.landscape_columns
import kotlinx.android.synthetic.main.pref_library_columns.view.portrait_columns import kotlinx.android.synthetic.main.pref_library_columns.view.portrait_columns
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import rx.Observable import rx.Observable
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -99,8 +101,9 @@ class SettingsLibraryController : SettingsController() {
entryValues = arrayOf("wifi", "ac") entryValues = arrayOf("wifi", "ac")
summaryRes = R.string.pref_library_update_restriction_summary summaryRes = R.string.pref_library_update_restriction_summary
preferences.libraryUpdateInterval().asObservable() preferences.libraryUpdateInterval().asFlow()
.subscribeUntilDestroy { isVisible = it > 0 } .onEach { isVisible = it > 0 }
.launchIn(scope)
onChange { onChange {
// Post to event looper to allow the preference to be updated. // Post to event looper to allow the preference to be updated.
@ -118,17 +121,18 @@ class SettingsLibraryController : SettingsController() {
titleRes = R.string.pref_library_update_categories titleRes = R.string.pref_library_update_categories
entries = categories.map { it.name }.toTypedArray() entries = categories.map { it.name }.toTypedArray()
entryValues = categories.map { it.id.toString() }.toTypedArray() entryValues = categories.map { it.id.toString() }.toTypedArray()
preferences.libraryUpdateCategories().asObservable() preferences.libraryUpdateCategories().asFlow()
.subscribeUntilDestroy { mutableSet -> .onEach { mutableSet ->
val selectedCategories = mutableSet val selectedCategories = mutableSet
.mapNotNull { id -> categories.find { it.id == id.toInt() } } .mapNotNull { id -> categories.find { it.id == id.toInt() } }
.sortedBy { it.order } .sortedBy { it.order }
summary = if (selectedCategories.isEmpty()) summary = if (selectedCategories.isEmpty())
context.getString(R.string.all) context.getString(R.string.all)
else else
selectedCategories.joinToString { it.name } selectedCategories.joinToString { it.name }
} }
.launchIn(scope)
} }
intListPreference { intListPreference {
key = Keys.libraryUpdatePrioritization key = Keys.libraryUpdatePrioritization
@ -146,7 +150,7 @@ class SettingsLibraryController : SettingsController() {
entryValues = priorities.map { it.first }.toTypedArray() entryValues = priorities.map { it.first }.toTypedArray()
defaultValue = defaultPriority.first defaultValue = defaultPriority.first
val selectedPriority = priorities.find { it.first.toInt() == preferences.libraryUpdatePrioritization().getOrDefault() } val selectedPriority = priorities.find { it.first.toInt() == preferences.libraryUpdatePrioritization().get() }
summaryRes = selectedPriority?.second ?: defaultPriority.second summaryRes = selectedPriority?.second ?: defaultPriority.second
onChange { newValue -> onChange { newValue ->
summaryRes = priorities.find { summaryRes = priorities.find {