Removed Rx java
This commit is contained in:
parent
ccad96dd41
commit
62726de918
12 changed files with 189 additions and 386 deletions
|
@ -25,9 +25,6 @@ import code.name.monkey.retromusic.model.*
|
|||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||
import code.name.monkey.retromusic.rest.LastFMRestClient
|
||||
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import java.io.IOException
|
||||
|
||||
class RepositoryImpl(private val context: Context) : Repository {
|
||||
|
@ -45,6 +42,19 @@ class RepositoryImpl(private val context: Context) : Repository {
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun albumById(albumId: Int): Result<Album> {
|
||||
return try {
|
||||
val album = AlbumLoader.getAlbum(context, albumId)
|
||||
if (album != null) {
|
||||
Success(album)
|
||||
} else {
|
||||
Error(Throwable("No album"))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun allArtists(): Result<ArrayList<Artist>> {
|
||||
return try {
|
||||
val artists = ArtistLoader.getAllArtists(context)
|
||||
|
@ -246,43 +256,6 @@ class RepositoryImpl(private val context: Context) : Repository {
|
|||
Error(Throwable("Error loading artist"))
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAlbumFlowable(albumId: Int): Observable<Album> {
|
||||
return AlbumLoader.getAlbumFlowable(context, albumId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
override fun getArtistByIdFlowable(artistId: Int): Observable<Artist> {
|
||||
return ArtistLoader.getArtistFlowable(context, artistId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
override fun getPlaylistSongsFlowable(playlist: Playlist): Observable<ArrayList<Song>> {
|
||||
return PlaylistSongsLoader.getPlaylistSongListFlowable(context, playlist)
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
override val favoritePlaylistFlowable: Observable<ArrayList<Playlist>>
|
||||
get() = PlaylistLoader.getFavoritePlaylistFlowable(context)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
||||
|
||||
override fun getSong(id: Int): Song {
|
||||
return SongLoader.getSong(context, id)
|
||||
}
|
||||
|
||||
override fun getAlbum(albumId: Int): Album {
|
||||
return AlbumLoader.getAlbum(context, albumId)
|
||||
}
|
||||
|
||||
override fun getArtistById(artistId: Long): Artist {
|
||||
return ArtistLoader.getArtist(context, artistId.toInt())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
suspend fun <T : Any> safeApiCall(call: suspend () -> Result<T>, errorMessage: String): Result<T> = try {
|
||||
|
|
|
@ -17,7 +17,6 @@ package code.name.monkey.retromusic.providers.interfaces
|
|||
import code.name.monkey.retromusic.Result
|
||||
import code.name.monkey.retromusic.model.*
|
||||
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
||||
import io.reactivex.Observable
|
||||
|
||||
/**
|
||||
* Created by hemanths on 11/08/17.
|
||||
|
@ -27,6 +26,8 @@ interface Repository {
|
|||
|
||||
suspend fun allAlbums(): Result<ArrayList<Album>>
|
||||
|
||||
suspend fun albumById(albumId: Int): Result<Album>
|
||||
|
||||
suspend fun allSongs(): Result<ArrayList<Song>>
|
||||
|
||||
suspend fun allArtists(): Result<ArrayList<Artist>>
|
||||
|
@ -54,19 +55,4 @@ interface Repository {
|
|||
suspend fun artistInfo(name: String, lang: String?, cache: String?): Result<LastFmArtist>
|
||||
|
||||
suspend fun artistById(artistId: Int): Result<Artist>
|
||||
|
||||
fun getSong(id: Int): Song
|
||||
|
||||
fun getAlbumFlowable(albumId: Int): Observable<Album>
|
||||
|
||||
fun getAlbum(albumId: Int): Album
|
||||
|
||||
fun getArtistByIdFlowable(artistId: Int): Observable<Artist>
|
||||
|
||||
fun getArtistById(artistId: Long): Artist
|
||||
|
||||
fun getPlaylistSongsFlowable(playlist: Playlist): Observable<ArrayList<Song>>
|
||||
|
||||
val favoritePlaylistFlowable: Observable<ArrayList<Playlist>>
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue