The issue is the recycler view is not displaying the data after the onchanged method is called. Or if it does, it takes a long time to display the information. heres the code:
public void onFilter(Filters filters) {
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(LIMIT);
Log.d("Query Info", query.toString());
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);
}
@Override
public void onError(FirebaseFirestoreException e) {
Log.e("error", e.getMessage());
}
};
adapter.notifyDataSetChanged();
mRecycler.setAdapter(adapter);
}
This is where the method gets called, i get data from the viewmodel, no problem with that but the recycler view dosent display the data.
mViewModel.getMutableLiveData().observe(this, new Observer<Filters>() {
@Override
public void onChanged(@Nullable Filters filters) {
if (filters != null){
Log.d("ExploreFragObserver", filters.getCategory() + " ");
Log.d("ExploreFragObserver", filters.getCity() + "");
Log.d("ExploreFragObserver", filters.getSortBy() + " ");
Log.d("ExploreFragObserver", filters.getPrice() + " ");
onFilter(filters);
Log.d("Done Loading Adapt", filters.getSortBy() + " ");
Log.d("ExploreFragObserver", filters.getCategory() + " ");
Log.d("ExploreFragObserver", filters.getCity() + "");
Log.d("ExploreFragObserver", filters.getSortBy() + " ");
Log.d("ExploreFragObserver", filters.getPrice() + " ");
// onFilter(Filters.getDefault());
}
}
});
A dialog fragment sets the data for the filters object in the viewmodel that both this fragment and the calling fragment both share.