mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-05 00:28:56 +01:00
Split library preferences from PreferencesHelper (#8036)
This commit is contained in:
@@ -10,6 +10,7 @@ import eu.kanade.data.DatabaseHandler
|
||||
import eu.kanade.domain.category.interactor.GetCategories
|
||||
import eu.kanade.domain.category.model.Category
|
||||
import eu.kanade.domain.history.model.HistoryUpdate
|
||||
import eu.kanade.domain.library.service.LibraryPreferences
|
||||
import eu.kanade.domain.manga.interactor.GetFavorites
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.backup.BackupConst.BACKUP_CATEGORY
|
||||
@@ -57,6 +58,7 @@ class BackupManager(
|
||||
private val handler: DatabaseHandler = Injekt.get()
|
||||
private val sourceManager: SourceManager = Injekt.get()
|
||||
private val preferences: PreferencesHelper = Injekt.get()
|
||||
private val libraryPreferences: LibraryPreferences = Injekt.get()
|
||||
private val getCategories: GetCategories = Injekt.get()
|
||||
private val getFavorites: GetFavorites = Injekt.get()
|
||||
|
||||
@@ -271,7 +273,7 @@ class BackupManager(
|
||||
category
|
||||
}
|
||||
|
||||
preferences.categorizedDisplaySettings().set(
|
||||
libraryPreferences.categorizedDisplaySettings().set(
|
||||
(dbCategories + categories)
|
||||
.distinctBy { it.flags }
|
||||
.size > 1,
|
||||
|
||||
@@ -8,11 +8,11 @@ import androidx.work.PeriodicWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import eu.kanade.domain.library.service.LibraryPreferences
|
||||
import eu.kanade.tachiyomi.data.preference.DEVICE_BATTERY_NOT_LOW
|
||||
import eu.kanade.tachiyomi.data.preference.DEVICE_CHARGING
|
||||
import eu.kanade.tachiyomi.data.preference.DEVICE_NETWORK_NOT_METERED
|
||||
import eu.kanade.tachiyomi.data.preference.DEVICE_ONLY_ON_WIFI
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.system.isConnectedToWifi
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
@@ -22,7 +22,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
||||
Worker(context, workerParams) {
|
||||
|
||||
override fun doWork(): Result {
|
||||
val preferences = Injekt.get<PreferencesHelper>()
|
||||
val preferences = Injekt.get<LibraryPreferences>()
|
||||
val restrictions = preferences.libraryUpdateDeviceRestriction().get()
|
||||
if ((DEVICE_ONLY_ON_WIFI in restrictions) && !context.isConnectedToWifi()) {
|
||||
return Result.failure()
|
||||
@@ -39,7 +39,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
||||
private const val TAG = "LibraryUpdate"
|
||||
|
||||
fun setupTask(context: Context, prefInterval: Int? = null) {
|
||||
val preferences = Injekt.get<PreferencesHelper>()
|
||||
val preferences = Injekt.get<LibraryPreferences>()
|
||||
val interval = prefInterval ?: preferences.libraryUpdateInterval().get()
|
||||
if (interval > 0) {
|
||||
val restrictions = preferences.libraryUpdateDeviceRestriction().get()
|
||||
|
||||
@@ -13,6 +13,7 @@ import eu.kanade.domain.chapter.interactor.GetChapterByMangaId
|
||||
import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource
|
||||
import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay
|
||||
import eu.kanade.domain.chapter.model.toDbChapter
|
||||
import eu.kanade.domain.library.service.LibraryPreferences
|
||||
import eu.kanade.domain.manga.interactor.GetLibraryManga
|
||||
import eu.kanade.domain.manga.interactor.GetManga
|
||||
import eu.kanade.domain.manga.interactor.UpdateManga
|
||||
@@ -86,6 +87,7 @@ import eu.kanade.domain.manga.model.Manga as DomainManga
|
||||
class LibraryUpdateService(
|
||||
val sourceManager: SourceManager = Injekt.get(),
|
||||
val preferences: PreferencesHelper = Injekt.get(),
|
||||
val libraryPreferences: LibraryPreferences = Injekt.get(),
|
||||
val downloadManager: DownloadManager = Injekt.get(),
|
||||
val trackManager: TrackManager = Injekt.get(),
|
||||
val coverCache: CoverCache = Injekt.get(),
|
||||
@@ -228,7 +230,7 @@ class LibraryUpdateService(
|
||||
|
||||
// If this is a chapter update; set the last update time to now
|
||||
if (target == Target.CHAPTERS) {
|
||||
preferences.libraryUpdateLastTimestamp().set(Date().time)
|
||||
libraryPreferences.libraryUpdateLastTimestamp().set(Date().time)
|
||||
}
|
||||
|
||||
// Update favorite manga
|
||||
@@ -264,14 +266,14 @@ class LibraryUpdateService(
|
||||
val listToUpdate = if (categoryId != -1L) {
|
||||
libraryManga.filter { it.category.toLong() == categoryId }
|
||||
} else {
|
||||
val categoriesToUpdate = preferences.libraryUpdateCategories().get().map(String::toInt)
|
||||
val categoriesToUpdate = libraryPreferences.libraryUpdateCategories().get().map(String::toInt)
|
||||
val listToInclude = if (categoriesToUpdate.isNotEmpty()) {
|
||||
libraryManga.filter { it.category in categoriesToUpdate }
|
||||
} else {
|
||||
libraryManga
|
||||
}
|
||||
|
||||
val categoriesToExclude = preferences.libraryUpdateCategoriesExclude().get().map(String::toInt)
|
||||
val categoriesToExclude = libraryPreferences.libraryUpdateCategoriesExclude().get().map(String::toInt)
|
||||
val listToExclude = if (categoriesToExclude.isNotEmpty()) {
|
||||
libraryManga.filter { it.category in categoriesToExclude }
|
||||
} else {
|
||||
@@ -312,8 +314,8 @@ class LibraryUpdateService(
|
||||
val failedUpdates = CopyOnWriteArrayList<Pair<Manga, String?>>()
|
||||
val hasDownloads = AtomicBoolean(false)
|
||||
val loggedServices by lazy { trackManager.services.filter { it.isLogged } }
|
||||
val currentUnreadUpdatesCount = preferences.unreadUpdatesCount().get()
|
||||
val restrictions = preferences.libraryUpdateMangaRestriction().get()
|
||||
val currentUnreadUpdatesCount = libraryPreferences.unreadUpdatesCount().get()
|
||||
val restrictions = libraryPreferences.libraryUpdateMangaRestriction().get()
|
||||
|
||||
withIOContext {
|
||||
mangaToUpdate.groupBy { it.source }
|
||||
@@ -396,7 +398,7 @@ class LibraryUpdateService(
|
||||
if (newUpdates.isNotEmpty()) {
|
||||
notifier.showUpdateNotifications(newUpdates)
|
||||
val newChapterCount = newUpdates.sumOf { it.second.size }
|
||||
preferences.unreadUpdatesCount().set(currentUnreadUpdatesCount + newChapterCount)
|
||||
libraryPreferences.unreadUpdatesCount().set(currentUnreadUpdatesCount + newChapterCount)
|
||||
if (hasDownloads.get()) {
|
||||
DownloadService.start(this)
|
||||
}
|
||||
|
||||
@@ -25,26 +25,12 @@ object PreferenceKeys {
|
||||
|
||||
const val removeBookmarkedChapters = "pref_remove_bookmarked"
|
||||
|
||||
const val filterDownloaded = "pref_filter_library_downloaded"
|
||||
|
||||
const val filterUnread = "pref_filter_library_unread"
|
||||
|
||||
const val filterStarted = "pref_filter_library_started"
|
||||
|
||||
const val filterCompleted = "pref_filter_library_completed"
|
||||
|
||||
const val filterTracked = "pref_filter_library_tracked"
|
||||
|
||||
const val librarySortingMode = "library_sorting_mode"
|
||||
|
||||
const val autoUpdateMetadata = "auto_update_metadata"
|
||||
|
||||
const val autoUpdateTrackers = "auto_update_trackers"
|
||||
|
||||
const val dateFormat = "app_date_format"
|
||||
|
||||
const val defaultCategory = "default_category"
|
||||
|
||||
const val skipRead = "skip_read"
|
||||
|
||||
const val skipFiltered = "skip_filtered"
|
||||
|
||||
@@ -10,13 +10,10 @@ import eu.kanade.tachiyomi.core.preference.getEnum
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.track.TrackService
|
||||
import eu.kanade.tachiyomi.data.track.anilist.Anilist
|
||||
import eu.kanade.tachiyomi.ui.library.setting.LibraryDisplayMode
|
||||
import eu.kanade.tachiyomi.ui.library.setting.LibrarySort
|
||||
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
|
||||
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
|
||||
import eu.kanade.tachiyomi.util.system.DeviceUtil
|
||||
import eu.kanade.tachiyomi.util.system.isDynamicColorAvailable
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView
|
||||
import java.io.File
|
||||
import java.text.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
@@ -144,18 +141,10 @@ class PreferencesHelper(
|
||||
|
||||
fun readerHideThreshold() = this.preferenceStore.getEnum("reader_hide_threshold", Values.ReaderHideThreshold.LOW)
|
||||
|
||||
fun portraitColumns() = this.preferenceStore.getInt("pref_library_columns_portrait_key", 0)
|
||||
|
||||
fun landscapeColumns() = this.preferenceStore.getInt("pref_library_columns_landscape_key", 0)
|
||||
|
||||
fun autoUpdateTrack() = this.preferenceStore.getBoolean(Keys.autoUpdateTrack, true)
|
||||
|
||||
fun lastUsedCategory() = this.preferenceStore.getInt("last_used_category", 0)
|
||||
|
||||
fun lastVersionCode() = this.preferenceStore.getInt("last_version_code", 0)
|
||||
|
||||
fun sourceDisplayMode() = this.preferenceStore.getObject("pref_display_mode_catalogue", LibraryDisplayMode.default, LibraryDisplayMode.Serializer::serialize, LibraryDisplayMode.Serializer::deserialize)
|
||||
|
||||
fun trackUsername(sync: TrackService) = this.preferenceStore.getString(Keys.trackUsername(sync.id), "")
|
||||
|
||||
fun trackPassword(sync: TrackService) = this.preferenceStore.getString(Keys.trackPassword(sync.id), "")
|
||||
@@ -200,46 +189,8 @@ class PreferencesHelper(
|
||||
|
||||
fun removeExcludeCategories() = this.preferenceStore.getStringSet("remove_exclude_categories", emptySet())
|
||||
|
||||
fun libraryUpdateInterval() = this.preferenceStore.getInt("pref_library_update_interval_key", 24)
|
||||
fun libraryUpdateLastTimestamp() = this.preferenceStore.getLong("library_update_last_timestamp", 0L)
|
||||
|
||||
fun libraryUpdateDeviceRestriction() = this.preferenceStore.getStringSet("library_update_restriction", setOf(DEVICE_ONLY_ON_WIFI))
|
||||
fun libraryUpdateMangaRestriction() = this.preferenceStore.getStringSet("library_update_manga_restriction", setOf(MANGA_HAS_UNREAD, MANGA_NON_COMPLETED, MANGA_NON_READ))
|
||||
|
||||
fun showUpdatesNavBadge() = this.preferenceStore.getBoolean("library_update_show_tab_badge", false)
|
||||
fun unreadUpdatesCount() = this.preferenceStore.getInt("library_unread_updates_count", 0)
|
||||
|
||||
fun libraryUpdateCategories() = this.preferenceStore.getStringSet("library_update_categories", emptySet())
|
||||
fun libraryUpdateCategoriesExclude() = this.preferenceStore.getStringSet("library_update_categories_exclude", emptySet())
|
||||
|
||||
fun libraryDisplayMode() = this.preferenceStore.getObject("pref_display_mode_library", LibraryDisplayMode.default, LibraryDisplayMode.Serializer::serialize, LibraryDisplayMode.Serializer::deserialize)
|
||||
|
||||
fun downloadBadge() = this.preferenceStore.getBoolean("display_download_badge", false)
|
||||
|
||||
fun localBadge() = this.preferenceStore.getBoolean("display_local_badge", true)
|
||||
|
||||
fun downloadedOnly() = this.preferenceStore.getBoolean("pref_downloaded_only", false)
|
||||
|
||||
fun unreadBadge() = this.preferenceStore.getBoolean("display_unread_badge", true)
|
||||
|
||||
fun languageBadge() = this.preferenceStore.getBoolean("display_language_badge", false)
|
||||
|
||||
fun categoryTabs() = this.preferenceStore.getBoolean("display_category_tabs", true)
|
||||
|
||||
fun categoryNumberOfItems() = this.preferenceStore.getBoolean("display_number_of_items", false)
|
||||
|
||||
fun filterDownloaded() = this.preferenceStore.getInt(Keys.filterDownloaded, ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
|
||||
fun filterUnread() = this.preferenceStore.getInt(Keys.filterUnread, ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
|
||||
fun filterStarted() = this.preferenceStore.getInt(Keys.filterStarted, ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
|
||||
fun filterCompleted() = this.preferenceStore.getInt(Keys.filterCompleted, ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
|
||||
fun filterTracking(name: Int) = this.preferenceStore.getInt("${Keys.filterTracked}_$name", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
|
||||
fun librarySortingMode() = this.preferenceStore.getObject(Keys.librarySortingMode, LibrarySort.default, LibrarySort.Serializer::serialize, LibrarySort.Serializer::deserialize)
|
||||
|
||||
fun automaticExtUpdates() = this.preferenceStore.getBoolean("automatic_ext_updates", true)
|
||||
|
||||
fun lastAppCheck() = this.preferenceStore.getLong("last_app_check", 0)
|
||||
@@ -252,10 +203,6 @@ class PreferencesHelper(
|
||||
|
||||
fun autoDownloadWhileReading() = this.preferenceStore.getInt("auto_download_while_reading", 0)
|
||||
|
||||
fun defaultCategory() = this.preferenceStore.getInt(Keys.defaultCategory, -1)
|
||||
|
||||
fun categorizedDisplaySettings() = this.preferenceStore.getBoolean("categorized_display", false)
|
||||
|
||||
fun skipRead() = this.preferenceStore.getBoolean(Keys.skipRead, false)
|
||||
|
||||
fun skipFiltered() = this.preferenceStore.getBoolean(Keys.skipFiltered, true)
|
||||
|
||||
Reference in New Issue
Block a user