[feature] add ability to set global filter/sort/display for Manga chapters (#3622)
* - [feature] add ability to set global filter/sort/display for Manga chapters * - move default chapter settings functionality to overflow menu - code clean up * - show confirmation dialog when user selects "Set as Default" option in Chapter Settings * - hide overflow menu in LibrarySettingsSheet * - apply default chapter settings if manga is added to Library from a Source's browsing screen Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package eu.kanade.tachiyomi.util.chapter
|
||||
|
||||
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.util.lang.launchIO
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
object ChapterSettingsHelper {
|
||||
private val prefs = Injekt.get<PreferencesHelper>()
|
||||
private val db: DatabaseHelper = Injekt.get()
|
||||
|
||||
/**
|
||||
* updates the Chapter Settings in Preferences
|
||||
*/
|
||||
fun setNewSettingDefaults(m: Manga?) {
|
||||
m?.let {
|
||||
prefs.setChapterSettingsDefault(it)
|
||||
db.updateFlags(it).executeAsBlocking()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* updates a single manga's Chapter Settings to match what's set in Preferences
|
||||
*/
|
||||
fun applySettingDefaultsFromPreferences(m: Manga) {
|
||||
m.readFilter = prefs.filterChapterByRead()
|
||||
m.downloadedFilter = prefs.filterChapterByDownloaded()
|
||||
m.bookmarkedFilter = prefs.filterChapterByBookmarked()
|
||||
m.sorting = prefs.sortChapterBySourceOrNumber()
|
||||
m.displayMode = prefs.displayChapterByNameOrNumber()
|
||||
m.setChapterOrder(prefs.sortChapterByAscendingOrDescending())
|
||||
db.updateFlags(m).executeAsBlocking()
|
||||
}
|
||||
|
||||
/**
|
||||
* updates all mangas in database Chapter Settings to match what's set in Preferences
|
||||
*/
|
||||
fun updateAllMangasWithDefaultsFromPreferences() {
|
||||
launchIO {
|
||||
val dbMangas = db.getMangas().executeAsBlocking().toMutableList()
|
||||
|
||||
val updatedMangas = dbMangas.map { m ->
|
||||
m.readFilter = prefs.filterChapterByRead()
|
||||
m.downloadedFilter = prefs.filterChapterByDownloaded()
|
||||
m.bookmarkedFilter = prefs.filterChapterByBookmarked()
|
||||
m.sorting = prefs.sortChapterBySourceOrNumber()
|
||||
m.displayMode = prefs.displayChapterByNameOrNumber()
|
||||
m.setChapterOrder(prefs.sortChapterByAscendingOrDescending())
|
||||
m
|
||||
}.toList()
|
||||
|
||||
db.updateFlags(updatedMangas).executeAsBlocking()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user