Search in sources :

Example 1 with RatingAdapter

use of com.google.firebase.example.fireeats.java.adapter.RatingAdapter in project quickstart-android by firebase.

the class RestaurantDetailFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mBinding.restaurantButtonBack.setOnClickListener(this);
    mBinding.fabShowRatingDialog.setOnClickListener(this);
    String restaurantId = RestaurantDetailFragmentArgs.fromBundle(getArguments()).getKeyRestaurantId();
    // Initialize Firestore
    mFirestore = FirebaseFirestore.getInstance();
    // Get reference to the restaurant
    mRestaurantRef = mFirestore.collection("restaurants").document(restaurantId);
    // Get ratings
    Query ratingsQuery = mRestaurantRef.collection("ratings").orderBy("timestamp", Query.Direction.DESCENDING).limit(50);
    // RecyclerView
    mRatingAdapter = new RatingAdapter(ratingsQuery) {

        @Override
        protected void onDataChanged() {
            if (getItemCount() == 0) {
                mBinding.recyclerRatings.setVisibility(View.GONE);
                mBinding.viewEmptyRatings.setVisibility(View.VISIBLE);
            } else {
                mBinding.recyclerRatings.setVisibility(View.VISIBLE);
                mBinding.viewEmptyRatings.setVisibility(View.GONE);
            }
        }
    };
    mBinding.recyclerRatings.setLayoutManager(new LinearLayoutManager(requireContext()));
    mBinding.recyclerRatings.setAdapter(mRatingAdapter);
    mRatingDialog = new RatingDialogFragment();
}
Also used : Query(com.google.firebase.firestore.Query) RatingAdapter(com.google.firebase.example.fireeats.java.adapter.RatingAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RatingAdapter (com.google.firebase.example.fireeats.java.adapter.RatingAdapter)1 Query (com.google.firebase.firestore.Query)1