Guest User

Untitled

a guest
Jun 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. @Singleton
  2. class PostRepositoryImpl @Inject constructor(
  3. private val cache: PostCache,
  4. private val remote: PostRemote,
  5. private val mapper: PostMapper) : PostRepository {
  6.  
  7. override fun get(refresh: Boolean): Single<List<Post>> = when (refresh) {
  8. true -> remote.getPosts().flatMap { set(it) }.map { mapper.mapToDomain(it) }
  9. false -> cache.load().map { mapper.mapToDomain(it) }.onErrorResumeNext { get(true) }
  10. }
  11.  
  12. private fun set(list: List<PostEntity>) = cache.save(list)
  13. }
Add Comment
Please, Sign In to add comment