Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. on<ListAction.Refresh> {
  2. flatMap {
  3. if (it.action.limit > ListAction.DEFAULT_LIMIT) {
  4. cache.get<List<GiphyItem>>(GiphyListViewModel.KEY_GIPHIES)?.let { giphies ->
  5. return@flatMap ListState.Screen(giphies, ListState.Mode.IDLE_REFRESH).just()
  6. }
  7. }
  8.  
  9. loadTrending(ListState.Mode.REFRESH, limit = it.action.limit) { _, list ->
  10. ListState.Screen(list, ListState.Mode.IDLE_REFRESH)
  11. }
  12. }
  13. }
  14.  
  15. on<ListAction.LoadMore> {
  16. flatMap {
  17. loadTrending(ListState.Mode.LOAD_MORE, it.action.offset) { state, list ->
  18. ListState.Screen(
  19. state.giphies.toMutableList().apply { addAll(list) },
  20. ListState.Mode.IDLE_LOAD_MORE
  21. ).also { screen ->
  22. cache.save(GiphyListViewModel.KEY_GIPHIES, screen.giphies)
  23. }
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement