From 07e2bdac81f109887cd14c662249747dbbf8599a Mon Sep 17 00:00:00 2001 From: MCAxiaz Date: Mon, 9 Mar 2020 08:32:59 -0700 Subject: [PATCH] Fix bug where status cannot be updated when all chapters have been read. (#2683) Minor cleanup. --- .../tachiyomi/data/track/TrackService.kt | 2 + .../tachiyomi/data/track/anilist/Anilist.kt | 5 +-- .../tachiyomi/data/track/bangumi/Bangumi.kt | 5 +-- .../tachiyomi/data/track/kitsu/Kitsu.kt | 6 +-- .../data/track/myanimelist/MyAnimeList.kt | 12 +++-- .../data/track/shikimori/Shikimori.kt | 45 +++++++++---------- .../ui/manga/track/TrackPresenter.kt | 6 +++ 7 files changed, 41 insertions(+), 40 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 7f294fd00..3bc560f41 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 @@ -31,6 +31,8 @@ abstract class TrackService(val id: Int) { abstract fun getStatus(status: Int): String + abstract fun getCompletionStatus(): Int + abstract fun getScoreList(): List open fun indexToScore(index: Int): Float { 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 d30b32cad..dfa799e6d 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,8 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { } } + override fun getCompletionStatus(): Int = COMPLETED + override fun getScoreList(): List { return when (scorePreference.getOrDefault()) { // 10 point @@ -133,9 +135,6 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { } override fun update(track: Track): Observable { - if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { - track.status = COMPLETED - } // If user was using API v1 fetch library_id if (track.library_id == null || track.library_id!! == 0L) { return api.findLibManga(track, getUsername().toInt()).flatMap { 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 147dde6de..5775c983f 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 @@ -34,9 +34,6 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { } override fun update(track: Track): Observable { - if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { - track.status = COMPLETED - } return api.updateLibManga(track) } @@ -99,6 +96,8 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { } } + override fun getCompletionStatus(): Int = COMPLETED + override fun login(username: String, password: String) = login(password) fun login(code: String): Completable { 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 0fcaba4fd..593010e46 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 @@ -56,6 +56,8 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { } } + override fun getCompletionStatus(): Int = COMPLETED + override fun getScoreList(): List { val df = DecimalFormat("0.#") return listOf("0") + IntRange(2, 20).map { df.format(it / 2f) } @@ -75,10 +77,6 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { } override fun update(track: Track): Observable { - if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { - track.status = COMPLETED - } - return api.updateLibManga(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 0ae1fa70a..3003fc954 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 @@ -38,6 +38,10 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { override fun getLogoColor() = Color.rgb(46, 81, 162) + override fun getStatusList(): List { + return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ) + } + override fun getStatus(status: Int): String = with(context) { when (status) { READING -> getString(R.string.reading) @@ -49,9 +53,7 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { } } - override fun getStatusList(): List { - return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ) - } + override fun getCompletionStatus(): Int = COMPLETED override fun getScoreList(): List { return IntRange(0, 10).map(Int::toString) @@ -66,10 +68,6 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { } override fun update(track: Track): Observable { - if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { - track.status = COMPLETED - } - return api.updateLibManga(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 00f7a517f..ceecb75ed 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 @@ -13,6 +13,26 @@ import uy.kohesive.injekt.injectLazy class Shikimori(private val context: Context, id: Int) : TrackService(id) { + companion object { + const val READING = 1 + const val COMPLETED = 2 + const val ON_HOLD = 3 + const val DROPPED = 4 + const val PLANNING = 5 + const val REPEATING = 6 + + const val DEFAULT_STATUS = READING + const val DEFAULT_SCORE = 0 + } + + override val name = "Shikimori" + + private val gson: Gson by injectLazy() + + private val interceptor by lazy { ShikimoriInterceptor(this, gson) } + + private val api by lazy { ShikimoriApi(client, interceptor) } + override fun getScoreList(): List { return IntRange(0, 10).map(Int::toString) } @@ -26,9 +46,6 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { } override fun update(track: Track): Observable { - if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { - track.status = COMPLETED - } return api.updateLibManga(track, getUsername()) } @@ -63,26 +80,6 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { } } - companion object { - const val READING = 1 - const val COMPLETED = 2 - const val ON_HOLD = 3 - const val DROPPED = 4 - const val PLANNING = 5 - const val REPEATING = 6 - - const val DEFAULT_STATUS = READING - const val DEFAULT_SCORE = 0 - } - - override val name = "Shikimori" - - private val gson: Gson by injectLazy() - - private val interceptor by lazy { ShikimoriInterceptor(this, gson) } - - private val api by lazy { ShikimoriApi(client, interceptor) } - override fun getLogo() = R.drawable.tracker_shikimori override fun getLogoColor() = Color.rgb(40, 40, 40) @@ -103,6 +100,8 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { } } + override fun getCompletionStatus(): Int = COMPLETED + override fun login(username: String, password: String) = login(password) fun login(code: String): Completable { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackPresenter.kt index dee9b3894..7ebe96361 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackPresenter.kt @@ -115,6 +115,9 @@ class TrackPresenter( fun setStatus(item: TrackItem, index: Int) { val track = item.track!! track.status = item.service.getStatusList()[index] + if (track.status == item.service.getCompletionStatus() && track.total_chapters != 0) { + track.last_chapter_read = track.total_chapters + } updateRemote(track, item.service) } @@ -127,6 +130,9 @@ class TrackPresenter( fun setLastChapterRead(item: TrackItem, chapterNumber: Int) { val track = item.track!! track.last_chapter_read = chapterNumber + if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { + track.status = item.service.getCompletionStatus() + } updateRemote(track, item.service) } }