From 922f115c78e8d787e6c07d5c46e96d25dd69b7bc Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Tue, 20 Jul 2021 14:50:31 -0400 Subject: [PATCH] Fixed completed oneshots not being added correctly Fixes #939 --- .../tachiyomi/data/database/models/Manga.kt | 17 ++++++++++++++++- .../kanade/tachiyomi/data/track/TrackService.kt | 11 +++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index 64ec782f8b..39f9287830 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.database.models import android.content.Context import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SManga @@ -146,7 +147,7 @@ interface Manga : SManga { */ fun defaultReaderType(): Int { val sourceName = Injekt.get().getOrStub(source).name - val currentTags = genre?.split(",")?.map { it.trim().toLowerCase(Locale.US) } ?: emptyList() + val currentTags = genre?.split(",")?.map { it.trim().lowercase(Locale.US) } ?: emptyList() return if (currentTags.any { tag -> isManhwaTag(tag) || tag.contains("webtoon") @@ -219,6 +220,20 @@ interface Manga : SManga { sourceName.contains("ComicExtra", true) } + fun isOneShotOrCompleted(db: DatabaseHelper): Boolean { + val tags by lazy { genre?.split(",")?.map { it.trim().lowercase(Locale.US) } } + val chapters by lazy { db.getChapters(this).executeAsBlocking() } + val firstChapterName by lazy { chapters.firstOrNull()?.name?.lowercase() ?: "" } + return status == SManga.COMPLETED || tags?.contains("oneshot") == true || + ( + chapters.size == 1 && + ( + Regex("one.?shot").containsMatchIn(firstChapterName) || + firstChapterName.contains("oneshot") + ) + ) + } + fun key(): String { return "manga-id-$id" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt index 7b75bd70c0..2dacdeba7a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt @@ -8,7 +8,6 @@ import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.network.NetworkHelper -import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.util.system.executeOnIO import okhttp3.OkHttpClient import uy.kohesive.injekt.injectLazy @@ -85,13 +84,16 @@ abstract class TrackService(val id: Int) { } suspend fun TrackService.updateNewTrackInfo(track: Track, planningStatus: Int) { - val allRead = db.getManga(track.manga_id).executeOnIO()?.status == SManga.COMPLETED && + val manga = db.getManga(track.manga_id).executeOnIO() + val allRead = manga?.isOneShotOrCompleted(db) == true && db.getChapters(track.manga_id).executeOnIO().all { it.read } if (supportsReadingDates) { track.started_reading_date = getStartDate(track) track.finished_reading_date = getCompletedDate(track, allRead) } - track.last_chapter_read = getLastChapterRead(track) + track.last_chapter_read = getLastChapterRead(track).takeUnless { + it == 0 && allRead + } ?: 1 if (track.last_chapter_read == 0) { track.status = planningStatus } @@ -120,5 +122,6 @@ suspend fun TrackService.getCompletedDate(track: Track, allRead: Boolean): Long suspend fun TrackService.getLastChapterRead(track: Track): Int { val chapters = db.getChapters(track.manga_id).executeOnIO() - return chapters.filter { it.read }.minByOrNull { it.source_order }?.chapter_number?.toInt() ?: 0 + val lastChapterRead = chapters.filter { it.read }.minByOrNull { it.source_order } + return lastChapterRead?.takeIf { it.isRecognizedNumber }?.chapter_number?.toInt() ?: 0 }