-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentRecyclerViewAdapter.java
More file actions
103 lines (81 loc) · 3.43 KB
/
Copy pathCommentRecyclerViewAdapter.java
File metadata and controls
103 lines (81 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.hossain.zakaria.firebasephotoapp.adapters;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.hossain.zakaria.firebasephotoapp.R;
import com.hossain.zakaria.firebasephotoapp.models.Comment;
import com.hossain.zakaria.firebasephotoapp.models.User;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class CommentRecyclerViewAdapter extends RecyclerView.Adapter<CommentRecyclerViewAdapter.CommentViewHolder> {
private List<User> commentUserList;
private List<Comment> commentList;
private Context context;
public CommentRecyclerViewAdapter(List<Comment> commentList, List<User> commentUserList, Context context) {
this.commentUserList = commentUserList;
this.commentList = commentList;
this.context = context;
}
@NonNull
@Override
public CommentViewHolder onCreateViewHolder(@NonNull ViewGroup container, int position) {
View view = LayoutInflater.from(context).inflate(R.layout.item_comment, container, false);
return new CommentViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull CommentViewHolder holder, int position) {
holder.setIsRecyclable(false);
/*Collections.reverse(commentList);
Collections.reverse(commentUserList);*/
String commentUserId = commentList.get(position).getCommentUserId();
String commentText = commentList.get(position).getCommentText();
String commentTimeStamp = commentList.get(position).getCommentTimeStamp();
if (commentUserId != null) {
String commenterName = commentUserList.get(position).getUserName();
String commenterImage = commentUserList.get(position).getUserImageUrl();
holder.setCommentUserNameAndImage(commenterName, commenterImage);
holder.setCommentTextAndTime(commentText, commentTimeStamp);
}
}
@Override
public int getItemCount() {
if (commentList != null) {
return commentList.size();
} else {
return 0;
}
}
class CommentViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.comment_field)
TextView commentField;
@BindView(R.id.comment_date_time)
TextView commentDateTime;
@BindView(R.id.comment_user_name)
TextView commentUserName;
@BindView(R.id.comment_user_image)
ImageView commentUserImage;
CommentViewHolder(@NonNull View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
void setCommentTextAndTime(String commentText, String commentTimeStamp) {
commentField.setText(commentText);
commentDateTime.setText(commentTimeStamp);
}
void setCommentUserNameAndImage(String commenterName, String commenterImage) {
commentUserName.setText(commenterName);
Glide.with(context)
.applyDefaultRequestOptions(new RequestOptions().placeholder(R.drawable.user_image_placeholder))
.load(commenterImage)
.into(commentUserImage);
}
}
}