I am writing an app that show restaurants and user reviews.
I want to display the reviews , I have the username
, comment
, date
and user_photo
.
First question is should I save in review document the username or userId ?
Second question is how to display user`s photo? I can not store it in the document as URL.
Because if the user change the photo it will not change in review document. Note that user`s photo is stored in Firestore Storage.
What it is the best practice to solve this issue?
AdapterReview.java
public class AdapterReview extends FirestoreRecyclerAdapter<ReviewModel, HolderReviews>{
public AdapterReview(@NonNull FirestoreRecyclerOptions<ReviewModel> options) {
super(options);
}
@Override
protected void onBindViewHolder(@NonNull HolderReviews holder, int i, @NonNull ReviewModel reviewObject) {
holder.usernameTextView.setText(reviewObject.getUsername());
holder.dateTextView.setText(reviewObject.getDate());
holder.commentTextView.setText(reviewObject.getComment());
holder.photoImageView.setImageURI(???);
}
@NonNull
@Override
public HolderReviews onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_adapter, parent, false);
return new HolderReviews(view);
}
}
This method that create firestore recyclerview in MainActivity.java
private void fireStoreRecyclerViews( ) {
Query query = db.collection("reviews");
FirestoreRecyclerOptions<ReviewModel> options = new FirestoreRecyclerOptions.Builder<ReviewModel>()
.setQuery(query, ReviewModel.class)
.build();
adapterReview = new AdapterReview(options);
RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this);
recyclerView.setAdapter(adapterReview);
}