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 2018516574..7b75bd70c0 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 @@ -54,7 +54,7 @@ abstract class TrackService(val id: Int) { abstract suspend fun add(track: Track): Track - abstract suspend fun update(track: Track): Track + abstract suspend fun update(track: Track, setToReadStatus: Boolean = false): Track abstract suspend fun bind(track: Track): Track @@ -84,7 +84,7 @@ abstract class TrackService(val id: Int) { } } -suspend fun TrackService.updateNewTrackInfo(track: Track) { +suspend fun TrackService.updateNewTrackInfo(track: Track, planningStatus: Int) { val allRead = db.getManga(track.manga_id).executeOnIO()?.status == SManga.COMPLETED && db.getChapters(track.manga_id).executeOnIO().all { it.read } if (supportsReadingDates) { @@ -92,6 +92,9 @@ suspend fun TrackService.updateNewTrackInfo(track: Track) { track.finished_reading_date = getCompletedDate(track, allRead) } track.last_chapter_read = getLastChapterRead(track) + if (track.last_chapter_read == 0) { + track.status = planningStatus + } if (allRead) { track.status = completedStatus() } @@ -99,7 +102,7 @@ suspend fun TrackService.updateNewTrackInfo(track: Track) { suspend fun TrackService.getStartDate(track: Track): Long { if (db.getChapters(track.manga_id).executeOnIO().any { it.read }) { - val chapters = db.getHistoryByMangaId(track.manga_id).executeOnIO() + val chapters = db.getHistoryByMangaId(track.manga_id).executeOnIO().filter { it.last_read > 0 } val date = chapters.minOfOrNull { it.last_read } ?: return 0L return if (date <= 0L) 0L else date } 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 af421b97e3..d7a0299fdb 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 @@ -130,11 +130,14 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { override suspend fun add(track: Track): Track { track.score = DEFAULT_SCORE.toFloat() track.status = DEFAULT_STATUS - updateNewTrackInfo(track) + updateNewTrackInfo(track, PLANNING) return api.addLibManga(track) } - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, setToReadStatus: Boolean): Track { + if (setToReadStatus && track.status == PLANNING && track.last_chapter_read != 0) { + track.status = READING + } if (track.status == READING && track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { track.status = COMPLETED } 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 fb5dbb764e..88f9b47641 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 @@ -32,7 +32,10 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { return track.score.toInt().toString() } - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, setToReadStatus: Boolean): Track { + if (setToReadStatus && track.status == PLANNING && track.last_chapter_read != 0) { + track.status = READING + } if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { track.status = COMPLETED } @@ -42,7 +45,7 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { override suspend fun add(track: Track): Track { track.score = DEFAULT_SCORE.toFloat() track.status = DEFAULT_STATUS - updateNewTrackInfo(track) + updateNewTrackInfo(track, PLANNING) api.addLibManga(track) return update(track) } 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 e7972eb220..0bf1b9e111 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 @@ -87,7 +87,10 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { return df.format(track.score) } - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, setToReadStatus: Boolean): Track { + if (setToReadStatus && track.status == PLAN_TO_READ && track.last_chapter_read != 0) { + track.status = READING + } if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { track.status = COMPLETED } 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 e0050bb2d8..3adb251cc1 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 @@ -70,11 +70,14 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { override suspend fun add(track: Track): Track { track.status = READING track.score = 0F - updateNewTrackInfo(track) + updateNewTrackInfo(track, PLAN_TO_READ) return api.updateItem(track) } - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, setToReadStatus: Boolean): Track { + if (setToReadStatus && track.status == PLAN_TO_READ && track.last_chapter_read != 0) { + track.status = READING + } return api.updateItem(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 8154ed429f..bf5545a2ae 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 @@ -67,7 +67,10 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { return track.score.toInt().toString() } - override suspend fun update(track: Track): Track { + override suspend fun update(track: Track, setToReadStatus: Boolean): Track { + if (setToReadStatus && track.status == PLANNING && track.last_chapter_read != 0) { + track.status = READING + } if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { track.status = COMPLETED } @@ -77,7 +80,7 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { override suspend fun add(track: Track): Track { track.score = DEFAULT_SCORE.toFloat() track.status = DEFAULT_STATUS - updateNewTrackInfo(track) + updateNewTrackInfo(track, PLANNING) return api.addLibManga(track, getUsername()) } override suspend fun bind(track: Track): Track { 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 1ce479e30d..9ac83414d0 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 @@ -860,7 +860,7 @@ class ReaderPresenter( if (service != null && service.isLogged && chapterRead > track.last_chapter_read) { try { track.last_chapter_read = chapterRead - service.update(track) + service.update(track, true) db.insertTrack(track).executeAsBlocking() } catch (e: Exception) { Timber.e(e)