Hi, im trying out `loadStateFlow` to manage my and...
# android
t
Hi, im trying out
loadStateFlow
to manage my android activity load states and do not understand how to achieve the desired effect heres my code...
myAdapter.loadStateFlow
.distinctUntilChangedBy { it.refresh }
.filter { it.refresh is LoadState.NotLoading || it.refresh is LoadState.Error }
.collectLatest { loadState ->
if (loadState.source.refresh is LoadState.NotLoading)
if (loadState.append.endOfPaginationReached && folderItemAdapter.itemCount < 1) {
binding.viewFlipper.displayedChild = 2
} else {
binding.viewFlipper.displayedChild = 0
}
}
the load state works fine and I am happy I understand it (I think 😉 )
in the same
collect{}
block I am also trying to manage errors from my remoteMediator which is where the behaviour is "odd" as I force each expected error the
collect
block is passed all previous load and error load states which results in my app displaying multiple error messages to the user where I only want to display the latest error how can I refactor my consumption of the
loadStateFlow
so that I only see the last error load state? I would have thought
collectLatest
would do this for me, obviously not though from what my logcat output is showing me