Skip to content

Instantly share code, notes, and snippets.

@griajobag
Created May 25, 2018 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save griajobag/ff244afbac837ef3d0cf024d1e22d286 to your computer and use it in GitHub Desktop.
Save griajobag/ff244afbac837ef3d0cf024d1e22d286 to your computer and use it in GitHub Desktop.
Rating
/**
* the method used to get all reviews in firebase firestore
* @param idProduct
*/
private void getAllReview(String idProduct) {
progressBar.setVisibility(View.VISIBLE);
rvReview.setVisibility(View.GONE);
CollectionReference collectionReference = firebaseFirestore.collection("product");
DocumentReference documentReference = collectionReference.document(idProduct);
documentReference.collection("review")
.get()
.addOnCompleteListener(task -> {
progressBar.setVisibility(View.GONE);
rvReview.setVisibility(View.VISIBLE);
if (task.getResult().isEmpty()) {
} else if (task.isSuccessful()) {
List<ReviewModel> listReview = new ArrayList<>();
for (DocumentSnapshot documentSnapshot : task.getResult()) {
ReviewModel reviewModel = new ReviewModel();
try {
reviewModel.setName(documentSnapshot.get("name").toString());
reviewModel.setReview(documentSnapshot.get("review").toString());
reviewModel.setTimeStamp(new Date(documentSnapshot.get("timeStamp").toString()));
reviewModel.setTotalStarGiven(Double.parseDouble(documentSnapshot.get("totalStarGiven").toString()));
} catch (Exception e) {
e.printStackTrace();
}
listReview.add(reviewModel);
initListReview(listReview);
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
//this method used to populating the recyclerview with data of reviews
private void initListReview(List<ReviewModel> reviewModels) {
adapter = new ReviewAdapter(reviewModels);
rvReview.setLayoutManager(new LinearLayoutManager(this));
rvReview.setAdapter(adapter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment