in app/src/main/java/com/google/firebase/example/fireeats/RestaurantDetailActivity.java [209:233]
public void onRating(Rating rating) {
// In a transaction, add the new rating and update the aggregate totals
addRating(mRestaurantRef, rating)
.addOnSuccessListener(this, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "Rating added");
// Hide keyboard and scroll to top
hideKeyboard();
mRatingsRecycler.smoothScrollToPosition(0);
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Add rating failed", e);
// Show failure message and hide keyboard
hideKeyboard();
Snackbar.make(findViewById(android.R.id.content), "Failed to add rating",
Snackbar.LENGTH_SHORT).show();
}
});
}