Skip to content

Instantly share code, notes, and snippets.

@gumil
Created February 18, 2019 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gumil/7eec80acee5a20672dbed709781ef71e to your computer and use it in GitHub Desktop.
Save gumil/7eec80acee5a20672dbed709781ef71e to your computer and use it in GitHub Desktop.
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