Tower Guidev2
12/15/2021, 9:42 AMloadStateFlow
to manage my android activity load states and do not understand how to achieve the desired effect
heres my code...Tower Guidev2
12/15/2021, 9:44 AMmyAdapter.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
}
}
Tower Guidev2
12/15/2021, 9:45 AMTower Guidev2
12/15/2021, 9:53 AMcollect{}
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