CommentAdapter.java
3.09 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
104
105
106
107
108
109
110
111
112
package com.cnlive.im.adapter;
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.ImageView;
import android.widget.TextView;
import com.cnlive.im.R;
import com.cnlive.libs.util.model.CommentItem;
import java.util.ArrayList;
import java.util.List;
/**
* @author 陈硕
* @time 2017/6/9 10:56
* @desc ${TODD}
*/
public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.CommentHolder> {
protected List<CommentItem> mItems = new ArrayList<CommentItem>();
protected OnImageViewClick onImageViewClick;
Context context;
private final LayoutInflater mLayoutInflater;
private CommentHolder commentHolder;
public CommentAdapter(Context context) {
this.context = context;
mLayoutInflater = LayoutInflater.from(context);
}
public void addItems(List<CommentItem> items) {
mItems.addAll(items);
notifyDataSetChanged();
}
public void refreshItems(List<CommentItem> items) {
mItems.clear();
mItems.addAll(items);
notifyDataSetChanged();
}
public void clearItems() {
mItems.clear();
}
@Override
public CommentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mLayoutInflater.inflate(R.layout.commet_item, parent, false);
commentHolder = new CommentHolder(view);
return commentHolder;
}
@Override
public void onBindViewHolder(CommentHolder holder, int position) {
final CommentItem commentItem = mItems.get(position);
commentHolder.nick_name.setText(commentItem.getUid());
commentHolder.comment_message.setText(commentItem.getContent());
commentHolder.comment_good_count.setText(commentItem.getPraise());
commentHolder.good_imv1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onImageViewClick != null) {
onImageViewClick.praiseComment(commentItem);
}
}
});
}
@Override
public int getItemCount() {
return mItems.size();
}
public void setOnImageViewClick(OnImageViewClick onImageViewClick) {
this.onImageViewClick = onImageViewClick;
}
public interface OnImageViewClick {
void praiseComment(CommentItem commentItem);
}
class CommentHolder extends RecyclerView.ViewHolder {
public final TextView nick_name;
public final TextView comment_message;
public final TextView comment_good_count;
public final ImageView good_imv1;
public CommentHolder(View itemView) {
super(itemView);
nick_name = (TextView) itemView.findViewById(R.id.nick_name);
good_imv1 = (ImageView) itemView.findViewById(R.id.good_imv);
comment_message = (TextView) itemView.findViewById(R.id.comment_message);
comment_good_count = (TextView) itemView.findViewById(R.id.comment_good_count);
}
}
}