Created
July 30, 2019 12:07
-
-
Save reactivedroid/0f22f2e0392aed60640c6151ebff1450 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
class FavoriteShowsRepository @Inject | |
constructor(private val showDao: ShowDao) { | |
suspend fun allFavoriteShows(): List<FavoriteShow> { | |
return showDao.allFavouriteShows() | |
} | |
fun insertShowIntoFavorites(show: Show) { | |
val favoriteShow = FavoriteShow( | |
id = show.id, | |
name = show.name, | |
premiered = show.premiered, | |
imageUrl = show.image!!["original"], | |
summary = show.summary, | |
rating = show.rating!!["average"], | |
runtime = show.runtime!!, | |
isFavorite = true | |
) | |
CoroutineScope(Dispatchers.IO).launch { showDao.insert(favoriteShow) } | |
} | |
fun removeShowFromFavorites(show: Show) { | |
val favoriteShow = FavoriteShow( | |
id = show.id, | |
name = show.name, | |
premiered = show.premiered, | |
imageUrl = show.image!!["original"], | |
summary = show.summary, | |
rating = show.rating!!["average"], | |
runtime = show.runtime!!, | |
isFavorite = false | |
) | |
CoroutineScope(Dispatchers.IO).launch { showDao.remove(favoriteShow) } | |
} | |
fun insertIntoFavorites(favoriteShow: FavoriteShow) { | |
CoroutineScope(Dispatchers.IO).launch { showDao.insert(favoriteShow) } | |
} | |
fun removeFromFavorites(favoriteShow: FavoriteShow) { | |
CoroutineScope(Dispatchers.IO).launch { showDao.remove(favoriteShow) } | |
} | |
suspend fun allFavoriteShowIds(): List<Long> { | |
return showDao.getFavoriteShowIds() | |
} | |
fun clearAll() { | |
CoroutineScope(Dispatchers.IO).launch { showDao.clear() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment