Clean up chapter restoring logic a bit

This commit is contained in:
arkon
2023-10-29 11:43:06 -04:00
parent 64ad25d1b5
commit ce5e10be95
13 changed files with 61 additions and 52 deletions

View File

@@ -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,
) {

View File

@@ -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,

View File

@@ -1,6 +1,6 @@
package tachiyomi.domain.history.interactor
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.chapter.service.getChapterSort
import tachiyomi.domain.history.repository.HistoryRepository
@@ -8,7 +8,7 @@ import tachiyomi.domain.manga.interactor.GetManga
import kotlin.math.max
class GetNextChapters(
private val getChapterByMangaId: GetChapterByMangaId,
private val getChaptersByMangaId: GetChaptersByMangaId,
private val getManga: GetManga,
private val historyRepository: HistoryRepository,
) {
@@ -20,7 +20,7 @@ class GetNextChapters(
suspend fun await(mangaId: Long, onlyUnread: Boolean = true): List<Chapter> {
val manga = getManga.await(mangaId) ?: return emptyList()
val chapters = getChapterByMangaId.await(mangaId)
val chapters = getChaptersByMangaId.await(mangaId)
.sortedWith(getChapterSort(manga, sortDescending = false))
return if (onlyUnread) {

View File

@@ -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,