From 97a308b1141e827bde8daff19343f5d94dabacb8 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 31 Dec 2020 10:51:23 -0500 Subject: [PATCH] Minor cleanup of some tracker observables --- .../tachiyomi/data/track/anilist/Anilist.kt | 36 +++++++++--------- .../tachiyomi/data/track/bangumi/Bangumi.kt | 19 ++++------ .../tachiyomi/data/track/kitsu/Kitsu.kt | 34 ++++++++--------- .../data/track/shikimori/Shikimori.kt | 37 +++++++++---------- 4 files changed, 61 insertions(+), 65 deletions(-) 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 cb30457f4..997d3c3c3 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 @@ -147,19 +147,19 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { } override fun bind(track: Track): Observable { - return runAsObservable({ api.findLibManga(track, getUsername().toInt()) }) - .flatMap { remoteTrack -> - if (remoteTrack != null) { - track.copyPersonalFrom(remoteTrack) - track.library_id = remoteTrack.library_id - runAsObservable({ update(track) }) - } else { - // Set default fields if it's not found in the list - track.score = DEFAULT_SCORE.toFloat() - track.status = DEFAULT_STATUS - runAsObservable({ add(track) }) - } + return runAsObservable({ + val remoteTrack = api.findLibManga(track, getUsername().toInt()) + if (remoteTrack != null) { + track.copyPersonalFrom(remoteTrack) + track.library_id = remoteTrack.library_id + update(track) + } else { + // Set default fields if it's not found in the list + track.score = DEFAULT_SCORE.toFloat() + track.status = DEFAULT_STATUS + add(track) } + }) } override fun search(query: String): Observable> { @@ -167,12 +167,12 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { } override fun refresh(track: Track): Observable { - return runAsObservable({ api.getLibManga(track, getUsername().toInt()) }) - .map { remoteTrack -> - track.copyPersonalFrom(remoteTrack) - track.total_chapters = remoteTrack.total_chapters - track - } + return runAsObservable({ + val remoteTrack = api.getLibManga(track, getUsername().toInt()) + track.copyPersonalFrom(remoteTrack) + track.total_chapters = remoteTrack.total_chapters + track + }) } override suspend fun login(username: String, password: String) = login(password) 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 9d135722e..e212704e7 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 @@ -65,18 +65,15 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { } override fun refresh(track: Track): Observable { - return runAsObservable({ api.statusLibManga(track) }) - .flatMap { - track.copyPersonalFrom(it!!) - runAsObservable({ api.findLibManga(track) }) - .map { remoteTrack -> - if (remoteTrack != null) { - track.total_chapters = remoteTrack.total_chapters - track.status = remoteTrack.status - } - track - } + return runAsObservable({ + val remoteStatusTrack = api.statusLibManga(track) + track.copyPersonalFrom(remoteStatusTrack!!) + api.findLibManga(track)?.let { remoteTrack -> + track.total_chapters = remoteTrack.total_chapters + track.status = remoteTrack.status } + track + }) } override fun getLogo() = R.drawable.ic_tracker_bangumi 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 b24ade682..07a67be9d 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 @@ -79,18 +79,18 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { } override fun bind(track: Track): Observable { - return runAsObservable({ api.findLibManga(track, getUserId()) }) - .flatMap { remoteTrack -> - if (remoteTrack != null) { - track.copyPersonalFrom(remoteTrack) - track.media_id = remoteTrack.media_id - runAsObservable({ update(track) }) - } else { - track.score = DEFAULT_SCORE - track.status = DEFAULT_STATUS - runAsObservable({ add(track) }) - } + return runAsObservable({ + val remoteTrack = api.findLibManga(track, getUserId()) + if (remoteTrack != null) { + track.copyPersonalFrom(remoteTrack) + track.media_id = remoteTrack.media_id + update(track) + } else { + track.score = DEFAULT_SCORE + track.status = DEFAULT_STATUS + add(track) } + }) } override fun search(query: String): Observable> { @@ -98,12 +98,12 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { } override fun refresh(track: Track): Observable { - return runAsObservable({ api.getLibManga(track) }) - .map { remoteTrack -> - track.copyPersonalFrom(remoteTrack) - track.total_chapters = remoteTrack.total_chapters - track - } + return runAsObservable({ + val remoteTrack = api.getLibManga(track) + track.copyPersonalFrom(remoteTrack) + track.total_chapters = remoteTrack.total_chapters + track + }) } override suspend fun login(username: String, password: String) { 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 bcec699d2..d1880b517 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 @@ -52,19 +52,19 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { } override fun bind(track: Track): Observable { - return runAsObservable({ api.findLibManga(track, getUsername()) }) - .flatMap { remoteTrack -> - if (remoteTrack != null) { - track.copyPersonalFrom(remoteTrack) - track.library_id = remoteTrack.library_id - runAsObservable({ update(track) }) - } else { - // Set default fields if it's not found in the list - track.score = DEFAULT_SCORE.toFloat() - track.status = DEFAULT_STATUS - runAsObservable({ add(track) }) - } + return runAsObservable({ + val remoteTrack = api.findLibManga(track, getUsername()) + if (remoteTrack != null) { + track.copyPersonalFrom(remoteTrack) + track.library_id = remoteTrack.library_id + update(track) + } else { + // Set default fields if it's not found in the list + track.score = DEFAULT_SCORE.toFloat() + track.status = DEFAULT_STATUS + add(track) } + }) } override fun search(query: String): Observable> { @@ -72,14 +72,13 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { } override fun refresh(track: Track): Observable { - return runAsObservable({ api.findLibManga(track, getUsername()) }) - .map { remoteTrack -> - if (remoteTrack != null) { - track.copyPersonalFrom(remoteTrack) - track.total_chapters = remoteTrack.total_chapters - } - track + return runAsObservable({ + api.findLibManga(track, getUsername())?.let { remoteTrack -> + track.copyPersonalFrom(remoteTrack) + track.total_chapters = remoteTrack.total_chapters } + track + }) } override fun getLogo() = R.drawable.ic_tracker_shikimori