mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 03:58:56 +01:00
Minor cleanup
This commit is contained in:
@@ -7,9 +7,8 @@ import eu.kanade.domain.download.interactor.DeleteDownload
|
||||
import eu.kanade.domain.download.service.DownloadPreferences
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.repository.MangaRepository
|
||||
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
import kotlinx.coroutines.withContext
|
||||
import logcat.LogPriority
|
||||
|
||||
class SetReadStatus(
|
||||
@@ -27,49 +26,39 @@ class SetReadStatus(
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun await(read: Boolean, vararg values: Chapter): Result = withContext(NonCancellable) {
|
||||
val chapters = values.filterNot { it.read == read }
|
||||
|
||||
if (chapters.isEmpty()) {
|
||||
return@withContext Result.NoChapters
|
||||
}
|
||||
|
||||
val manga = chapters.fold(mutableSetOf<Manga>()) { acc, chapter ->
|
||||
if (acc.all { it.id != chapter.mangaId }) {
|
||||
acc += mangaRepository.getMangaById(chapter.mangaId)
|
||||
}
|
||||
acc
|
||||
suspend fun await(read: Boolean, vararg chapters: Chapter): Result = withNonCancellableContext {
|
||||
val chaptersToUpdate = chapters.filterNot { it.read == read }
|
||||
if (chaptersToUpdate.isEmpty()) {
|
||||
return@withNonCancellableContext Result.NoChapters
|
||||
}
|
||||
|
||||
try {
|
||||
chapterRepository.updateAll(
|
||||
chapters.map { chapter ->
|
||||
mapper(chapter, read)
|
||||
},
|
||||
chaptersToUpdate.map { mapper(it, read) },
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
return@withContext Result.InternalError(e)
|
||||
return@withNonCancellableContext Result.InternalError(e)
|
||||
}
|
||||
|
||||
if (read && downloadPreferences.removeAfterMarkedAsRead().get()) {
|
||||
manga.forEach {
|
||||
deleteDownload.awaitAll(
|
||||
manga = it,
|
||||
values = chapters
|
||||
.filter { chapter -> it.id == chapter.mangaId }
|
||||
.toTypedArray(),
|
||||
)
|
||||
}
|
||||
chaptersToUpdate
|
||||
.groupBy { it.mangaId }
|
||||
.forEach { (mangaId, chapters) ->
|
||||
deleteDownload.awaitAll(
|
||||
manga = mangaRepository.getMangaById(mangaId),
|
||||
chapters = chapters.toTypedArray(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Result.Success
|
||||
}
|
||||
|
||||
suspend fun await(mangaId: Long, read: Boolean): Result = withContext(NonCancellable) {
|
||||
suspend fun await(mangaId: Long, read: Boolean): Result = withNonCancellableContext {
|
||||
await(
|
||||
read = read,
|
||||
values = chapterRepository
|
||||
chapters = chapterRepository
|
||||
.getChapterByMangaId(mangaId)
|
||||
.toTypedArray(),
|
||||
)
|
||||
|
||||
@@ -9,8 +9,8 @@ import eu.kanade.domain.chapter.repository.ChapterRepository
|
||||
import eu.kanade.domain.manga.interactor.UpdateManga
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.isLocal
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterRecognition
|
||||
@@ -42,7 +42,7 @@ class SyncChaptersWithSource(
|
||||
manga: Manga,
|
||||
source: Source,
|
||||
): List<Chapter> {
|
||||
if (rawSourceChapters.isEmpty() && source.id != LocalSource.ID) {
|
||||
if (rawSourceChapters.isEmpty() && !source.isLocal()) {
|
||||
throw NoChaptersException()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user