Created
May 25, 2018 01:51
-
-
Save griajobag/ff244afbac837ef3d0cf024d1e22d286 to your computer and use it in GitHub Desktop.
Rating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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