Created
February 18, 2019 10:30
-
-
Save gumil/9ead435a12987342d2e2010f9ea0c668 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 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