Minor cleanup of some tracker observables

This commit is contained in:
arkon 2020-12-31 10:51:23 -05:00
parent 430714e67f
commit 97a308b114
4 changed files with 61 additions and 65 deletions

View File

@ -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)

View File

@ -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

View File

@ -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) {

View File

@ -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