use of com.google.firebase.example.fireeats.java.adapter.RestaurantAdapter in project quickstart-android by firebase.
the class MainFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mBinding.filterBar.setOnClickListener(this);
mBinding.buttonClearFilter.setOnClickListener(this);
// View model
mViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
// Enable Firestore logging
FirebaseFirestore.setLoggingEnabled(true);
// Firestore
mFirestore = FirebaseFirestore.getInstance();
// Get ${LIMIT} restaurants
mQuery = mFirestore.collection("restaurants").orderBy("avgRating", Query.Direction.DESCENDING).limit(LIMIT);
// RecyclerView
mAdapter = new RestaurantAdapter(mQuery, this) {
@Override
protected void onDataChanged() {
// Show/hide content if the query returns empty.
if (getItemCount() == 0) {
mBinding.recyclerRestaurants.setVisibility(View.GONE);
mBinding.viewEmpty.setVisibility(View.VISIBLE);
} else {
mBinding.recyclerRestaurants.setVisibility(View.VISIBLE);
mBinding.viewEmpty.setVisibility(View.GONE);
}
}
@Override
protected void onError(FirebaseFirestoreException e) {
// Show a snackbar on errors
Snackbar.make(mBinding.getRoot(), "Error: check logs for info.", Snackbar.LENGTH_LONG).show();
}
};
mBinding.recyclerRestaurants.setLayoutManager(new LinearLayoutManager(requireContext()));
mBinding.recyclerRestaurants.setAdapter(mAdapter);
// Filter Dialog
mFilterDialog = new FilterDialogFragment();
}
Aggregations