Эх сурвалжийг харах

Minor cleanup of some tracker observables

arkon 4 жил өмнө
parent
commit
97a308b114

+ 18 - 18
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<Track> {
-        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<List<TrackSearch>> {
@@ -167,12 +167,12 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) {
     }
 
     override fun refresh(track: Track): Observable<Track> {
-        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)

+ 8 - 11
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<Track> {
-        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

+ 17 - 17
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<Track> {
-        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<List<TrackSearch>> {
@@ -98,12 +98,12 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) {
     }
 
     override fun refresh(track: Track): Observable<Track> {
-        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) {

+ 18 - 19
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<Track> {
-        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<List<TrackSearch>> {
@@ -72,14 +72,13 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) {
     }
 
     override fun refresh(track: Track): Observable<Track> {
-        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