diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt index 01905e02a..7dae0653c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt @@ -30,7 +30,7 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet fun setupTask(context: Context, prefInterval: Int? = null) { val preferences = Injekt.get() - val interval = prefInterval ?: preferences.backupInterval().getOrDefault() + val interval = prefInterval ?: preferences.backupInterval().get() if (interval > 0) { val request = PeriodicWorkRequestBuilder( interval.toLong(), TimeUnit.HOURS, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt index 9b86bb674..8898b87f1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt @@ -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.TrackImpl 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.source.Source 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 */ - fun numberOfBackups(): Int = preferences.numberOfBackups().getOrDefault() + fun numberOfBackups(): Int = preferences.numberOfBackups().get() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt index 8cbe006d9..12c0f1578 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt @@ -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 java.util.concurrent.TimeUnit import uy.kohesive.injekt.Injekt 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) { val preferences = Injekt.get() - val interval = prefInterval ?: preferences.libraryUpdateInterval().getOrDefault() + val interval = prefInterval ?: preferences.libraryUpdateInterval().get() if (interval > 0) { val restrictions = preferences.libraryUpdateRestriction()!! val acRestriction = "ac" in restrictions diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 0d52a2980..a5a70f8e3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -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.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.source.SourceManager 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. subscription = Observable .defer { - val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault() + val selectedScheme = preferences.libraryUpdatePrioritization().get() val mangaList = getMangaToUpdate(intent, target) .sortedWith(rankingScheme[selectedScheme]) @@ -263,7 +262,7 @@ class LibraryUpdateService( var listToUpdate = if (categoryId != -1) db.getLibraryMangas().executeAsBlocking().filter { it.category == categoryId } else { - val categoriesToUpdate = preferences.libraryUpdateCategories().getOrDefault().map(String::toInt) + val categoriesToUpdate = preferences.libraryUpdateCategories().get().map(String::toInt) if (categoriesToUpdate.isNotEmpty()) db.getLibraryMangas().executeAsBlocking() .filter { it.category in categoriesToUpdate } @@ -295,9 +294,9 @@ class LibraryUpdateService( // List containing failed updates val failedUpdates = ArrayList() // 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. - val downloadNew = preferences.downloadNew().getOrDefault() + val downloadNew = preferences.downloadNew().get() // Boolean to determine if DownloadManager has downloads var hasDownloads = false diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 00e5c6912..3c94ffcaf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -165,37 +165,37 @@ class PreferencesHelper(val context: Context) { 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 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 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 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) @@ -209,9 +209,9 @@ class PreferencesHelper(val context: Context) { 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, "") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index 657186bfe..72efe2fe9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -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.library.LibraryUpdateService 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.system.toast import eu.kanade.tachiyomi.util.view.inflate @@ -67,7 +66,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att fun onCreate(controller: LibraryController) { this.controller = controller - recycler = if (preferences.libraryAsList().getOrDefault()) { + recycler = if (preferences.libraryAsList().get()) { (swipe_refresh.inflate(R.layout.library_list_recycler) as RecyclerView).apply { layoutManager = LinearLayoutManager(context) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 98adf0595..9c22457f3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -5,14 +5,13 @@ import android.view.View import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.widget.FrameLayout 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.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.IFilterable import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R 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.widget.AutofitRecyclerView 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 override fun getLayoutRes(): Int { - return if (libraryAsList.getOrDefault()) + return if (libraryAsList.get()) R.layout.source_list_item else R.layout.source_grid_item diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index f9f0d33a2..e08404a99 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -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.download.DownloadManager 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.SourceManager import eu.kanade.tachiyomi.source.model.SManga @@ -111,9 +110,9 @@ class LibraryPresenter( * @param map the map to filter. */ private fun applyFilters(map: LibraryMap): LibraryMap { - val filterDownloaded = preferences.downloadedOnly().get() || preferences.filterDownloaded().getOrDefault() - val filterUnread = preferences.filterUnread().getOrDefault() - val filterCompleted = preferences.filterCompleted().getOrDefault() + val filterDownloaded = preferences.downloadedOnly().get() || preferences.filterDownloaded().get() + val filterUnread = preferences.filterUnread().get() + val filterCompleted = preferences.filterCompleted().get() val filterFn: (LibraryItem) -> Boolean = f@{ item -> // Filter when there isn't unread chapters. @@ -150,7 +149,7 @@ class LibraryPresenter( * @param map the map of manga. */ private fun setDownloadCount(map: LibraryMap) { - if (!preferences.downloadBadge().getOrDefault()) { + if (!preferences.downloadBadge().get()) { // Unset download count if the preference is not enabled. for ((_, itemList) in map) { for (item in itemList) { @@ -173,7 +172,7 @@ class LibraryPresenter( * @param map the map to sort. */ private fun applySort(map: LibraryMap): LibraryMap { - val sortingMode = preferences.librarySortingMode().getOrDefault() + val sortingMode = preferences.librarySortingMode().get() val lastReadManga by lazy { var counter = 0 @@ -215,7 +214,7 @@ class LibraryPresenter( } } - val comparator = if (preferences.librarySortingAscending().getOrDefault()) + val comparator = if (preferences.librarySortingAscending().get()) Comparator(sortFn) else Collections.reverseOrder(sortFn) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index 1773b619a..f12106678 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -6,7 +6,6 @@ import android.util.AttributeSet import com.google.android.material.bottomsheet.BottomSheetDialog import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.widget.ExtendedNavigationView import uy.kohesive.injekt.injectLazy @@ -96,10 +95,10 @@ class LibrarySettingsSheet( override val footer = Item.Separator() override fun initModels() { - downloaded.checked = preferences.downloadedOnly().get() || preferences.filterDownloaded().getOrDefault() + downloaded.checked = preferences.downloadedOnly().get() || preferences.filterDownloaded().get() downloaded.enabled = !preferences.downloadedOnly().get() - unread.checked = preferences.filterUnread().getOrDefault() - completed.checked = preferences.filterCompleted().getOrDefault() + unread.checked = preferences.filterUnread().get() + completed.checked = preferences.filterCompleted().get() } override fun onItemClicked(item: Item) { @@ -140,8 +139,8 @@ class LibrarySettingsSheet( override val footer = Item.Separator() override fun initModels() { - val sorting = preferences.librarySortingMode().getOrDefault() - val order = if (preferences.librarySortingAscending().getOrDefault()) + val sorting = preferences.librarySortingMode().get() + val order = if (preferences.librarySortingAscending().get()) Item.MultiSort.SORT_ASC else Item.MultiSort.SORT_DESC alphabetically.state = @@ -196,7 +195,7 @@ class LibrarySettingsSheet( override val footer = null override val items = listOf(downloadBadge) override fun initModels() { - downloadBadge.checked = preferences.downloadBadge().getOrDefault() + downloadBadge.checked = preferences.downloadBadge().get() } override fun onItemClicked(item: Item) { @@ -223,7 +222,7 @@ class LibrarySettingsSheet( override val footer = null override fun initModels() { - val asList = preferences.libraryAsList().getOrDefault() + val asList = preferences.libraryAsList().get() grid.checked = !asList list.checked = asList } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index 64ccfca60..978641109 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -39,6 +39,8 @@ import eu.kanade.tachiyomi.util.system.getFilePicker import eu.kanade.tachiyomi.util.system.registerLocalReceiver import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.unregisterLocalReceiver +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach class SettingsBackupController : SettingsController() { @@ -148,11 +150,12 @@ class SettingsBackupController : SettingsController() { summary = "%s" } - preferences.backupInterval().asObservable() - .subscribeUntilDestroy { - backupDir.isVisible = it > 0 - backupNumber.isVisible = it > 0 - } + preferences.backupInterval().asFlow() + .onEach { + backupDir.isVisible = it > 0 + backupNumber.isVisible = it > 0 + } + .launchIn(scope) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt index b9afcf497..de18b96c9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt @@ -30,6 +30,8 @@ import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.system.getFilePicker import java.io.File +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 @@ -98,20 +100,22 @@ class SettingsDownloadController : SettingsController() { entries = categories.map { it.name }.toTypedArray() entryValues = categories.map { it.id.toString() }.toTypedArray() - preferences.downloadNew().asObservable() - .subscribeUntilDestroy { isVisible = it } + preferences.downloadNew().asFlow() + .onEach { isVisible = it } + .launchIn(scope) - preferences.downloadNewCategories().asObservable() - .subscribeUntilDestroy { mutableSet -> - val selectedCategories = mutableSet - .mapNotNull { id -> categories.find { it.id == id.toInt() } } - .sortedBy { it.order } + preferences.downloadNewCategories().asFlow() + .onEach { mutableSet -> + val selectedCategories = mutableSet + .mapNotNull { id -> categories.find { it.id == id.toInt() } } + .sortedBy { it.order } - summary = if (selectedCategories.isEmpty()) - resources?.getString(R.string.all) - else - selectedCategories.joinToString { it.name } - } + summary = if (selectedCategories.isEmpty()) + resources?.getString(R.string.all) + else + selectedCategories.joinToString { it.name } + } + .launchIn(scope) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 363a753a0..a75f0a759 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -30,6 +30,8 @@ import eu.kanade.tachiyomi.util.preference.switchPreference 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.portrait_columns +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import rx.Observable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -99,8 +101,9 @@ class SettingsLibraryController : SettingsController() { entryValues = arrayOf("wifi", "ac") summaryRes = R.string.pref_library_update_restriction_summary - preferences.libraryUpdateInterval().asObservable() - .subscribeUntilDestroy { isVisible = it > 0 } + preferences.libraryUpdateInterval().asFlow() + .onEach { isVisible = it > 0 } + .launchIn(scope) onChange { // 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 entries = categories.map { it.name }.toTypedArray() entryValues = categories.map { it.id.toString() }.toTypedArray() - preferences.libraryUpdateCategories().asObservable() - .subscribeUntilDestroy { mutableSet -> - val selectedCategories = mutableSet - .mapNotNull { id -> categories.find { it.id == id.toInt() } } - .sortedBy { it.order } + preferences.libraryUpdateCategories().asFlow() + .onEach { mutableSet -> + val selectedCategories = mutableSet + .mapNotNull { id -> categories.find { it.id == id.toInt() } } + .sortedBy { it.order } - summary = if (selectedCategories.isEmpty()) - context.getString(R.string.all) - else - selectedCategories.joinToString { it.name } - } + summary = if (selectedCategories.isEmpty()) + context.getString(R.string.all) + else + selectedCategories.joinToString { it.name } + } + .launchIn(scope) } intListPreference { key = Keys.libraryUpdatePrioritization @@ -146,7 +150,7 @@ class SettingsLibraryController : SettingsController() { entryValues = priorities.map { it.first }.toTypedArray() 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 onChange { newValue -> summaryRes = priorities.find {