-
Notifications
You must be signed in to change notification settings - Fork 0
/
DisplayCommentsAdapter.java
94 lines (67 loc) · 2.75 KB
/
DisplayCommentsAdapter.java
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
package theo.tziomakas.news.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import theo.tziomakas.news.R;
import theo.tziomakas.news.model.Comment;
public class DisplayCommentsAdapter extends RecyclerView.Adapter<DisplayCommentsAdapter.CommentsViewHolder>{
private static final String LOG_TAG = NewsAdapter.class.getName();
private ValueEventListener context;
private ArrayList<Comment> commentArrayList;
public DisplayCommentsAdapter(ValueEventListener context, ArrayList<Comment> commentArrayList){
this.context = context;
this.commentArrayList = commentArrayList;
}
@Override
public DisplayCommentsAdapter.CommentsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
int layoutIdForListItem = R.layout.single_comment_row;
LayoutInflater inflater = LayoutInflater.from(context);
boolean shouldAttactToParentImmediately = false;
View view = inflater.inflate(layoutIdForListItem,parent,shouldAttactToParentImmediately);
CommentsViewHolder commentsViewHolder = new CommentsViewHolder(view);
return commentsViewHolder;
}
@Override
public void onBindViewHolder(DisplayCommentsAdapter.CommentsViewHolder holder, int position) {
Comment comment = commentArrayList.get(position);
holder.mTitle.setText(comment.commentTitle);
holder.mBody.setText(comment.commentBody);
holder.mAuthor.setText(comment.commentAuthor);
holder.mDate.setText(comment.date);
}
@Override
public int getItemCount() {
if(commentArrayList == null){
return 0;
}else{
return commentArrayList.size();
}
}
public void setCommentsData(ArrayList<Comment> newsList){
this.commentArrayList = commentArrayList;
notifyDataSetChanged();
}
public void clear() {
commentArrayList.clear();
notifyDataSetChanged();
}
public class CommentsViewHolder extends RecyclerView.ViewHolder {
TextView mTitle;
TextView mBody;
TextView mAuthor;
TextView mDate;
public CommentsViewHolder(View itemView) {
super(itemView);
mTitle = itemView.findViewById(R.id.display_comment_title);
mBody = itemView.findViewById(R.id.display_comment_body);
mAuthor = itemView.findViewById(R.id.display_comment_author);
mDate = itemView.findViewById(R.id.display_comment_date);
}
}
}