Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created July 21, 2019 11:45
Show Gist options
  • Save PatilShreyas/386bab2f2e3abac118dc0b3748d89f54 to your computer and use it in GitHub Desktop.
Save PatilShreyas/386bab2f2e3abac118dc0b3748d89f54 to your computer and use it in GitHub Desktop.
// Instantiate Paging Adapter
mAdapter = new FirestorePagingAdapter<Post, PostViewHolder>(options) {
@NonNull
@Override
public PostViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = getLayoutInflater().inflate(R.layout.item_post, parent, false);
return new PostViewHolder(view);
}
@Override
protected void onBindViewHolder(@NonNull PostViewHolder viewHolder, int i, @NonNull Post post) {
// Bind to ViewHolder
viewHolder.bind(post);
}
@Override
protected void onError(@NonNull Exception e) {
super.onError(e);
Log.e("MainActivity", e.getMessage());
}
@Override
protected void onLoadingStateChanged(@NonNull LoadingState state) {
switch (state) {
case LOADING_INITIAL:
case LOADING_MORE:
mSwipeRefreshLayout.setRefreshing(true);
break;
case LOADED:
mSwipeRefreshLayout.setRefreshing(false);
break;
case ERROR:
Toast.makeText(
getApplicationContext(),
"Error Occurred!",
Toast.LENGTH_SHORT
).show();
mSwipeRefreshLayout.setRefreshing(false);
break;
case FINISHED:
mSwipeRefreshLayout.setRefreshing(false);
break;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment