From 07d1b9f3bac5df3c469601b8d08ed024b5e607ec Mon Sep 17 00:00:00 2001 From: nzoba <55888232+nzoba@users.noreply.github.com> Date: Sat, 10 Sep 2022 04:29:24 +0200 Subject: [PATCH] Fix download ahead missing out 1 chapter (#7927) * Fix download ahead missing out 1 chapter * Move toLong() function * Add check whether the next chapter is queued --- .../main/java/eu/kanade/data/DatabaseUtils.kt | 3 --- .../data/chapter/ChapterRepositoryImpl.kt | 2 +- .../eu/kanade/data/manga/MangaRepositoryImpl.kt | 2 +- .../tachiyomi/data/backup/BackupManager.kt | 2 +- .../tachiyomi/ui/reader/ReaderPresenter.kt | 17 +++++++++++------ .../tachiyomi/util/system/BooleanExtensions.kt | 5 +++++ 6 files changed, 19 insertions(+), 12 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/data/DatabaseUtils.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/system/BooleanExtensions.kt diff --git a/app/src/main/java/eu/kanade/data/DatabaseUtils.kt b/app/src/main/java/eu/kanade/data/DatabaseUtils.kt deleted file mode 100644 index d46f4b1f8b..0000000000 --- a/app/src/main/java/eu/kanade/data/DatabaseUtils.kt +++ /dev/null @@ -1,3 +0,0 @@ -package eu.kanade.data - -fun Boolean.toLong() = if (this) 1L else 0L diff --git a/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt index b5050670a5..ef724393e7 100644 --- a/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt @@ -1,11 +1,11 @@ package eu.kanade.data.chapter import eu.kanade.data.DatabaseHandler -import eu.kanade.data.toLong import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.chapter.model.ChapterUpdate import eu.kanade.domain.chapter.repository.ChapterRepository import eu.kanade.tachiyomi.util.system.logcat +import eu.kanade.tachiyomi.util.system.toLong import kotlinx.coroutines.flow.Flow import logcat.LogPriority diff --git a/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt index 28f51402e4..1731fb2250 100644 --- a/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt @@ -2,12 +2,12 @@ package eu.kanade.data.manga import eu.kanade.data.DatabaseHandler import eu.kanade.data.listOfStringsAdapter -import eu.kanade.data.toLong import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.MangaUpdate import eu.kanade.domain.manga.repository.MangaRepository import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.util.system.logcat +import eu.kanade.tachiyomi.util.system.toLong import kotlinx.coroutines.flow.Flow import logcat.LogPriority diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt index 76d7568f29..3e45a94b09 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt @@ -6,7 +6,6 @@ import com.hippo.unifile.UniFile import data.Manga_sync import data.Mangas import eu.kanade.data.DatabaseHandler -import eu.kanade.data.toLong import eu.kanade.domain.category.interactor.GetCategories import eu.kanade.domain.category.model.Category import eu.kanade.domain.history.model.HistoryUpdate @@ -35,6 +34,7 @@ import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.util.system.logcat +import eu.kanade.tachiyomi.util.system.toLong import kotlinx.serialization.protobuf.ProtoBuf import logcat.LogPriority import okio.buffer diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index d79ee1ba63..88d4235180 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -54,6 +54,7 @@ import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.storage.cacheImageDir import eu.kanade.tachiyomi.util.system.isOnline import eu.kanade.tachiyomi.util.system.logcat +import eu.kanade.tachiyomi.util.system.toInt import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.runBlocking @@ -449,15 +450,19 @@ class ReaderPresenter( val nextChapter = viewerChaptersRelay.value?.nextChapter?.chapter ?: return val chaptersNumberToDownload = preferences.autoDownloadWhileReading().get() if (chaptersNumberToDownload == 0 || !manga.favorite) return - val isNextChapterDownloaded = - downloadManager.isChapterDownloaded(nextChapter.name, nextChapter.scanlator, manga.title, manga.source) - if (isNextChapterDownloaded) { - downloadAutoNextChapters(chaptersNumberToDownload, nextChapter.id) + val isNextChapterDownloadedOrQueued = downloadManager.isChapterDownloaded( + nextChapter.name, + nextChapter.scanlator, + manga.title, + manga.source, + ) || downloadManager.getChapterDownloadOrNull(nextChapter) != null + if (isNextChapterDownloadedOrQueued) { + downloadAutoNextChapters(chaptersNumberToDownload, nextChapter.id, nextChapter.read) } } - private fun downloadAutoNextChapters(choice: Int, nextChapterId: Long?) { - val chaptersToDownload = getNextUnreadChaptersSorted(nextChapterId).take(choice - 1) + private fun downloadAutoNextChapters(choice: Int, nextChapterId: Long?, isNextChapterRead: Boolean) { + val chaptersToDownload = getNextUnreadChaptersSorted(nextChapterId).take(choice - 1 + isNextChapterRead.toInt()) if (chaptersToDownload.isNotEmpty()) { downloadChapters(chaptersToDownload) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/BooleanExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/BooleanExtensions.kt new file mode 100644 index 0000000000..130205aa5d --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/BooleanExtensions.kt @@ -0,0 +1,5 @@ +package eu.kanade.tachiyomi.util.system + +fun Boolean.toInt() = if (this) 1 else 0 + +fun Boolean.toLong() = if (this) 1L else 0L