'Is there any way to remove item from PagedList and notify RecyclerView?

Is there any way to remove item from PagedList and notify RecyclerView without invalidating DataSource (not Room)?

What I have tried:

Store all model in own list, remove model from it when needed, call dataSource.invalidate() and submit stored list in loadInitial -> onResult callback. But seems like this is not very elegant silution...



Solution 1:[1]

After couple hours of trying my approach is call the network for removing and after collecting PagingData again. This action will go through till mapper.

 viewModel.remove(item) {
        lifecycleScope.launch{
            viewModel.uiState.collectLatest { uiState ->
               adapter.submitData(viewLifecycleOwner.lifecycle, uiState.list)
            }
        }

And in the mapper check the field for me it was isUserFavorited. filter is a PagingDataTransforms extension and it was life saver other than visibility changing or layout height 0 shenanigans

return dataSource
        .myItemList(
            id = id,
            search = queryDecider.convertString(search),
        ).map {
            it.map { response ->
                mapper.map(response)
            }.filter { uiModel ->
                uiModel.isUserFavorited
            }
        }.flowOn(dispatcher.io)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dgncn