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
public class Post { | |
public String authorName; | |
public String message; | |
public Post() { | |
} | |
public Post(String authorName, String message) { | |
this.authorName = authorName; | |
this.message = message; |
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
// Init Paging Configuration | |
PagedList.Config config = new PagedList.Config.Builder() | |
.setEnablePlaceholders(false) | |
.setPrefetchDistance(2) | |
.setPageSize(10) | |
.build(); |
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
// Init Adapter Configuration | |
FirestorePagingOptions options = new FirestorePagingOptions.Builder<Post>() | |
.setLifecycleOwner(this) | |
.setQuery(mQuery, config, Post.class) | |
.build(); |
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 |
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) |
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
@Override | |
protected void onError(@NonNull Exception e) { | |
super.onError(e); | |
Log.e("MainActivity", e.getMessage()); | |
// Handle the error. | |
} |
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
// Refresh Action on Swipe Refresh Layout | |
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { | |
@Override | |
public void onRefresh() { | |
mAdapter.refresh(); | |
} | |
}); |
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
@Override | |
protected void onStart() { | |
super.onStart(); | |
mAdapter.startListening(); | |
} |
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
@Override | |
protected void onStop() { | |
super.onStop(); | |
mAdapter.stopListening(); | |
} |
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
public class PostViewHolder extends RecyclerView.ViewHolder { | |
private TextView authorView; | |
private TextView messageView; | |
public PostViewHolder(@NonNull View itemView) { | |
super(itemView); | |
authorView = itemView.findViewById(R.id.post_AuthorName); | |
messageView = itemView.findViewById(R.id.post_Message); | |
} |