I am new to RXJava. I want to perform three different database operations by using observable and I want to get the corresponding result. For this scenario, I have tried Flowable.combineLatest like below. I am having searchview where I search the tickets using name,ticketnumber etc. Based on the search query, I am getting the data from database and displaying it. For example, If I search name contains "ba" then it returns baskar and balaji. The second time if I search "sa" then it returns sanjay,sanjeev and sanjit. Now I can see all these three tickets information in my recyclerview and I am just updating any one of the ticket. After I update any one of the ticket, it is misbehaving. Now the prepareDataToRender - attendees are containg both (baskar, balaji) and (sanjay,sanjeev and sanjit). But I want to show only (sanjay,sanjeev and sanjit) with the updated information.

Flowables
    .combineLatest(
        ticketHoldersRepository.getSearhTickets(eventId, searchQuery.value.toString()),
        verifiedCredentialsRepository.listVerifiedCredentials(eventId),
        blacklistRepository.getBlacklistedItems(eventId),
        combineFunction = { attendees, verifiedIdentities, blacklistedCredentials ->
          prepareDataToRender(attendees, verifiedIdentities, blacklistedCredentials)
        }
    )
    .subscribeOn(rxSchedulers.io)
    .observeOn(rxSchedulers.mainThread)
    .subscribeBy(
        onNext = { dataToRender ->
          if (dataToRender.attendeesList.isNotEmpty()) {
            attendeesList.addAll(dataToRender.attendeesList)
            if (!searchQuery.value.isNullOrEmpty()) {
              view?.showAttendees(
                  attendeesList,
                  dataToRender.blacklistedAttendeesList,
                  serverTimeProvider.timeZone,
                  verifierId)
            } else {
              view?.hideAttendees()
            }
          }
        },
        onError = { error ->
          logger.e(error.message.toString())
          view?.showToastMessage(app.getString(R.string.ticket_not_available))
        }
    )
    .addTo(disposables)  

private fun prepareDataToRender(
  attendees: List<TicketHolderEntity>,
  verifiedIdentities: Map<String, VerifiedCredentialEntity>,
  blacklistedCredentials: List<BlacklistedCredentialEntity>
): DataToRender {
     val attendeesList = attendees
    .map { createAttendeeItem(it, verifiedIdentities[it.number]) }
     val blacklistedAttendeesList = blacklistedCredentials
    .map { blacklistTransformer.entityToData(it) }
    return DataToRender(attendeesList, blacklistedAttendeesList)
}

private data class DataToRender(
    val attendeesList: List<AttendeeItem>,
    val blacklistedAttendeesList: List<BlacklistedAttendee>
)

Can someone help me to solve this issue? I think my approach might be wrong. So if someone give me a correct idea that would be appreciated. Thanks in advance.

0

There are 0 answers