This is a snippet of the code, I am creating the adapter in the call to my livedata observe method.
mViewModel.getMutableLiveData().observe(this, new Observer<Filters>() {
@Override
public void onChanged(@Nullable Filters filters) {
if(filters != null){
FirebaseFirestore mFireStored = FirebaseFirestore.getInstance();
Log.d("FiltersINfoVM",filters.getPrice() +" ");
Log.d("FiltersINfoVM",filters.getSortBy() +" ");
Log.d("FiltersINfoVW",filters.getCategory() +" ");
Log.d("FiltersINfoVW",filters.getSearchDescription(getContext()) +" ");
Log.d("FiltersINfoVW",filters.getCity() +" ");
// Construct query basic query
CollectionReference collectionReference = mFireStored.collection("Products");
//Query query = collectionReference.orderBy("Products");
// Category (equality filter)
// if (filters.hasCategory()) {
// query2 = collectionReference.whereEqualTo(Product.FIELD_CATEGORY,"docs" );//filters.getCategory()
// }
// City (equality filter)
// if (filters.hasCity()) {
// query2 = collectionReference.whereEqualTo(Product.FIELD_CITY,"owerri" );//filters.getCity()
// }
//
// // Price (equality filter)
// if (filters.hasPrice()) {
// query2 = collectionReference.whereEqualTo(Product.FIELD_PRICE, filters.getPrice());
// }
// Sort by (orderBy with direction)
// if (filters.hasSortBy()) {
// //query = collectionReference.orderBy(filters.getSortBy(), filters.getSortDirection())
// Log.d("Sort Values method",filters.getSortBy());
// query2 = collectionReference.orderBy(filters.getSortBy(),filters.getSortDirection());
// }
query2 = collectionReference.orderBy("productName", Query.Direction.ASCENDING);
// Limit items
//query = collectionReference.limit(LIMIT);
// query = collectionReference.orderBy("numRatings", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Product> response2 = new FirestoreRecyclerOptions.Builder<Product>()
.setQuery(query2,Product.class)
.build();
FirestoreRecyclerAdapter<Product,ExploreViewholder>
adapterResp = new FirestoreRecyclerAdapter<Product,ExploreViewholder>(response2) {
@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());
}
};
adapterResp.notifyDataSetChanged();
// mRecycler.setAdapter(adapterResp);
mRecycler.swapAdapter(adapterResp,true);
}
}
});
I am getting data in the filters object in the onchanged method, and everything works as expected except when it is time for the overridden methods of the Firestore recycler adapter to get called,(they dont, i set breakpoints and tried debugging, execution just skips those methods), as a result the RecyclerView do not display any data. "Product" is a model class and ExploreViewHolder is the viewholder for the RecyclerView. The problem is the first time I query the database I receive data and is displayed in the recycler view..but I then want to query the data again at runtime, I am doing this using a dialog fragment, I create a new query with a new adapter and I swap the old adapter for this one..the problem is It does not display anything in the recyclerview after this new query...