Clean up chapter restoring logic a bit
(cherry picked from commit ce5e10be955d8166f53de8118f8f12e76546b5ea) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/MigrateDialog.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt # domain/src/main/java/tachiyomi/domain/history/interactor/GetNextChapters.kt
This commit is contained in:
parent
c99e4cc94b
commit
dfb3e2da8e
@ -40,8 +40,8 @@ import tachiyomi.domain.category.interactor.SetSortModeForCategory
|
||||
import tachiyomi.domain.category.interactor.UpdateCategory
|
||||
import tachiyomi.domain.category.repository.CategoryRepository
|
||||
import tachiyomi.domain.chapter.interactor.GetChapter
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByUrlAndMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.SetMangaDefaultChapterFlags
|
||||
import tachiyomi.domain.chapter.interactor.ShouldUpdateDbChapter
|
||||
import tachiyomi.domain.chapter.interactor.UpdateChapter
|
||||
@ -128,7 +128,7 @@ class DomainModule : InjektModule {
|
||||
|
||||
addSingletonFactory<ChapterRepository> { ChapterRepositoryImpl(get()) }
|
||||
addFactory { GetChapter(get()) }
|
||||
addFactory { GetChapterByMangaId(get()) }
|
||||
addFactory { GetChaptersByMangaId(get()) }
|
||||
addFactory { GetChapterByUrlAndMangaId(get()) }
|
||||
addFactory { UpdateChapter(get()) }
|
||||
addFactory { SetReadStatus(get(), get(), get(), get(), get()) }
|
||||
|
@ -25,7 +25,7 @@ import tachiyomi.data.source.FeedSavedSearchRepositoryImpl
|
||||
import tachiyomi.data.source.SavedSearchRepositoryImpl
|
||||
import tachiyomi.domain.chapter.interactor.DeleteChapters
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByUrl
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChaptersByMangaId
|
||||
import tachiyomi.domain.history.interactor.GetHistoryByMangaId
|
||||
import tachiyomi.domain.manga.interactor.DeleteByMergeId
|
||||
import tachiyomi.domain.manga.interactor.DeleteFavoriteEntries
|
||||
@ -130,7 +130,7 @@ class SYDomainModule : InjektModule {
|
||||
addFactory { GetMergedManga(get()) }
|
||||
addFactory { GetMergedMangaById(get()) }
|
||||
addFactory { GetMergedReferencesById(get()) }
|
||||
addFactory { GetMergedChapterByMangaId(get(), get()) }
|
||||
addFactory { GetMergedChaptersByMangaId(get(), get()) }
|
||||
addFactory { InsertMergedReference(get()) }
|
||||
addFactory { UpdateMergedSettings(get()) }
|
||||
addFactory { DeleteByMergeId(get()) }
|
||||
|
@ -5,7 +5,7 @@ import exh.source.MERGED_SOURCE_ID
|
||||
import logcat.LogPriority
|
||||
import tachiyomi.core.util.lang.withNonCancellableContext
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.model.ChapterUpdate
|
||||
import tachiyomi.domain.chapter.repository.ChapterRepository
|
||||
@ -19,7 +19,7 @@ class SetReadStatus(
|
||||
private val mangaRepository: MangaRepository,
|
||||
private val chapterRepository: ChapterRepository,
|
||||
// SY -->
|
||||
private val getMergedChapterByMangaId: GetMergedChapterByMangaId,
|
||||
private val getMergedChaptersByMangaId: GetMergedChaptersByMangaId,
|
||||
// SY <--
|
||||
) {
|
||||
|
||||
@ -78,7 +78,7 @@ class SetReadStatus(
|
||||
private suspend fun awaitMerged(mangaId: Long, read: Boolean) = withNonCancellableContext f@{
|
||||
return@f await(
|
||||
read = read,
|
||||
chapters = getMergedChapterByMangaId
|
||||
chapters = getMergedChaptersByMangaId
|
||||
.await(mangaId, dedupe = false)
|
||||
.toTypedArray(),
|
||||
)
|
||||
|
@ -11,7 +11,7 @@ import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import exh.source.isEhBasedManga
|
||||
import tachiyomi.data.chapter.ChapterSanitizer
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.ShouldUpdateDbChapter
|
||||
import tachiyomi.domain.chapter.interactor.UpdateChapter
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
@ -33,7 +33,7 @@ class SyncChaptersWithSource(
|
||||
private val shouldUpdateDbChapter: ShouldUpdateDbChapter,
|
||||
private val updateManga: UpdateManga,
|
||||
private val updateChapter: UpdateChapter,
|
||||
private val getChapterByMangaId: GetChapterByMangaId,
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId,
|
||||
) {
|
||||
|
||||
/**
|
||||
@ -67,7 +67,7 @@ class SyncChaptersWithSource(
|
||||
}
|
||||
|
||||
// Chapters from db.
|
||||
val dbChapters = getChapterByMangaId.await(manga.id)
|
||||
val dbChapters = getChaptersByMangaId.await(manga.id)
|
||||
|
||||
// Chapters from the source not in db.
|
||||
val toAdd = mutableListOf<Chapter>()
|
||||
|
@ -2,7 +2,6 @@ package eu.kanade.domain.chapter.model
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.ChapterImpl
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import tachiyomi.data.Chapters
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter as DbChapter
|
||||
|
||||
@ -27,16 +26,6 @@ fun Chapter.copyFromSChapter(sChapter: SChapter): Chapter {
|
||||
)
|
||||
}
|
||||
|
||||
fun Chapter.copyFrom(other: Chapters): Chapter {
|
||||
return copy(
|
||||
name = other.name,
|
||||
url = other.url,
|
||||
dateUpload = other.date_upload,
|
||||
chapterNumber = other.chapter_number,
|
||||
scanlator = other.scanlator?.ifBlank { null },
|
||||
)
|
||||
}
|
||||
|
||||
fun Chapter.toDbChapter(): DbChapter = ChapterImpl().also {
|
||||
it.id = id
|
||||
it.manga_id = mangaId
|
||||
|
@ -7,18 +7,18 @@ import eu.kanade.tachiyomi.data.cache.PagePreviewCache
|
||||
import eu.kanade.tachiyomi.source.PagePreviewSource
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import exh.source.getMainSource
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
|
||||
class GetPagePreviews(
|
||||
private val pagePreviewCache: PagePreviewCache,
|
||||
private val getChapters: GetChapterByMangaId,
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId,
|
||||
) {
|
||||
|
||||
suspend fun await(manga: Manga, source: Source, page: Int): Result {
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val source = source.getMainSource<PagePreviewSource>() ?: return Result.Unused
|
||||
val chapters = getChapters.await(manga.id).sortedByDescending { it.sourceOrder }
|
||||
val chapters = getChaptersByMangaId.await(manga.id).sortedByDescending { it.sourceOrder }
|
||||
val chapterIds = chapters.map { it.id }
|
||||
return try {
|
||||
val pagePreviews = try {
|
||||
|
@ -5,7 +5,7 @@ import eu.kanade.tachiyomi.data.track.EnhancedTracker
|
||||
import eu.kanade.tachiyomi.data.track.Tracker
|
||||
import logcat.LogPriority
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.UpdateChapter
|
||||
import tachiyomi.domain.chapter.model.toChapterUpdate
|
||||
import tachiyomi.domain.track.interactor.InsertTrack
|
||||
@ -14,7 +14,7 @@ import tachiyomi.domain.track.model.Track
|
||||
class SyncChapterProgressWithTrack(
|
||||
private val updateChapter: UpdateChapter,
|
||||
private val insertTrack: InsertTrack,
|
||||
private val getChapterByMangaId: GetChapterByMangaId,
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId,
|
||||
) {
|
||||
|
||||
suspend fun await(
|
||||
@ -26,7 +26,7 @@ class SyncChapterProgressWithTrack(
|
||||
return
|
||||
}
|
||||
|
||||
val sortedChapters = getChapterByMangaId.await(mangaId)
|
||||
val sortedChapters = getChaptersByMangaId.await(mangaId)
|
||||
.sortedBy { it.chapterNumber }
|
||||
.filter { it.isRecognizedNumber }
|
||||
|
||||
|
@ -77,10 +77,9 @@ import tachiyomi.core.util.lang.launchNonCancellable
|
||||
import tachiyomi.core.util.lang.withUIContext
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.UnsortedPreferences
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.manga.interactor.GetAllManga
|
||||
import tachiyomi.domain.manga.interactor.ResetViewerFlags
|
||||
import tachiyomi.domain.manga.repository.MangaRepository
|
||||
import tachiyomi.domain.source.service.SourceManager
|
||||
import tachiyomi.presentation.core.components.LabeledCheckbox
|
||||
import tachiyomi.presentation.core.util.collectAsState
|
||||
@ -497,7 +496,7 @@ object SettingsAdvancedScreen : SearchableSettings {
|
||||
)
|
||||
mangaFolder.delete()
|
||||
} else {
|
||||
val chapterList = Injekt.get<GetChapterByMangaId>().await(manga.id)
|
||||
val chapterList = Injekt.get<GetChaptersByMangaId>().await(manga.id)
|
||||
foldersCleared += downloadManager.cleanupChapters(
|
||||
chapterList,
|
||||
manga,
|
||||
|
@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.data.backup
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import eu.kanade.domain.chapter.model.copyFrom
|
||||
import eu.kanade.domain.manga.interactor.UpdateManga
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.backup.models.BackupCategory
|
||||
@ -41,6 +40,7 @@ import tachiyomi.data.UpdateStrategyColumnAdapter
|
||||
import tachiyomi.data.manga.MangaMapper
|
||||
import tachiyomi.data.manga.MergedMangaMapper
|
||||
import tachiyomi.domain.category.interactor.GetCategories
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.history.model.HistoryUpdate
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
@ -68,6 +68,7 @@ class BackupRestorer(
|
||||
private val handler: DatabaseHandler = Injekt.get()
|
||||
private val updateManga: UpdateManga = Injekt.get()
|
||||
private val getCategories: GetCategories = Injekt.get()
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId = Injekt.get()
|
||||
private val fetchInterval: FetchInterval = Injekt.get()
|
||||
|
||||
private val preferenceStore: PreferenceStore = Injekt.get()
|
||||
@ -354,30 +355,39 @@ class BackupRestorer(
|
||||
}
|
||||
|
||||
private suspend fun restoreChapters(manga: Manga, chapters: List<Chapter>) {
|
||||
val dbChapters = handler.awaitList { chaptersQueries.getChaptersByMangaId(manga.id) }
|
||||
val dbChaptersByUrl = getChaptersByMangaId.await(manga.id)
|
||||
.associateBy { it.url }
|
||||
|
||||
val processed = chapters.map { chapter ->
|
||||
var updatedChapter = chapter
|
||||
val dbChapter = dbChapters.find { it.url == updatedChapter.url }
|
||||
|
||||
val dbChapter = dbChaptersByUrl[updatedChapter.url]
|
||||
if (dbChapter != null) {
|
||||
updatedChapter = updatedChapter.copy(id = dbChapter._id)
|
||||
updatedChapter = updatedChapter.copyFrom(dbChapter)
|
||||
updatedChapter = updatedChapter
|
||||
.copyFrom(dbChapter)
|
||||
.copy(
|
||||
id = dbChapter.id,
|
||||
mangaId = manga.id,
|
||||
bookmark = updatedChapter.bookmark || dbChapter.bookmark,
|
||||
)
|
||||
if (dbChapter.read && !updatedChapter.read) {
|
||||
updatedChapter = updatedChapter.copy(read = true, lastPageRead = dbChapter.last_page_read)
|
||||
} else if (updatedChapter.lastPageRead == 0L && dbChapter.last_page_read != 0L) {
|
||||
updatedChapter = updatedChapter.copy(lastPageRead = dbChapter.last_page_read)
|
||||
}
|
||||
if (!updatedChapter.bookmark && dbChapter.bookmark) {
|
||||
updatedChapter = updatedChapter.copy(bookmark = true)
|
||||
updatedChapter = updatedChapter.copy(
|
||||
read = true,
|
||||
lastPageRead = dbChapter.lastPageRead,
|
||||
)
|
||||
} else if (updatedChapter.lastPageRead == 0L && dbChapter.lastPageRead != 0L) {
|
||||
updatedChapter = updatedChapter.copy(
|
||||
lastPageRead = dbChapter.lastPageRead,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
updatedChapter.copy(mangaId = manga.id)
|
||||
updatedChapter
|
||||
}
|
||||
|
||||
val newChapters = processed.groupBy { it.id > 0 }
|
||||
newChapters[true]?.let { updateKnownChapters(it) }
|
||||
newChapters[false]?.let { insertChapters(it) }
|
||||
val (existingChapters, newChapters) = processed.partition { it.id > 0 }
|
||||
updateKnownChapters(existingChapters)
|
||||
insertChapters(newChapters)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ import okhttp3.OkHttpClient
|
||||
import tachiyomi.core.util.lang.withIOContext
|
||||
import tachiyomi.core.util.lang.withUIContext
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.history.interactor.GetHistory
|
||||
import tachiyomi.domain.track.interactor.InsertTrack
|
||||
import uy.kohesive.injekt.Injekt
|
||||
@ -71,7 +71,7 @@ abstract class BaseTracker(
|
||||
item.manga_id = mangaId
|
||||
try {
|
||||
withIOContext {
|
||||
val allChapters = Injekt.get<GetChapterByMangaId>().await(mangaId)
|
||||
val allChapters = Injekt.get<GetChaptersByMangaId>().await(mangaId)
|
||||
val hasReadChapters = allChapters.any { it.read }
|
||||
bind(item, hasReadChapters)
|
||||
|
||||
|
@ -39,7 +39,7 @@ import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.UnsortedPreferences
|
||||
import tachiyomi.domain.category.interactor.GetCategories
|
||||
import tachiyomi.domain.category.interactor.SetMangaCategories
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.UpdateChapter
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.model.ChapterUpdate
|
||||
@ -70,7 +70,7 @@ class MigrationListScreenModel(
|
||||
private val updateManga: UpdateManga = Injekt.get(),
|
||||
private val syncChaptersWithSource: SyncChaptersWithSource = Injekt.get(),
|
||||
private val updateChapter: UpdateChapter = Injekt.get(),
|
||||
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId = Injekt.get(),
|
||||
private val getMergedReferencesById: GetMergedReferencesById = Injekt.get(),
|
||||
private val getHistoryByMangaId: GetHistoryByMangaId = Injekt.get(),
|
||||
private val upsertHistory: UpsertHistory = Injekt.get(),
|
||||
@ -134,7 +134,7 @@ class MigrationListScreenModel(
|
||||
suspend fun getManga(result: SearchResult.Result) = getManga(result.id)
|
||||
suspend fun getManga(id: Long) = getManga.await(id)
|
||||
suspend fun getChapterInfo(result: SearchResult.Result) = getChapterInfo(result.id)
|
||||
suspend fun getChapterInfo(id: Long) = getChapterByMangaId.await(id).let { chapters ->
|
||||
suspend fun getChapterInfo(id: Long) = getChaptersByMangaId.await(id).let { chapters ->
|
||||
MigratingManga.ChapterInfo(
|
||||
latestChapter = chapters.maxOfOrNull { it.chapterNumber },
|
||||
chapterCount = chapters.size,
|
||||
@ -310,10 +310,10 @@ class MigrationListScreenModel(
|
||||
val flags = preferences.migrateFlags().get()
|
||||
// Update chapters read
|
||||
if (MigrationFlags.hasChapters(flags)) {
|
||||
val prevMangaChapters = getChapterByMangaId.await(prevManga.id)
|
||||
val prevMangaChapters = getChaptersByMangaId.await(prevManga.id)
|
||||
val maxChapterRead = prevMangaChapters.filter(Chapter::read)
|
||||
.maxOfOrNull(Chapter::chapterNumber)
|
||||
val dbChapters = getChapterByMangaId.await(manga.id)
|
||||
val dbChapters = getChaptersByMangaId.await(manga.id)
|
||||
val prevHistoryList = getHistoryByMangaId.await(prevManga.id)
|
||||
|
||||
val chapterUpdates = mutableListOf<ChapterUpdate>()
|
||||
|
@ -79,8 +79,8 @@ import tachiyomi.domain.UnsortedPreferences
|
||||
import tachiyomi.domain.category.interactor.GetCategories
|
||||
import tachiyomi.domain.category.interactor.SetMangaCategories
|
||||
import tachiyomi.domain.category.model.Category
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.history.interactor.GetNextChapters
|
||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||
@ -121,7 +121,7 @@ class LibraryScreenModel(
|
||||
private val getCategories: GetCategories = Injekt.get(),
|
||||
private val getTracksPerManga: GetTracksPerManga = Injekt.get(),
|
||||
private val getNextChapters: GetNextChapters = Injekt.get(),
|
||||
private val getChaptersByMangaId: GetChapterByMangaId = Injekt.get(),
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId = Injekt.get(),
|
||||
private val setReadStatus: SetReadStatus = Injekt.get(),
|
||||
private val updateManga: UpdateManga = Injekt.get(),
|
||||
private val setMangaCategories: SetMangaCategories = Injekt.get(),
|
||||
@ -142,7 +142,7 @@ class LibraryScreenModel(
|
||||
private val getSearchTitles: GetSearchTitles = Injekt.get(),
|
||||
private val searchEngine: SearchEngine = Injekt.get(),
|
||||
private val setCustomMangaInfo: SetCustomMangaInfo = Injekt.get(),
|
||||
private val getMergedChapterByMangaId: GetMergedChapterByMangaId = Injekt.get(),
|
||||
private val getMergedChaptersByMangaId: GetMergedChaptersByMangaId = Injekt.get(),
|
||||
// SY <--
|
||||
) : StateScreenModel<LibraryScreenModel.State>(State()) {
|
||||
|
||||
@ -581,7 +581,7 @@ class LibraryScreenModel(
|
||||
// SY -->
|
||||
val mergedManga = getMergedMangaById.await(manga.id).associateBy { it.id }
|
||||
return if (manga.id == MERGED_SOURCE_ID) {
|
||||
getMergedChapterByMangaId.await(manga.id)
|
||||
getMergedChaptersByMangaId.await(manga.id)
|
||||
} else {
|
||||
getChaptersByMangaId.await(manga.id)
|
||||
}.getNextUnread(manga, downloadManager, mergedManga)
|
||||
|
@ -82,7 +82,7 @@ import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.category.interactor.GetCategories
|
||||
import tachiyomi.domain.category.interactor.SetMangaCategories
|
||||
import tachiyomi.domain.category.model.Category
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.SetMangaDefaultChapterFlags
|
||||
import tachiyomi.domain.chapter.interactor.UpdateChapter
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
@ -139,7 +139,7 @@ class MangaScreenModel(
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
private val getManga: GetManga = Injekt.get(),
|
||||
private val setMangaFilteredScanlators: SetMangaFilteredScanlators = Injekt.get(),
|
||||
private val getMergedChapterByMangaId: GetMergedChapterByMangaId = Injekt.get(),
|
||||
private val getMergedChaptersByMangaId: GetMergedChaptersByMangaId = Injekt.get(),
|
||||
private val getMergedMangaById: GetMergedMangaById = Injekt.get(),
|
||||
private val getMergedReferencesById: GetMergedReferencesById = Injekt.get(),
|
||||
private val insertMergedReference: InsertMergedReference = Injekt.get(),
|
||||
@ -239,7 +239,7 @@ class MangaScreenModel(
|
||||
.distinctUntilChanged()
|
||||
// SY -->
|
||||
.combine(
|
||||
getMergedChapterByMangaId.subscribe(mangaId, true)
|
||||
getMergedChaptersByMangaId.subscribe(mangaId, true)
|
||||
.distinctUntilChanged(),
|
||||
) { (manga, chapters), mergedChapters ->
|
||||
if (manga.source == MERGED_SOURCE_ID) {
|
||||
@ -320,7 +320,7 @@ class MangaScreenModel(
|
||||
screenModelScope.launchIO {
|
||||
val manga = getMangaAndChapters.awaitManga(mangaId)
|
||||
// SY -->
|
||||
val chapters = (if (manga.source == MERGED_SOURCE_ID) getMergedChapterByMangaId.await(mangaId) else getMangaAndChapters.awaitChapters(mangaId))
|
||||
val chapters = (if (manga.source == MERGED_SOURCE_ID) getMergedChaptersByMangaId.await(mangaId) else getMangaAndChapters.awaitChapters(mangaId))
|
||||
.toChapterItems(manga, null)
|
||||
val mergedData = getMergedReferencesById.await(mangaId).takeIf { it.isNotEmpty() }?.let { references ->
|
||||
MergedMangaData(
|
||||
|
@ -79,8 +79,8 @@ import tachiyomi.core.util.lang.withUIContext
|
||||
import tachiyomi.core.util.system.ImageUtil
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.decoder.ImageDecoder
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.UpdateChapter
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.model.ChapterUpdate
|
||||
@ -116,7 +116,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
private val trackPreferences: TrackPreferences = Injekt.get(),
|
||||
private val trackChapter: TrackChapter = Injekt.get(),
|
||||
private val getManga: GetManga = Injekt.get(),
|
||||
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId = Injekt.get(),
|
||||
private val getNextChapters: GetNextChapters = Injekt.get(),
|
||||
private val upsertHistory: UpsertHistory = Injekt.get(),
|
||||
private val updateChapter: UpdateChapter = Injekt.get(),
|
||||
@ -126,7 +126,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
private val getFlatMetadataById: GetFlatMetadataById = Injekt.get(),
|
||||
private val getMergedMangaById: GetMergedMangaById = Injekt.get(),
|
||||
private val getMergedReferencesById: GetMergedReferencesById = Injekt.get(),
|
||||
private val getMergedChapterByMangaId: GetMergedChapterByMangaId = Injekt.get(),
|
||||
private val getMergedChaptersByMangaId: GetMergedChaptersByMangaId = Injekt.get(),
|
||||
// SY <--
|
||||
) : ViewModel() {
|
||||
|
||||
@ -181,10 +181,10 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
// SY -->
|
||||
val (chapters, mangaMap) = runBlocking {
|
||||
if (manga.source == MERGED_SOURCE_ID) {
|
||||
getMergedChapterByMangaId.await(manga.id) to getMergedMangaById.await(manga.id)
|
||||
getMergedChaptersByMangaId.await(manga.id) to getMergedMangaById.await(manga.id)
|
||||
.associateBy { it.id }
|
||||
} else {
|
||||
getChapterByMangaId.await(manga.id) to null
|
||||
getChaptersByMangaId.await(manga.id) to null
|
||||
}
|
||||
}
|
||||
fun isChapterDownloaded(chapter: Chapter): Boolean {
|
||||
|
@ -8,8 +8,8 @@ import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import tachiyomi.domain.category.interactor.GetCategories
|
||||
import tachiyomi.domain.category.interactor.SetMangaCategories
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByUrl
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.model.ChapterUpdate
|
||||
import tachiyomi.domain.chapter.repository.ChapterRepository
|
||||
@ -35,7 +35,7 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
GalleryEntry.Serializer(),
|
||||
)
|
||||
private val getChapterByUrl: GetChapterByUrl by injectLazy()
|
||||
private val getChapterByMangaId: GetChapterByMangaId by injectLazy()
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId by injectLazy()
|
||||
private val getManga: GetManga by injectLazy()
|
||||
private val updateManga: UpdateManga by injectLazy()
|
||||
private val setMangaCategories: SetMangaCategories by injectLazy()
|
||||
@ -64,7 +64,7 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
getManga.await(mangaId)
|
||||
}
|
||||
val chapterList = async(Dispatchers.IO) {
|
||||
getChapterByMangaId.await(mangaId)
|
||||
getChaptersByMangaId.await(mangaId)
|
||||
}
|
||||
val history = async(Dispatchers.IO) {
|
||||
getHistoryByMangaId.await(mangaId)
|
||||
@ -115,7 +115,7 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
chapterRepository.updateAll(chapterUpdates)
|
||||
chapterRepository.addAll(newChapters)
|
||||
|
||||
val (newHistory, deleteHistory) = getHistory(getChapterByMangaId.await(accepted.manga.id), chainsAsChapters, chainsAsHistory)
|
||||
val (newHistory, deleteHistory) = getHistory(getChaptersByMangaId.await(accepted.manga.id), chainsAsChapters, chainsAsHistory)
|
||||
|
||||
// Delete the duplicate history first
|
||||
deleteHistory.forEach {
|
||||
|
@ -28,7 +28,7 @@ import kotlinx.coroutines.flow.toList
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import tachiyomi.domain.UnsortedPreferences
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.library.service.LibraryPreferences.Companion.DEVICE_CHARGING
|
||||
import tachiyomi.domain.library.service.LibraryPreferences.Companion.DEVICE_ONLY_ON_WIFI
|
||||
@ -51,7 +51,7 @@ class EHentaiUpdateWorker(private val context: Context, workerParams: WorkerPara
|
||||
private val logger: Logger = xLog()
|
||||
private val updateManga: UpdateManga by injectLazy()
|
||||
private val syncChaptersWithSource: SyncChaptersWithSource by injectLazy()
|
||||
private val getChapterByMangaId: GetChapterByMangaId by injectLazy()
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId by injectLazy()
|
||||
private val getFlatMetadataById: GetFlatMetadataById by injectLazy()
|
||||
private val insertFlatMetadata: InsertFlatMetadata by injectLazy()
|
||||
private val getExhFavoriteMangaWithMetadata: GetExhFavoriteMangaWithMetadata by injectLazy()
|
||||
@ -92,7 +92,7 @@ class EHentaiUpdateWorker(private val context: Context, workerParams: WorkerPara
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
val chapter = getChapterByMangaId.await(manga.id).minByOrNull {
|
||||
val chapter = getChaptersByMangaId.await(manga.id).minByOrNull {
|
||||
it.dateUpload
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ class EHentaiUpdateWorker(private val context: Context, workerParams: WorkerPara
|
||||
val newChapters = source.getChapterList(manga.toSManga())
|
||||
|
||||
val new = syncChaptersWithSource.await(newChapters, manga, source)
|
||||
return new to getChapterByMangaId.await(manga.id)
|
||||
return new to getChaptersByMangaId.await(manga.id)
|
||||
} catch (t: Throwable) {
|
||||
if (t is EHentai.GalleryNotFoundException) {
|
||||
val meta = getFlatMetadataById.await(manga.id)?.raise<EHentaiSearchMetadata>()
|
||||
|
@ -14,7 +14,7 @@ import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.update
|
||||
import tachiyomi.core.util.lang.launchIO
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.manga.interactor.GetManga
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
@ -26,7 +26,7 @@ class PagePreviewScreenModel(
|
||||
private val mangaId: Long,
|
||||
private val getPagePreviews: GetPagePreviews = Injekt.get(),
|
||||
private val getManga: GetManga = Injekt.get(),
|
||||
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId = Injekt.get(),
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
) : StateScreenModel<PagePreviewState>(PagePreviewState.Loading) {
|
||||
|
||||
@ -37,7 +37,7 @@ class PagePreviewScreenModel(
|
||||
init {
|
||||
screenModelScope.launchIO {
|
||||
val manga = getManga.await(mangaId)!!
|
||||
val chapter = getChapterByMangaId.await(mangaId).minByOrNull { it.sourceOrder }
|
||||
val chapter = getChaptersByMangaId.await(mangaId).minByOrNull { it.sourceOrder }
|
||||
if (chapter == null) {
|
||||
mutableState.update {
|
||||
PagePreviewState.Error(Exception("No chapters found"))
|
||||
|
@ -5,7 +5,7 @@ import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.repository.ChapterRepository
|
||||
|
||||
class GetChapterByMangaId(
|
||||
class GetChaptersByMangaId(
|
||||
private val chapterRepository: ChapterRepository,
|
||||
) {
|
||||
|
@ -11,7 +11,7 @@ import tachiyomi.domain.chapter.repository.ChapterRepository
|
||||
import tachiyomi.domain.manga.interactor.GetMergedReferencesById
|
||||
import tachiyomi.domain.manga.model.MergedMangaReference
|
||||
|
||||
class GetMergedChapterByMangaId(
|
||||
class GetMergedChaptersByMangaId(
|
||||
private val chapterRepository: ChapterRepository,
|
||||
private val getMergedReferencesById: GetMergedReferencesById,
|
||||
) {
|
@ -18,6 +18,16 @@ data class Chapter(
|
||||
val isRecognizedNumber: Boolean
|
||||
get() = chapterNumber >= 0f
|
||||
|
||||
fun copyFrom(other: Chapter): Chapter {
|
||||
return copy(
|
||||
name = other.name,
|
||||
url = other.url,
|
||||
dateUpload = other.dateUpload,
|
||||
chapterNumber = other.chapterNumber,
|
||||
scanlator = other.scanlator?.ifBlank { null },
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun create() = Chapter(
|
||||
id = -1,
|
||||
|
@ -2,8 +2,8 @@ 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.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetMergedChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.service.getChapterSort
|
||||
import tachiyomi.domain.history.repository.HistoryRepository
|
||||
@ -11,9 +11,9 @@ import tachiyomi.domain.manga.interactor.GetManga
|
||||
import kotlin.math.max
|
||||
|
||||
class GetNextChapters(
|
||||
private val getChapterByMangaId: GetChapterByMangaId,
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId,
|
||||
// SY -->
|
||||
private val getMergedChapterByMangaId: GetMergedChapterByMangaId,
|
||||
private val getMergedChaptersByMangaId: GetMergedChaptersByMangaId,
|
||||
// SY <--
|
||||
private val getManga: GetManga,
|
||||
private val historyRepository: HistoryRepository,
|
||||
@ -29,7 +29,7 @@ class GetNextChapters(
|
||||
|
||||
// SY -->
|
||||
if (manga.source == MERGED_SOURCE_ID) {
|
||||
val chapters = getMergedChapterByMangaId.await(mangaId)
|
||||
val chapters = getMergedChaptersByMangaId.await(mangaId)
|
||||
.sortedWith(getChapterSort(manga, sortDescending = false))
|
||||
|
||||
return if (onlyUnread) {
|
||||
@ -39,7 +39,7 @@ class GetNextChapters(
|
||||
}
|
||||
}
|
||||
if (manga.isEhBasedManga()) {
|
||||
val chapters = getChapterByMangaId.await(mangaId)
|
||||
val chapters = getChaptersByMangaId.await(mangaId)
|
||||
.sortedWith(getChapterSort(manga, sortDescending = false))
|
||||
|
||||
return if (onlyUnread) {
|
||||
@ -50,7 +50,7 @@ class GetNextChapters(
|
||||
}
|
||||
// SY <--
|
||||
|
||||
val chapters = getChapterByMangaId.await(mangaId)
|
||||
val chapters = getChaptersByMangaId.await(mangaId)
|
||||
.sortedWith(getChapterSort(manga, sortDescending = false))
|
||||
|
||||
return if (onlyUnread) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package tachiyomi.domain.manga.interactor
|
||||
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.manga.model.MangaUpdate
|
||||
@ -11,7 +11,7 @@ import java.time.temporal.ChronoUnit
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
class FetchInterval(
|
||||
private val getChapterByMangaId: GetChapterByMangaId,
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId,
|
||||
) {
|
||||
|
||||
suspend fun toMangaUpdateOrNull(
|
||||
@ -24,7 +24,7 @@ class FetchInterval(
|
||||
} else {
|
||||
window
|
||||
}
|
||||
val chapters = getChapterByMangaId.await(manga.id)
|
||||
val chapters = getChaptersByMangaId.await(manga.id)
|
||||
val interval = manga.fetchInterval.takeIf { it < 0 } ?: calculateInterval(
|
||||
chapters,
|
||||
dateTime.zone,
|
||||
|
Loading…
x
Reference in New Issue
Block a user