Fix chapter list live update (#7296)

This commit is contained in:
AntsyLich
2022-06-12 21:23:41 +06:00
committed by GitHub
parent e7695aef78
commit b96686e6ad
8 changed files with 64 additions and 32 deletions

View File

@@ -0,0 +1,31 @@
package eu.kanade.domain.chapter.interactor
import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.chapter.repository.ChapterRepository
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import logcat.LogPriority
class GetChapterByMangaId(
private val chapterRepository: ChapterRepository,
) {
suspend fun await(mangaId: Long): List<Chapter> {
return try {
chapterRepository.getChapterByMangaId(mangaId)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
emptyList()
}
}
suspend fun subscribe(mangaId: Long): Flow<List<Chapter>> {
return try {
chapterRepository.getChapterByMangaIdFlow(mangaId)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
flowOf(emptyList())
}
}
}

View File

@@ -25,6 +25,7 @@ class SyncChaptersWithSource(
private val chapterRepository: ChapterRepository = Injekt.get(),
private val shouldUpdateDbChapter: ShouldUpdateDbChapter = Injekt.get(),
private val updateManga: UpdateManga = Injekt.get(),
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
) {
suspend fun await(
@@ -45,7 +46,7 @@ class SyncChaptersWithSource(
}
// Chapters from db.
val dbChapters = chapterRepository.getChapterByMangaId(manga.id)
val dbChapters = getChapterByMangaId.await(manga.id)
// Chapters from the source not in db.
val toAdd = mutableListOf<Chapter>()

View File

@@ -2,6 +2,7 @@ package eu.kanade.domain.chapter.repository
import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.chapter.model.ChapterUpdate
import kotlinx.coroutines.flow.Flow
interface ChapterRepository {
@@ -14,4 +15,6 @@ interface ChapterRepository {
suspend fun removeChaptersWithIds(chapterIds: List<Long>)
suspend fun getChapterByMangaId(mangaId: Long): List<Chapter>
suspend fun getChapterByMangaIdFlow(mangaId: Long): Flow<List<Chapter>>
}