Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.18 KB | None | 0 0
  1. override fun onFirstViewAttach() {
  2.         super.onFirstViewAttach()
  3.         Flowable
  4.             .combineLatest<List<AccreditationItem>, List<Event>, Pair<List<AccreditationItem>, List<Event>>>(
  5.                 repository.getAccreditations(),
  6.                 eventRepo.observeEvents(),
  7.                 BiFunction { accreditations, events ->
  8.                     Pair(accreditations, events)
  9.                 }
  10.             )
  11.             .map { pair ->
  12.                 val accreditations = pair.first
  13.                 val events = pair.second
  14.                 events.mapNotNull { event ->
  15.                     val eventAccreditation = accreditations.firstOrNull { it.eventId == event.eventId }
  16.                     event.name?.let { eventAccreditation?.barcode?.let { it1 -> EventAccreditation(it, it1) } }
  17.                 }
  18.             }
  19.             .observeOn(schedulers.ui())
  20.             .subscribeOn(schedulers.io())
  21.             .subscribe({
  22.                 if (!it.isNullOrEmpty())
  23.                     viewState.loadData(it)
  24.                 else
  25.                     throw Throwable()
  26.             }, {
  27.                 viewState.onError()
  28.             })
  29.             .untilDestroy()
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement