Move more things to domain/data modules
(cherry picked from commit bebd4be43d73617de2cfbc1ff4289e81f535a8e6) # Conflicts: # app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt # app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt # app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt # app/src/main/java/eu/kanade/tachiyomi/AppModule.kt # app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt # app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt # app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt # app/src/main/java/eu/kanade/tachiyomi/ui/home/HomeScreen.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt # app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt # data/src/main/java/tachiyomi/data/source/EHentaiPagingSource.kt # data/src/main/java/tachiyomi/data/source/SourcePagingSource.kt # domain/build.gradle.kts # domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayModeForCategory.kt # domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt # domain/src/main/java/tachiyomi/domain/history/interactor/GetHistoryByMangaId.kt # domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt
This commit is contained in:
@@ -19,6 +19,8 @@ dependencies {
|
||||
implementation(platform(kotlinx.coroutines.bom))
|
||||
implementation(kotlinx.bundles.coroutines)
|
||||
|
||||
api(libs.sqldelight.android.paging)
|
||||
|
||||
// SY -->
|
||||
implementation(libs.injekt.core)
|
||||
// SY <--
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package exh.source
|
||||
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
|
||||
// Used to speed up isLewdSource
|
||||
var metadataDelegatedSourceIds: List<Long> = emptyList()
|
||||
|
||||
var nHentaiSourceIds: List<Long> = emptyList()
|
||||
|
||||
var mangaDexSourceIds: List<Long> = emptyList()
|
||||
|
||||
var LIBRARY_UPDATE_EXCLUDED_SOURCES = listOf(
|
||||
EH_SOURCE_ID,
|
||||
EXH_SOURCE_ID,
|
||||
PURURIN_SOURCE_ID,
|
||||
)
|
||||
|
||||
// This method MUST be fast!
|
||||
fun isMetadataSource(source: Long) = source in 6900..6999 ||
|
||||
metadataDelegatedSourceIds.binarySearch(source) >= 0
|
||||
|
||||
fun Source.isEhBasedSource() = id == EH_SOURCE_ID || id == EXH_SOURCE_ID
|
||||
|
||||
fun Source.isMdBasedSource() = id in mangaDexSourceIds
|
||||
|
||||
fun Manga.isEhBasedManga() = source == EH_SOURCE_ID || source == EXH_SOURCE_ID
|
||||
|
||||
fun Source.getMainSource(): Source = if (this is EnhancedHttpSource) {
|
||||
this.source()
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
@JvmName("getMainSourceInline")
|
||||
inline fun <reified T : Source> Source.getMainSource(): T? = if (this is EnhancedHttpSource) {
|
||||
this.source() as? T
|
||||
} else {
|
||||
this as? T
|
||||
}
|
||||
|
||||
fun Source.getOriginalSource(): Source = if (this is EnhancedHttpSource) {
|
||||
this.originalSource
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
fun Source.getEnhancedSource(): Source = if (this is EnhancedHttpSource) {
|
||||
this.enhancedSource
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
inline fun <reified T> Source.anyIs(): Boolean {
|
||||
return if (this is EnhancedHttpSource) {
|
||||
originalSource is T || enhancedSource is T
|
||||
} else {
|
||||
this is T
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package tachiyomi.domain.category.interactor
|
||||
|
||||
import logcat.LogPriority
|
||||
import tachiyomi.core.util.lang.withNonCancellableContext
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.category.model.Category
|
||||
import tachiyomi.domain.category.repository.CategoryRepository
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
|
||||
class CreateCategoryWithName(
|
||||
private val categoryRepository: CategoryRepository,
|
||||
private val preferences: LibraryPreferences,
|
||||
) {
|
||||
|
||||
private val initialFlags: Long
|
||||
get() {
|
||||
val sort = preferences.librarySortingMode().get()
|
||||
return preferences.libraryDisplayMode().get().flag or
|
||||
sort.type.flag or
|
||||
sort.direction.flag
|
||||
}
|
||||
|
||||
suspend fun await(name: String): Result = withNonCancellableContext {
|
||||
val categories = categoryRepository.getAll()
|
||||
val nextOrder = categories.maxOfOrNull { it.order }?.plus(1) ?: 0
|
||||
val newCategory = Category(
|
||||
id = 0,
|
||||
name = name,
|
||||
order = nextOrder,
|
||||
flags = initialFlags,
|
||||
)
|
||||
|
||||
try {
|
||||
categoryRepository.insert(newCategory)
|
||||
Result.Success(/* SY --> */newCategory/* SY <-- */)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
Result.InternalError(e)
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Result {
|
||||
// SY -->
|
||||
data class Success(val category: Category) : Result()
|
||||
|
||||
// SY <--
|
||||
data class InternalError(val error: Throwable) : Result()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package tachiyomi.domain.category.interactor
|
||||
|
||||
import tachiyomi.domain.category.repository.CategoryRepository
|
||||
import tachiyomi.domain.library.model.plus
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
|
||||
class ResetCategoryFlags(
|
||||
private val preferences: LibraryPreferences,
|
||||
private val categoryRepository: CategoryRepository,
|
||||
) {
|
||||
|
||||
suspend fun await() {
|
||||
val display = preferences.libraryDisplayMode().get()
|
||||
val sort = preferences.librarySortingMode().get()
|
||||
categoryRepository.updateAllFlags(display + sort.type + sort.direction)
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package tachiyomi.domain.category.interactor
|
||||
|
||||
import tachiyomi.domain.category.model.Category
|
||||
import tachiyomi.domain.category.model.CategoryUpdate
|
||||
import tachiyomi.domain.category.repository.CategoryRepository
|
||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||
import tachiyomi.domain.library.model.LibraryGroup
|
||||
import tachiyomi.domain.library.model.plus
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
|
||||
class SetDisplayModeForCategory(
|
||||
private val preferences: LibraryPreferences,
|
||||
private val categoryRepository: CategoryRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(categoryId: Long, display: LibraryDisplayMode) {
|
||||
// SY -->
|
||||
if (preferences.groupLibraryBy().get() != LibraryGroup.BY_DEFAULT) {
|
||||
preferences.libraryDisplayMode().set(display)
|
||||
return
|
||||
}
|
||||
// SY <--
|
||||
val category = categoryRepository.get(categoryId) ?: return
|
||||
val flags = category.flags + display
|
||||
if (preferences.categorizedDisplaySettings().get()) {
|
||||
categoryRepository.updatePartial(
|
||||
CategoryUpdate(
|
||||
id = category.id,
|
||||
flags = flags,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
preferences.libraryDisplayMode().set(display)
|
||||
categoryRepository.updateAllFlags(flags)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun await(category: Category, display: LibraryDisplayMode) {
|
||||
await(category.id, display)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package tachiyomi.domain.category.interactor
|
||||
|
||||
import tachiyomi.domain.category.model.Category
|
||||
import tachiyomi.domain.category.model.CategoryUpdate
|
||||
import tachiyomi.domain.category.repository.CategoryRepository
|
||||
import tachiyomi.domain.library.model.LibraryGroup
|
||||
import tachiyomi.domain.library.model.LibrarySort
|
||||
import tachiyomi.domain.library.model.plus
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
|
||||
class SetSortModeForCategory(
|
||||
private val preferences: LibraryPreferences,
|
||||
private val categoryRepository: CategoryRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(categoryId: Long, type: LibrarySort.Type, direction: LibrarySort.Direction) {
|
||||
// SY -->
|
||||
if (preferences.groupLibraryBy().get() != LibraryGroup.BY_DEFAULT) {
|
||||
preferences.librarySortingMode().set(LibrarySort(type, direction))
|
||||
return
|
||||
}
|
||||
// SY <--
|
||||
val category = categoryRepository.get(categoryId) ?: return
|
||||
val flags = category.flags + type + direction
|
||||
if (preferences.categorizedDisplaySettings().get()) {
|
||||
categoryRepository.updatePartial(
|
||||
CategoryUpdate(
|
||||
id = category.id,
|
||||
flags = flags,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
preferences.librarySortingMode().set(LibrarySort(type, direction))
|
||||
categoryRepository.updateAllFlags(flags)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun await(category: Category, type: LibrarySort.Type, direction: LibrarySort.Direction) {
|
||||
await(category.id, type, direction)
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package tachiyomi.domain.chapter.interactor
|
||||
|
||||
import exh.source.MERGED_SOURCE_ID
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import logcat.LogPriority
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.repository.ChapterRepository
|
||||
import tachiyomi.domain.manga.interactor.GetMergedReferencesById
|
||||
import tachiyomi.domain.manga.model.MergedMangaReference
|
||||
|
||||
class GetMergedChapterByMangaId(
|
||||
private val chapterRepository: ChapterRepository,
|
||||
private val getMergedReferencesById: GetMergedReferencesById,
|
||||
) {
|
||||
|
||||
suspend fun await(mangaId: Long, dedupe: Boolean = true): List<Chapter> {
|
||||
return transformMergedChapters(getMergedReferencesById.await(mangaId), getFromDatabase(mangaId), dedupe)
|
||||
}
|
||||
|
||||
suspend fun subscribe(mangaId: Long, dedupe: Boolean = true): Flow<List<Chapter>> {
|
||||
return try {
|
||||
chapterRepository.getMergedChapterByMangaIdAsFlow(mangaId)
|
||||
.combine(getMergedReferencesById.subscribe(mangaId)) { chapters, references ->
|
||||
transformMergedChapters(references, chapters, dedupe)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
flowOf(emptyList())
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getFromDatabase(mangaId: Long): List<Chapter> {
|
||||
return try {
|
||||
chapterRepository.getMergedChapterByMangaId(mangaId)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
fun transformMergedChapters(mangaReferences: List<MergedMangaReference>, chapterList: List<Chapter>, dedupe: Boolean): List<Chapter> {
|
||||
return if (dedupe) dedupeChapterList(mangaReferences, chapterList) else chapterList
|
||||
}
|
||||
|
||||
private fun dedupeChapterList(mangaReferences: List<MergedMangaReference>, chapterList: List<Chapter>): List<Chapter> {
|
||||
return when (mangaReferences.firstOrNull { it.mangaSourceId == MERGED_SOURCE_ID }?.chapterSortMode) {
|
||||
MergedMangaReference.CHAPTER_SORT_NO_DEDUPE, MergedMangaReference.CHAPTER_SORT_NONE -> chapterList
|
||||
MergedMangaReference.CHAPTER_SORT_PRIORITY -> dedupeByPriority(mangaReferences, chapterList)
|
||||
MergedMangaReference.CHAPTER_SORT_MOST_CHAPTERS -> {
|
||||
findSourceWithMostChapters(chapterList)?.let { mangaId ->
|
||||
chapterList.filter { it.mangaId == mangaId }
|
||||
} ?: chapterList
|
||||
}
|
||||
MergedMangaReference.CHAPTER_SORT_HIGHEST_CHAPTER_NUMBER -> {
|
||||
findSourceWithHighestChapterNumber(chapterList)?.let { mangaId ->
|
||||
chapterList.filter { it.mangaId == mangaId }
|
||||
} ?: chapterList
|
||||
}
|
||||
else -> chapterList
|
||||
}
|
||||
}
|
||||
|
||||
private fun findSourceWithMostChapters(chapterList: List<Chapter>): Long? {
|
||||
return chapterList.groupBy { it.mangaId }.maxByOrNull { it.value.size }?.key
|
||||
}
|
||||
|
||||
private fun findSourceWithHighestChapterNumber(chapterList: List<Chapter>): Long? {
|
||||
return chapterList.maxByOrNull { it.chapterNumber }?.mangaId
|
||||
}
|
||||
|
||||
private fun dedupeByPriority(mangaReferences: List<MergedMangaReference>, chapterList: List<Chapter>): List<Chapter> {
|
||||
val sortedChapterList = mutableListOf<Chapter>()
|
||||
|
||||
var existingChapterIndex: Int
|
||||
chapterList.groupBy { it.mangaId }
|
||||
.entries
|
||||
.sortedBy { (mangaId) ->
|
||||
mangaReferences.find { it.mangaId == mangaId }?.chapterPriority ?: Int.MAX_VALUE
|
||||
}
|
||||
.forEach { (_, chapters) ->
|
||||
existingChapterIndex = -1
|
||||
chapters.forEach { chapter ->
|
||||
val oldChapterIndex = existingChapterIndex
|
||||
if (chapter.isRecognizedNumber) {
|
||||
existingChapterIndex = sortedChapterList.indexOfFirst {
|
||||
it.isRecognizedNumber && it.chapterNumber == chapter.chapterNumber && // check if the chapter is not already there
|
||||
it.mangaId != chapter.mangaId // allow multiple chapters of the same number from the same source
|
||||
}
|
||||
if (existingChapterIndex == -1) {
|
||||
sortedChapterList.add(oldChapterIndex + 1, chapter)
|
||||
existingChapterIndex = oldChapterIndex + 1
|
||||
}
|
||||
} else {
|
||||
sortedChapterList.add(oldChapterIndex + 1, chapter)
|
||||
existingChapterIndex = oldChapterIndex + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sortedChapterList.mapIndexed { index, chapter ->
|
||||
chapter.copy(sourceOrder = index.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package tachiyomi.domain.chapter.interactor
|
||||
|
||||
import tachiyomi.core.util.lang.withNonCancellableContext
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
import tachiyomi.domain.manga.interactor.GetFavorites
|
||||
import tachiyomi.domain.manga.interactor.SetMangaChapterFlags
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
|
||||
class SetMangaDefaultChapterFlags(
|
||||
private val libraryPreferences: LibraryPreferences,
|
||||
private val setMangaChapterFlags: SetMangaChapterFlags,
|
||||
private val getFavorites: GetFavorites,
|
||||
) {
|
||||
|
||||
suspend fun await(manga: Manga) {
|
||||
withNonCancellableContext {
|
||||
with(libraryPreferences) {
|
||||
setMangaChapterFlags.awaitSetAllFlags(
|
||||
mangaId = manga.id,
|
||||
unreadFilter = filterChapterByRead().get(),
|
||||
downloadedFilter = filterChapterByDownloaded().get(),
|
||||
bookmarkedFilter = filterChapterByBookmarked().get(),
|
||||
sortingMode = sortChapterBySourceOrNumber().get(),
|
||||
sortingDirection = sortChapterByAscendingOrDescending().get(),
|
||||
displayMode = displayChapterByNameOrNumber().get(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun awaitAll() {
|
||||
withNonCancellableContext {
|
||||
getFavorites.await().forEach { await(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package tachiyomi.domain.history.interactor
|
||||
|
||||
import tachiyomi.domain.history.model.History
|
||||
import tachiyomi.domain.history.repository.HistoryRepository
|
||||
|
||||
class GetHistoryByMangaId(
|
||||
private val repository: HistoryRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(mangaId: Long): List<History> {
|
||||
return repository.getByMangaId(mangaId)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package tachiyomi.domain.history.interactor
|
||||
|
||||
import exh.source.MERGED_SOURCE_ID
|
||||
import exh.source.isEhBasedManga
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChapterByMangaId
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.service.getChapterSort
|
||||
import tachiyomi.domain.history.repository.HistoryRepository
|
||||
import tachiyomi.domain.manga.interactor.GetManga
|
||||
import kotlin.math.max
|
||||
|
||||
class GetNextChapters(
|
||||
private val getChapterByMangaId: GetChapterByMangaId,
|
||||
// SY -->
|
||||
private val getMergedChapterByMangaId: GetMergedChapterByMangaId,
|
||||
// SY <--
|
||||
private val getManga: GetManga,
|
||||
private val historyRepository: HistoryRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(onlyUnread: Boolean = true): List<Chapter> {
|
||||
val history = historyRepository.getLastHistory() ?: return emptyList()
|
||||
return await(history.mangaId, history.chapterId, onlyUnread)
|
||||
}
|
||||
|
||||
suspend fun await(mangaId: Long, onlyUnread: Boolean = true): List<Chapter> {
|
||||
val manga = getManga.await(mangaId) ?: return emptyList()
|
||||
|
||||
// SY -->
|
||||
if (manga.source == MERGED_SOURCE_ID) {
|
||||
val chapters = getMergedChapterByMangaId.await(mangaId)
|
||||
.sortedWith(getChapterSort(manga, sortDescending = false))
|
||||
|
||||
return if (onlyUnread) {
|
||||
chapters.filterNot { it.read }
|
||||
} else {
|
||||
chapters
|
||||
}
|
||||
}
|
||||
if (manga.isEhBasedManga()) {
|
||||
val chapters = getChapterByMangaId.await(mangaId)
|
||||
.sortedWith(getChapterSort(manga, sortDescending = false))
|
||||
|
||||
return if (onlyUnread) {
|
||||
chapters.takeLast(1).takeUnless { it.firstOrNull()?.read == true }.orEmpty()
|
||||
} else {
|
||||
chapters
|
||||
}
|
||||
}
|
||||
// SY <--
|
||||
|
||||
val chapters = getChapterByMangaId.await(mangaId)
|
||||
.sortedWith(getChapterSort(manga, sortDescending = false))
|
||||
|
||||
return if (onlyUnread) {
|
||||
chapters.filterNot { it.read }
|
||||
} else {
|
||||
chapters
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun await(mangaId: Long, fromChapterId: Long, onlyUnread: Boolean = true): List<Chapter> {
|
||||
val chapters = await(mangaId, onlyUnread)
|
||||
val currChapterIndex = chapters.indexOfFirst { it.id == fromChapterId }
|
||||
val nextChapters = chapters.subList(max(0, currChapterIndex), chapters.size)
|
||||
|
||||
if (onlyUnread) {
|
||||
return nextChapters
|
||||
}
|
||||
|
||||
// The "next chapter" is either:
|
||||
// - The current chapter if it isn't completely read
|
||||
// - The chapters after the current chapter if the current one is completely read
|
||||
val fromChapter = chapters.getOrNull(currChapterIndex)
|
||||
return if (fromChapter != null && !fromChapter.read) {
|
||||
nextChapters
|
||||
} else {
|
||||
nextChapters.drop(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package tachiyomi.domain.library.model
|
||||
|
||||
enum class GroupLibraryMode {
|
||||
GLOBAL,
|
||||
ALL_BUT_UNGROUPED,
|
||||
ALL,
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package tachiyomi.domain.library.model
|
||||
|
||||
import tachiyomi.domain.R
|
||||
|
||||
object LibraryGroup {
|
||||
|
||||
const val BY_DEFAULT = 0
|
||||
const val BY_SOURCE = 1
|
||||
const val BY_STATUS = 2
|
||||
const val BY_TRACK_STATUS = 3
|
||||
const val UNGROUPED = 4
|
||||
|
||||
fun groupTypeStringRes(type: Int, hasCategories: Boolean = true): Int {
|
||||
return when (type) {
|
||||
BY_STATUS -> R.string.status
|
||||
BY_SOURCE -> R.string.label_sources
|
||||
BY_TRACK_STATUS -> R.string.tracking_status
|
||||
UNGROUPED -> R.string.ungrouped
|
||||
else -> if (hasCategories) R.string.categories else R.string.ungrouped
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package tachiyomi.domain.library.service
|
||||
|
||||
import tachiyomi.core.preference.PreferenceStore
|
||||
import tachiyomi.core.preference.getEnum
|
||||
import tachiyomi.domain.library.model.GroupLibraryMode
|
||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||
import tachiyomi.domain.library.model.LibraryGroup
|
||||
import tachiyomi.domain.library.model.LibrarySort
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.manga.model.TriStateFilter
|
||||
|
||||
class LibraryPreferences(
|
||||
private val preferenceStore: PreferenceStore,
|
||||
) {
|
||||
|
||||
fun libraryDisplayMode() = preferenceStore.getObject("pref_display_mode_library", LibraryDisplayMode.default, LibraryDisplayMode.Serializer::serialize, LibraryDisplayMode.Serializer::deserialize)
|
||||
|
||||
fun librarySortingMode() = preferenceStore.getObject("library_sorting_mode", LibrarySort.default, LibrarySort.Serializer::serialize, LibrarySort.Serializer::deserialize)
|
||||
|
||||
fun portraitColumns() = preferenceStore.getInt("pref_library_columns_portrait_key", 0)
|
||||
|
||||
fun landscapeColumns() = preferenceStore.getInt("pref_library_columns_landscape_key", 0)
|
||||
|
||||
fun libraryUpdateInterval() = preferenceStore.getInt("pref_library_update_interval_key", 24)
|
||||
fun libraryUpdateLastTimestamp() = preferenceStore.getLong("library_update_last_timestamp", 0L)
|
||||
|
||||
fun libraryUpdateDeviceRestriction() = preferenceStore.getStringSet(
|
||||
"library_update_restriction",
|
||||
setOf(
|
||||
DEVICE_ONLY_ON_WIFI,
|
||||
),
|
||||
)
|
||||
fun libraryUpdateMangaRestriction() = preferenceStore.getStringSet(
|
||||
"library_update_manga_restriction",
|
||||
setOf(
|
||||
MANGA_HAS_UNREAD,
|
||||
MANGA_NON_COMPLETED,
|
||||
MANGA_NON_READ,
|
||||
),
|
||||
)
|
||||
|
||||
fun autoUpdateMetadata() = preferenceStore.getBoolean("auto_update_metadata", false)
|
||||
|
||||
fun autoUpdateTrackers() = preferenceStore.getBoolean("auto_update_trackers", false)
|
||||
|
||||
fun showContinueReadingButton() = preferenceStore.getBoolean("display_continue_reading_button", false)
|
||||
|
||||
// region Filter
|
||||
|
||||
fun filterDownloaded() = preferenceStore.getEnum("pref_filter_library_downloaded_v2", TriStateFilter.DISABLED)
|
||||
|
||||
fun filterUnread() = preferenceStore.getEnum("pref_filter_library_unread_v2", TriStateFilter.DISABLED)
|
||||
|
||||
fun filterStarted() = preferenceStore.getEnum("pref_filter_library_started_v2", TriStateFilter.DISABLED)
|
||||
|
||||
fun filterBookmarked() = preferenceStore.getEnum("pref_filter_library_bookmarked_v2", TriStateFilter.DISABLED)
|
||||
|
||||
fun filterCompleted() = preferenceStore.getEnum("pref_filter_library_completed_v2", TriStateFilter.DISABLED)
|
||||
|
||||
// SY -->
|
||||
fun filterLewd() = preferenceStore.getEnum("pref_filter_library_lewd_v2", TriStateFilter.DISABLED)
|
||||
// SY <--
|
||||
|
||||
fun filterTracking(id: Int) = preferenceStore.getEnum("pref_filter_library_tracked_${id}_v2", TriStateFilter.DISABLED)
|
||||
|
||||
// endregion
|
||||
|
||||
// region Badges
|
||||
|
||||
fun downloadBadge() = preferenceStore.getBoolean("display_download_badge", false)
|
||||
|
||||
fun localBadge() = preferenceStore.getBoolean("display_local_badge", true)
|
||||
|
||||
fun languageBadge() = preferenceStore.getBoolean("display_language_badge", false)
|
||||
|
||||
fun newShowUpdatesCount() = preferenceStore.getBoolean("library_show_updates_count", true)
|
||||
fun newUpdatesCount() = preferenceStore.getInt("library_unseen_updates_count", 0)
|
||||
|
||||
// endregion
|
||||
|
||||
// region Category
|
||||
|
||||
fun defaultCategory() = preferenceStore.getInt("default_category", -1)
|
||||
|
||||
fun lastUsedCategory() = preferenceStore.getInt("last_used_category", 0)
|
||||
|
||||
fun categoryTabs() = preferenceStore.getBoolean("display_category_tabs", true)
|
||||
|
||||
fun categoryNumberOfItems() = preferenceStore.getBoolean("display_number_of_items", false)
|
||||
|
||||
fun categorizedDisplaySettings() = preferenceStore.getBoolean("categorized_display", false)
|
||||
|
||||
fun libraryUpdateCategories() = preferenceStore.getStringSet("library_update_categories", emptySet())
|
||||
|
||||
fun libraryUpdateCategoriesExclude() = preferenceStore.getStringSet("library_update_categories_exclude", emptySet())
|
||||
|
||||
// endregion
|
||||
|
||||
// region Chapter
|
||||
|
||||
fun filterChapterByRead() = preferenceStore.getLong("default_chapter_filter_by_read", Manga.SHOW_ALL)
|
||||
|
||||
fun filterChapterByDownloaded() = preferenceStore.getLong("default_chapter_filter_by_downloaded", Manga.SHOW_ALL)
|
||||
|
||||
fun filterChapterByBookmarked() = preferenceStore.getLong("default_chapter_filter_by_bookmarked", Manga.SHOW_ALL)
|
||||
|
||||
// and upload date
|
||||
fun sortChapterBySourceOrNumber() = preferenceStore.getLong("default_chapter_sort_by_source_or_number", Manga.CHAPTER_SORTING_SOURCE)
|
||||
|
||||
fun displayChapterByNameOrNumber() = preferenceStore.getLong("default_chapter_display_by_name_or_number", Manga.CHAPTER_DISPLAY_NAME)
|
||||
|
||||
fun sortChapterByAscendingOrDescending() = preferenceStore.getLong("default_chapter_sort_by_ascending_or_descending", Manga.CHAPTER_SORT_DESC)
|
||||
|
||||
fun setChapterSettingsDefault(manga: Manga) {
|
||||
filterChapterByRead().set(manga.unreadFilterRaw)
|
||||
filterChapterByDownloaded().set(manga.downloadedFilterRaw)
|
||||
filterChapterByBookmarked().set(manga.bookmarkedFilterRaw)
|
||||
sortChapterBySourceOrNumber().set(manga.sorting)
|
||||
displayChapterByNameOrNumber().set(manga.displayMode)
|
||||
sortChapterByAscendingOrDescending().set(if (manga.sortDescending()) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC)
|
||||
}
|
||||
|
||||
fun autoClearChapterCache() = preferenceStore.getBoolean("auto_clear_chapter_cache", false)
|
||||
|
||||
// endregion
|
||||
|
||||
// SY -->
|
||||
|
||||
fun sortTagsForLibrary() = preferenceStore.getStringSet("sort_tags_for_library", mutableSetOf())
|
||||
|
||||
fun groupLibraryUpdateType() = preferenceStore.getEnum("group_library_update_type", GroupLibraryMode.GLOBAL)
|
||||
|
||||
fun groupLibraryBy() = preferenceStore.getInt("group_library_by", LibraryGroup.BY_DEFAULT)
|
||||
|
||||
// SY <--
|
||||
|
||||
companion object {
|
||||
const val DEVICE_ONLY_ON_WIFI = "wifi"
|
||||
const val DEVICE_NETWORK_NOT_METERED = "network_not_metered"
|
||||
const val DEVICE_CHARGING = "ac"
|
||||
const val DEVICE_BATTERY_NOT_LOW = "battery_not_low"
|
||||
|
||||
const val MANGA_NON_COMPLETED = "manga_ongoing"
|
||||
const val MANGA_HAS_UNREAD = "manga_fully_read"
|
||||
const val MANGA_NON_READ = "manga_started"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package tachiyomi.domain.manga.interactor
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import logcat.LogPriority
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.manga.model.MergedMangaReference
|
||||
import tachiyomi.domain.manga.repository.MangaMergeRepository
|
||||
|
||||
class GetMergedReferencesById(
|
||||
private val mangaMergeRepository: MangaMergeRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(id: Long): List<MergedMangaReference> {
|
||||
return try {
|
||||
mangaMergeRepository.getReferencesById(id)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun subscribe(id: Long): Flow<List<MergedMangaReference>> {
|
||||
return mangaMergeRepository.subscribeReferencesById(id)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package tachiyomi.domain.source.interactor
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import tachiyomi.domain.source.repository.SourcePagingSourceType
|
||||
import tachiyomi.domain.source.repository.SourceRepository
|
||||
|
||||
class GetRemoteManga(
|
||||
private val repository: SourceRepository,
|
||||
) {
|
||||
|
||||
fun subscribe(sourceId: Long, query: String, filterList: FilterList): SourcePagingSourceType {
|
||||
return when (query) {
|
||||
QUERY_POPULAR -> repository.getPopular(sourceId)
|
||||
QUERY_LATEST -> repository.getLatest(sourceId)
|
||||
else -> repository.search(sourceId, query, filterList)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val QUERY_POPULAR = "eu.kanade.domain.source.interactor.POPULAR"
|
||||
const val QUERY_LATEST = "eu.kanade.domain.source.interactor.LATEST"
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package tachiyomi.domain.source.interactor
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import tachiyomi.domain.source.model.SourceWithCount
|
||||
import tachiyomi.domain.source.repository.SourceRepository
|
||||
|
||||
class GetSourcesWithNonLibraryManga(
|
||||
private val repository: SourceRepository,
|
||||
) {
|
||||
|
||||
fun subscribe(): Flow<List<SourceWithCount>> {
|
||||
return repository.getSourcesWithNonLibraryManga()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package tachiyomi.domain.source.repository
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import exh.metadata.metadata.base.RaisedSearchMetadata
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import tachiyomi.domain.source.model.Source
|
||||
import tachiyomi.domain.source.model.SourceWithCount
|
||||
|
||||
typealias SourcePagingSourceType = PagingSource<Long, /*SY --> */ Pair<SManga, RaisedSearchMetadata?>/*SY <-- */>
|
||||
|
||||
interface SourceRepository {
|
||||
|
||||
fun getSources(): Flow<List<Source>>
|
||||
|
||||
fun getOnlineSources(): Flow<List<Source>>
|
||||
|
||||
fun getSourcesWithFavoriteCount(): Flow<List<Pair<Source, Long>>>
|
||||
|
||||
fun getSourcesWithNonLibraryManga(): Flow<List<SourceWithCount>>
|
||||
|
||||
fun search(sourceId: Long, query: String, filterList: FilterList): SourcePagingSourceType
|
||||
|
||||
fun getPopular(sourceId: Long): SourcePagingSourceType
|
||||
|
||||
fun getLatest(sourceId: Long): SourcePagingSourceType
|
||||
}
|
||||
Reference in New Issue
Block a user