5

I'm making 2 parallel API calls to request for paging data. I need to combine the result of both API calls upon getting the result and submit the paging data to adapter.

viewLifecycleOwner.lifecycleScope.launchWhenStarted {
            val assignedList = async {
                assignedTaskViewModel.getPagingTasks(getAssignedTasks)
            }

            val unscheduledTasksList = async {
                assignedTaskViewModel.getUnscheduledChores(getUnscheduledTasks)
            }

            unscheduledTasksList.await().combine(assignedList.await()) { unschedule, assign ->
                Timber.d("combining 2 calls")
                //TODO need to show unscheduledTasksList first followed by assignedList
            }.collectLatest {
                it.map { value ->
                    Timber.d("paging data = $value")
                }
                assignedTasksPagingAdapter?.submitData(it)
            }
        }

is there a way to transform the pagingData so that i can combine the result from 2 API calls and submit to the adapter as single paging data?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • I would suggest you to insert the data from both the api's into local DB and then use paging3 for the retrieval of data from the DB. – Nataraj KR Oct 14 '22 at 05:03

0 Answers0