UGCGiftAdapter.java
3.56 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.cnlive.gundam.video.adpter;
import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.cnlive.gundam.R;
import com.cnlive.gundam.video.activity.PlayerActivity;
import com.cnlive.gundam.video.fragment.chat.ChatRoomFragment;
import com.cnlive.gundam.video.fragment.chat.UGCChatRoomFragment;
import com.cnlive.gundam.video.model.CNMessageModle;
import com.cnlive.gundam.video.model.GiftModle;
import com.cnlive.gundam.video.model.MessageInfo;
import com.cnlive.libs.util.chat.ChatUtil;
import com.cnlive.libs.util.chat.base.IChat;
import com.cnlive.libs.util.chat.model.CNMessage;
import com.google.gson.Gson;
import java.util.List;
/**
* @author 陈硕
* @time 2017/5/27 16:04
* @desc ${TODD}
*/
public class UGCGiftAdapter extends RecyclerView.Adapter<UGCGiftAdapter.RVHolder> {
private Context mContext;
private List<GiftModle> mDataList;
private int mLayoutId; // 条目布局文件ID
private int mVariableId; // DataBinding变量ID
private String roomId;
private final Gson gson2;
public UGCGiftAdapter(String roomId, Context context, List<GiftModle> list, int layoutId, int variableId) {
this.mContext = context;
this.mDataList = list;
this.mLayoutId = layoutId;
mVariableId = variableId;
this.roomId=roomId;
gson2 = new Gson();
}
@Override
public RVHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), mLayoutId, parent, false);
RVHolder holder = new RVHolder(binding.getRoot());
holder.binding = binding;
return holder;
}
@Override
public void onBindViewHolder(final RVHolder holder, final int position) {
holder.binding.setVariable(mVariableId, mDataList.get(position));
holder.binding.getRoot().findViewById(R.id.ll_item).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CNMessageModle cnMessageModle = new CNMessageModle("giftType",new MessageInfo("0",mDataList.get(position).getGiftMessage(),"1","0",mDataList.get(position).getGiftMessage()));
String obj2=gson2.toJson(cnMessageModle);
ChatUtil.sendMessage(IChat.CHATROOM, roomId, obj2, new IChat.OnSendMessageListener() {
@Override
public void onAttached(CNMessage message) {
}
@Override
public void onSuccess(CNMessage message) {
PlayerActivity context = (PlayerActivity) UGCGiftAdapter.this.mContext;
UGCChatRoomFragment chatRoomFragment = (UGCChatRoomFragment) context.getSupportFragmentManager().findFragmentByTag("UGCChatRoomFragment");
chatRoomFragment.giftItem(position);
}
@Override
public void onError(CNMessage message, int what, String extra) {
}
});
}
});
holder.binding.executePendingBindings();
}
@Override
public int getItemCount() {
return mDataList == null ? 0 : mDataList.size();
}
class RVHolder extends RecyclerView.ViewHolder {
ViewDataBinding binding;
RVHolder(View view) {
super(view);
}
}
}