Created
February 18, 2019 10:27
-
-
Save gumil/7eec80acee5a20672dbed709781ef71e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun actions() = Observable.merge<ListAction>( | |
recyclerView.scrollEvents() | |
// filter when we do a scroll up | |
.filter { it.dy > 0 } | |
// filter when recyclerView is currently loading | |
.filter { !isLoading } | |
// filter threshold | |
.filter { | |
val layoutManager = it.view.layoutManager as StaggeredGridLayoutManager | |
val visibleItemCount = recyclerView.childCount | |
val totalItemCount = layoutManager.itemCount | |
val firstVisibleItem = layoutManager.findFirstVisibleItemPositions(null).first() | |
totalItemCount - visibleItemCount <= firstVisibleItem + GiphyListFragment.VISIBLE_THRESHOLD | |
} | |
.map { ListAction.LoadMore(adapter.list.size) } | |
.doOnNext { isLoading = true }, | |
swipeRefreshLayout.refreshes().map { ListAction.Refresh() }, | |
giphyViewItem.itemClick().map { ListAction.OnItemClick(it) } | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment