Created
July 21, 2019 11:46
-
-
Save PatilShreyas/5b837c026ae483c98e825ef3b93c652d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Instantiate Paging Adapter | |
mAdapter = object : FirestorePagingAdapter<Post, PostViewHolder>(options) { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PostViewHolder { | |
val view = layoutInflater.inflate(R.layout.item_post, parent, false) | |
return PostViewHolder(view) | |
} | |
override fun onBindViewHolder(viewHolder: PostViewHolder, position: Int, post: Post) { | |
// Bind to ViewHolder | |
viewHolder.bind(post) | |
} | |
override fun onError(e: Exception) { | |
super.onError(e) | |
Log.e("MainActivity", e.message) | |
} | |
override fun onLoadingStateChanged(state: LoadingState) { | |
when (state) { | |
LoadingState.LOADING_INITIAL -> { | |
swipeRefreshLayout.isRefreshing = true | |
} | |
LoadingState.LOADING_MORE -> { | |
swipeRefreshLayout.isRefreshing = true | |
} | |
LoadingState.LOADED -> { | |
swipeRefreshLayout.isRefreshing = false | |
} | |
LoadingState.ERROR -> { | |
Toast.makeText( | |
applicationContext, | |
"Error Occurred!", | |
Toast.LENGTH_SHORT | |
).show() | |
swipeRefreshLayout.isRefreshing = false | |
} | |
LoadingState.FINISHED -> { | |
swipeRefreshLayout.isRefreshing = false | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment