Skip to content

Instantly share code, notes, and snippets.

@gumil
Created February 18, 2019 10:30
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/9ead435a12987342d2e2010f9ea0c668 to your computer and use it in GitHub Desktop.
Save gumil/9ead435a12987342d2e2010f9ea0c668 to your computer and use it in GitHub Desktop.
fun ListState.render(): Unit? = when (this) {
is ListState.Screen -> {
when(loadingMode) {
ListState.Mode.REFRESH -> { swipeRefreshLayout.isRefreshing = true }
ListState.Mode.LOAD_MORE -> adapter.showFooter()
ListState.Mode.IDLE_LOAD_MORE -> {
adapter.addItems(giphies)
isLoading = false
restoreRecyclerView(giphies)
}
ListState.Mode.IDLE_REFRESH -> {
swipeRefreshLayout.isRefreshing = false
adapter.list = giphies
isLoading = false
restoreRecyclerView(giphies)
}
}
}
is ListState.Error -> {
swipeRefreshLayout.isRefreshing = false
showSnackbar(errorMessage)
}
is ListState.GoToDetail -> view
?.findNavController()
?.navigate(R.id.action_giphyListFragment_to_giphyDetailFragment,
GiphyDetailFragment.getBundle(giphy))
?.also {
pendingRestore = recyclerView.layoutManager?.onSaveInstanceState()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment