From c0647c311002e66c54c3f85d1d075cd216124c86 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sat, 17 Jul 2021 17:26:29 +0200 Subject: [PATCH] Make default tracking status depend if the user has read chapter or not (#5567) - When user reads a chapter change tracking status to reading --- .../tachiyomi/data/track/TrackService.kt | 8 ++++-- .../tachiyomi/data/track/anilist/Anilist.kt | 23 ++++++++++++++--- .../tachiyomi/data/track/bangumi/Bangumi.kt | 22 +++++++++++++--- .../tachiyomi/data/track/kitsu/Kitsu.kt | 21 +++++++++++++--- .../tachiyomi/data/track/komga/Komga.kt | 14 +++++++++-- .../data/track/myanimelist/MyAnimeList.kt | 25 ++++++++++++++++--- .../data/track/shikimori/Shikimori.kt | 22 +++++++++++++--- .../tachiyomi/ui/manga/MangaPresenter.kt | 6 ++++- .../tachiyomi/ui/reader/ReaderPresenter.kt | 2 +- 9 files changed, 120 insertions(+), 23 deletions(-) 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 41dd5c267..3e59201ba 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 @@ -36,6 +36,10 @@ abstract class TrackService(val id: Int) { abstract fun getStatus(status: Int): String + abstract fun getReadingStatus(): Int + + abstract fun getRereadingStatus(): Int + abstract fun getCompletionStatus(): Int abstract fun getScoreList(): List @@ -46,9 +50,9 @@ abstract class TrackService(val id: Int) { abstract fun displayScore(track: Track): String - abstract suspend fun update(track: Track): Track + abstract suspend fun update(track: Track, didReadChapter: Boolean = false): Track - abstract suspend fun bind(track: Track): Track + abstract suspend fun bind(track: Track, hasReadChapters: Boolean = false): Track abstract suspend fun search(query: String): List diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt index 9d147bf69..efd766855 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt @@ -72,6 +72,10 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { } } + override fun getReadingStatus(): Int = READING + + override fun getRereadingStatus(): Int = REPEATING + override fun getCompletionStatus(): Int = COMPLETED override fun getScoreList(): List { @@ -134,7 +138,7 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { return api.addLibManga(track) } - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, didReadChapter: Boolean): Track { // If user was using API v1 fetch library_id if (track.library_id == null || track.library_id!! == 0L) { val libManga = api.findLibManga(track, getUsername().toInt()) @@ -142,18 +146,31 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { track.library_id = libManga.library_id } + + if (track.status != COMPLETED) { + if (track.status != REPEATING && didReadChapter) { + track.status = READING + } + } + return api.updateLibManga(track) } - override suspend fun bind(track: Track): Track { + override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { val remoteTrack = api.findLibManga(track, getUsername().toInt()) return if (remoteTrack != null) { track.copyPersonalFrom(remoteTrack) track.library_id = remoteTrack.library_id + + if (track.status != COMPLETED) { + val isRereading = track.status == REPEATING + track.status = if (isRereading.not() && hasReadChapters) READING else track.status + } + update(track) } else { // Set default fields if it's not found in the list - track.status = READING + track.status = if (hasReadChapters) READING else PLANNING track.score = 0F add(track) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt index 7347317bf..475f1d53c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt @@ -35,24 +35,34 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { return api.addLibManga(track) } - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, didReadChapter: Boolean): Track { + if (track.status != COMPLETED) { + if (didReadChapter) { + track.status = READING + } + } + return api.updateLibManga(track) } - override suspend fun bind(track: Track): Track { + override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { val statusTrack = api.statusLibManga(track) val remoteTrack = api.findLibManga(track) return if (remoteTrack != null && statusTrack != null) { track.copyPersonalFrom(remoteTrack) track.library_id = remoteTrack.library_id - track.status = statusTrack.status + + if (track.status != COMPLETED) { + track.status = if (hasReadChapters) READING else statusTrack.status + } + track.score = statusTrack.score track.last_chapter_read = statusTrack.last_chapter_read track.total_chapters = remoteTrack.total_chapters refresh(track) } else { // Set default fields if it's not found in the list - track.status = READING + track.status = if (hasReadChapters) READING else PLANNING track.score = 0F add(track) update(track) @@ -91,6 +101,10 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { } } + override fun getReadingStatus(): Int = READING + + override fun getRereadingStatus(): Int = -1 + override fun getCompletionStatus(): Int = COMPLETED override suspend fun login(username: String, password: String) = login(password) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt index be4f53bcf..c2b385a70 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt @@ -51,6 +51,10 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { } } + override fun getReadingStatus(): Int = READING + + override fun getRereadingStatus(): Int = -1 + override fun getCompletionStatus(): Int = COMPLETED override fun getScoreList(): List { @@ -71,18 +75,29 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { return api.addLibManga(track, getUserId()) } - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, didReadChapter: Boolean): Track { + if (track.status != COMPLETED) { + if (didReadChapter) { + track.status = READING + } + } + return api.updateLibManga(track) } - override suspend fun bind(track: Track): Track { + override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { val remoteTrack = api.findLibManga(track, getUserId()) return if (remoteTrack != null) { track.copyPersonalFrom(remoteTrack) track.media_id = remoteTrack.media_id + + if (track.status != COMPLETED) { + track.status = if (hasReadChapters) READING else track.status + } + update(track) } else { - track.status = READING + track.status = if (hasReadChapters) READING else PLAN_TO_READ track.score = 0F add(track) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt index 75d90219d..2d3fa0912 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt @@ -49,17 +49,27 @@ class Komga(private val context: Context, id: Int) : TrackService(id), Unattende } } + override fun getReadingStatus(): Int = READING + + override fun getRereadingStatus(): Int = -1 + override fun getCompletionStatus(): Int = COMPLETED override fun getScoreList(): List = emptyList() override fun displayScore(track: Track): String = "" - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, didReadChapter: Boolean): Track { + if (track.status != COMPLETED) { + if (didReadChapter) { + track.status = READING + } + } + return api.updateProgress(track) } - override suspend fun bind(track: Track): Track { + override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { return track } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt index 5ab2e9fb8..e5a82885d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt @@ -56,6 +56,10 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { } } + override fun getReadingStatus(): Int = READING + + override fun getRereadingStatus(): Int = REREADING + override fun getCompletionStatus(): Int = COMPLETED override fun getScoreList(): List { @@ -67,22 +71,35 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { } private suspend fun add(track: Track): Track { - track.status = READING - track.score = 0F return api.updateItem(track) } - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, didReadChapter: Boolean): Track { + if (track.status != COMPLETED) { + if (track.status != REREADING && didReadChapter) { + track.status = READING + } + } + return api.updateItem(track) } - override suspend fun bind(track: Track): Track { + override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { val remoteTrack = api.findListItem(track) return if (remoteTrack != null) { track.copyPersonalFrom(remoteTrack) track.media_id = remoteTrack.media_id + + if (track.status != COMPLETED) { + val isRereading = track.status == REREADING + track.status = if (isRereading.not() && hasReadChapters) READING else track.status + } + update(track) } else { + // Set default fields if it's not found in the list + track.status = if (hasReadChapters) READING else PLAN_TO_READ + track.score = 0F add(track) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt index badec0b33..308bd3ded 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt @@ -44,19 +44,31 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { return api.addLibManga(track, getUsername()) } - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, didReadChapter: Boolean): Track { + if (track.status != COMPLETED) { + if (track.status != REPEATING && didReadChapter) { + track.status = READING + } + } + return api.updateLibManga(track, getUsername()) } - override suspend fun bind(track: Track): Track { + override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { val remoteTrack = api.findLibManga(track, getUsername()) return if (remoteTrack != null) { track.copyPersonalFrom(remoteTrack) track.library_id = remoteTrack.library_id + + if (track.status != COMPLETED) { + val isRereading = track.status == REPEATING + track.status = if (isRereading.not() && hasReadChapters) READING else track.status + } + update(track) } else { // Set default fields if it's not found in the list - track.status = READING + track.status = if (hasReadChapters) READING else PLANNING track.score = 0F add(track) } @@ -94,6 +106,10 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { } } + override fun getReadingStatus(): Int = READING + + override fun getRereadingStatus(): Int = REPEATING + override fun getCompletionStatus(): Int = COMPLETED override suspend fun login(username: String, password: String) = login(password) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index a56d7c4bc..5d1112eb9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -779,7 +779,8 @@ class MangaPresenter( item.manga_id = manga.id!! launchIO { try { - service.bind(item) + val hasReadChapters = allChapters.any { it.read } + service.bind(item, hasReadChapters) db.insertTrack(item).executeAsBlocking() if (service is UnattendedTrackService) { @@ -830,6 +831,9 @@ class MangaPresenter( fun setTrackerLastChapterRead(item: TrackItem, chapterNumber: Int) { val track = item.track!! + if (track.last_chapter_read == 0 && track.last_chapter_read < chapterNumber && track.status != item.service.getRereadingStatus()) { + track.status = item.service.getReadingStatus() + } track.last_chapter_read = chapterNumber if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { track.status = item.service.getCompletionStatus() 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 92251ba72..377bf542f 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 @@ -713,7 +713,7 @@ class ReaderPresenter( // for a while. The view can still be garbage collected. async { runCatching { - service.update(track) + service.update(track, true) db.insertTrack(track).executeAsBlocking() } }