Created
July 21, 2019 11:45
-
-
Save PatilShreyas/386bab2f2e3abac118dc0b3748d89f54 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 = 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