Minor cleanup of some tracker observables
This commit is contained in:
parent
430714e67f
commit
97a308b114
@ -147,19 +147,19 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun bind(track: Track): Observable<Track> {
|
override fun bind(track: Track): Observable<Track> {
|
||||||
return runAsObservable({ api.findLibManga(track, getUsername().toInt()) })
|
return runAsObservable({
|
||||||
.flatMap { remoteTrack ->
|
val remoteTrack = api.findLibManga(track, getUsername().toInt())
|
||||||
if (remoteTrack != null) {
|
if (remoteTrack != null) {
|
||||||
track.copyPersonalFrom(remoteTrack)
|
track.copyPersonalFrom(remoteTrack)
|
||||||
track.library_id = remoteTrack.library_id
|
track.library_id = remoteTrack.library_id
|
||||||
runAsObservable({ update(track) })
|
update(track)
|
||||||
} else {
|
} else {
|
||||||
// Set default fields if it's not found in the list
|
// Set default fields if it's not found in the list
|
||||||
track.score = DEFAULT_SCORE.toFloat()
|
track.score = DEFAULT_SCORE.toFloat()
|
||||||
track.status = DEFAULT_STATUS
|
track.status = DEFAULT_STATUS
|
||||||
runAsObservable({ add(track) })
|
add(track)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun search(query: String): Observable<List<TrackSearch>> {
|
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> {
|
override fun refresh(track: Track): Observable<Track> {
|
||||||
return runAsObservable({ api.getLibManga(track, getUsername().toInt()) })
|
return runAsObservable({
|
||||||
.map { remoteTrack ->
|
val remoteTrack = api.getLibManga(track, getUsername().toInt())
|
||||||
track.copyPersonalFrom(remoteTrack)
|
track.copyPersonalFrom(remoteTrack)
|
||||||
track.total_chapters = remoteTrack.total_chapters
|
track.total_chapters = remoteTrack.total_chapters
|
||||||
track
|
track
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun login(username: String, password: String) = login(password)
|
override suspend fun login(username: String, password: String) = login(password)
|
||||||
|
@ -65,18 +65,15 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun refresh(track: Track): Observable<Track> {
|
override fun refresh(track: Track): Observable<Track> {
|
||||||
return runAsObservable({ api.statusLibManga(track) })
|
return runAsObservable({
|
||||||
.flatMap {
|
val remoteStatusTrack = api.statusLibManga(track)
|
||||||
track.copyPersonalFrom(it!!)
|
track.copyPersonalFrom(remoteStatusTrack!!)
|
||||||
runAsObservable({ api.findLibManga(track) })
|
api.findLibManga(track)?.let { remoteTrack ->
|
||||||
.map { remoteTrack ->
|
|
||||||
if (remoteTrack != null) {
|
|
||||||
track.total_chapters = remoteTrack.total_chapters
|
track.total_chapters = remoteTrack.total_chapters
|
||||||
track.status = remoteTrack.status
|
track.status = remoteTrack.status
|
||||||
}
|
}
|
||||||
track
|
track
|
||||||
}
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getLogo() = R.drawable.ic_tracker_bangumi
|
override fun getLogo() = R.drawable.ic_tracker_bangumi
|
||||||
|
@ -79,18 +79,18 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun bind(track: Track): Observable<Track> {
|
override fun bind(track: Track): Observable<Track> {
|
||||||
return runAsObservable({ api.findLibManga(track, getUserId()) })
|
return runAsObservable({
|
||||||
.flatMap { remoteTrack ->
|
val remoteTrack = api.findLibManga(track, getUserId())
|
||||||
if (remoteTrack != null) {
|
if (remoteTrack != null) {
|
||||||
track.copyPersonalFrom(remoteTrack)
|
track.copyPersonalFrom(remoteTrack)
|
||||||
track.media_id = remoteTrack.media_id
|
track.media_id = remoteTrack.media_id
|
||||||
runAsObservable({ update(track) })
|
update(track)
|
||||||
} else {
|
} else {
|
||||||
track.score = DEFAULT_SCORE
|
track.score = DEFAULT_SCORE
|
||||||
track.status = DEFAULT_STATUS
|
track.status = DEFAULT_STATUS
|
||||||
runAsObservable({ add(track) })
|
add(track)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun search(query: String): Observable<List<TrackSearch>> {
|
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> {
|
override fun refresh(track: Track): Observable<Track> {
|
||||||
return runAsObservable({ api.getLibManga(track) })
|
return runAsObservable({
|
||||||
.map { remoteTrack ->
|
val remoteTrack = api.getLibManga(track)
|
||||||
track.copyPersonalFrom(remoteTrack)
|
track.copyPersonalFrom(remoteTrack)
|
||||||
track.total_chapters = remoteTrack.total_chapters
|
track.total_chapters = remoteTrack.total_chapters
|
||||||
track
|
track
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun login(username: String, password: String) {
|
override suspend fun login(username: String, password: String) {
|
||||||
|
@ -52,19 +52,19 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun bind(track: Track): Observable<Track> {
|
override fun bind(track: Track): Observable<Track> {
|
||||||
return runAsObservable({ api.findLibManga(track, getUsername()) })
|
return runAsObservable({
|
||||||
.flatMap { remoteTrack ->
|
val remoteTrack = api.findLibManga(track, getUsername())
|
||||||
if (remoteTrack != null) {
|
if (remoteTrack != null) {
|
||||||
track.copyPersonalFrom(remoteTrack)
|
track.copyPersonalFrom(remoteTrack)
|
||||||
track.library_id = remoteTrack.library_id
|
track.library_id = remoteTrack.library_id
|
||||||
runAsObservable({ update(track) })
|
update(track)
|
||||||
} else {
|
} else {
|
||||||
// Set default fields if it's not found in the list
|
// Set default fields if it's not found in the list
|
||||||
track.score = DEFAULT_SCORE.toFloat()
|
track.score = DEFAULT_SCORE.toFloat()
|
||||||
track.status = DEFAULT_STATUS
|
track.status = DEFAULT_STATUS
|
||||||
runAsObservable({ add(track) })
|
add(track)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun search(query: String): Observable<List<TrackSearch>> {
|
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> {
|
override fun refresh(track: Track): Observable<Track> {
|
||||||
return runAsObservable({ api.findLibManga(track, getUsername()) })
|
return runAsObservable({
|
||||||
.map { remoteTrack ->
|
api.findLibManga(track, getUsername())?.let { remoteTrack ->
|
||||||
if (remoteTrack != null) {
|
|
||||||
track.copyPersonalFrom(remoteTrack)
|
track.copyPersonalFrom(remoteTrack)
|
||||||
track.total_chapters = remoteTrack.total_chapters
|
track.total_chapters = remoteTrack.total_chapters
|
||||||
}
|
}
|
||||||
track
|
track
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getLogo() = R.drawable.ic_tracker_shikimori
|
override fun getLogo() = R.drawable.ic_tracker_shikimori
|
||||||
|
Loading…
Reference in New Issue
Block a user