-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChatAdapter.java
71 lines (64 loc) · 3.13 KB
/
ChatAdapter.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
package com.scanor.chat.adapter;
import android.view.ViewGroup;
/**
* Created by Administrator on 2016/10/17.
*/
public class ChatAdapter extends BaseRecyclerBindingAdapter<MessageTable> {
//两个type,一个是是否自己发的,第二个是消息类型,余数是是否自己发,商是消息类型
@Override
public int getItemViewType(int position) {
MessageTable msg = getDataList().get(position);
Type type = Type.fromString(msg.getType());
int selfSend = msg.isSendByMyself() ? 1 : 0;//是否自己发的标志位
return type.getValue() * 10 + selfSend;
}
@Override
public BindingHolder onCreateViewHolder(ViewGroup parent, int viewType) {
int selfSend = viewType % 10;
int typeValue = viewType / 10;
Type type = Type.fromValue(typeValue);
boolean isSelfSend = selfSend == 1;
switch (type) {
case text:
return BindingHolder.newInstance(isSelfSend ? R.layout.newchat_send_msg_text : R.layout.newchat_receive_msg_text, parent);
case image:
return BindingHolder.newInstance(isSelfSend ? R.layout.newchat_send_msg_image : R.layout.newchat_receive_msg_image, parent);
case voice:
return BindingHolder.newInstance(isSelfSend ? R.layout.newchat_send_msg_audio : R.layout.newchat_receive_msg_audio, parent);
case video:
return BindingHolder.newInstance(isSelfSend ? R.layout.newchat_send_msg_video : R.layout.newchat_receive_msg_video, parent);
case DTCard:
return BindingHolder.newInstance(isSelfSend ? R.layout.newchat_send_msg_card : R.layout.newchat_receive_msg_card, parent);
case search:
return BindingHolder.newInstance(R.layout.newchat_receive_msg_search, parent);
case address:
return BindingHolder.newInstance(isSelfSend ? R.layout.newchat_send_msg_address : R.layout.newchat_receive_msg_address, parent);
case notification:
return BindingHolder.newInstance(R.layout.newchat_sendandrecv_msg_notification, parent);
case redpacket:
return BindingHolder.newInstance(isSelfSend ? R.layout.newchat_send_msg_red_packet : R.layout.newchat_receive_msg_red_packet, parent);
default:
return BindingHolder.newInstance(isSelfSend ? R.layout.newchat_send_msg_text : R.layout.newchat_receive_msg_text, parent);
}
}
@Override
public void onBindViewHolder(BindingHolder holder, int position) {
final MessageTable message = getDataList().get(position);
final Type type = Type.fromString(message.getType());
if (message.isSendByMyself()) {
switch (type) {
case A:
XXXBinding1 binding = holder.getBinding();
...
break;
case A:
XXXBinding2 binding = holder.getBinding();
...
break;
...
}
} else {
handleContactMsg(holder, message, type, position);
}
}
}