i am using firebase ui to populate data from the firebase firestore backend, and what i want to do is perform a filter or sort operation. so that means i want to update the query object that is passed to the recyclerviewqueryoptions object which is then passed to the adapter at runtime.
@Override
public void onFilter(Filters filters) {
mFireStore = FirebaseFirestore.getInstance();
Query query = mFireStore.collection("Products");
// Category (equality filter)
if (filters.hasCategory()) {
query = query.whereEqualTo(Product.FIELD_CATEGORY, filters.getCategory());
}
// City (equality filter)
if (filters.hasCity()) {
query = query.whereEqualTo(Product.FIELD_CITY, filters.getCity());
}
// Price (equality filter)
if (filters.hasPrice()) {
query = query.whereEqualTo(Product.FIELD_PRICE, filters.getPrice());
}
// Sort by (orderBy with direction)
if (filters.hasSortBy()) {
query = query.orderBy(filters.getSortBy(), filters.getSortDirection());
}
// Limit items
query = query.limit(10);
// db = FirebaseFirestore.getInstance();
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
FirestoreRecyclerOptions<Product> response = new FirestoreRecyclerOptions.Builder<Product>()
.setQuery(query,Product.class)
.build();
adapter = new FirestoreRecyclerAdapter<Product,ExploreViewholder>(response) {
@Override
public ExploreViewholder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.recycler_view_explore_item, parent, false);
return new ExploreViewholder(view);
}
@Override
protected void onBindViewHolder(@NonNull ExploreViewholder holder, int position, @NonNull Product model) {
holder.productName.setText(model.getProductName());
holder.creatorName.setText(mUser.getDisplayName());
holder.productDesc.setText(model.getProductDescription());
Glide.with(getContext())
.load(model.getProductImageUrl())
.into(holder.productImage);
}
};
adapter.notifyDataSetChanged();
mViewModel.setFilters(filters);
}
How can i update the data the recyclerview is going to display with the new query. or is this done automatically.. the query object above is going to get new data at runtime, theres no set query method i can call.