SubscriptionAdapter.java
5.21 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.cnlive.goldenline.ui.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.LinearLayout;
import android.widget.TextView;
import com.cnlive.goldenline.R;
import com.cnlive.goldenline.model.AnchorItem;
import com.cnlive.goldenline.ui.adapter.viewholder.EmptyViewHolder;
import com.cnlive.goldenline.ui.base.BaseRecyclerAdapter;
import org.greenrobot.eventbus.EventBus;
/**
* Description:我的订阅页面 适配器
* Created on 2017/3/14
* Author : 郭
*/
public class SubscriptionAdapter extends BaseRecyclerAdapter<AnchorItem> {
private View headView;
public SubscriptionAdapter(Context context) {
super(context);
}
@Override
public int getItemViewType(int position) {
if (position == 0 && headView != null) {
return 0;
} else {
return 1;
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
case 0:
return new EmptyViewHolder(headView);
case 1:
return new SubscriptionViewHolder(LayoutInflater.from(mContext).inflate(R.layout.layout_find_item, null));
}
return null;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof SubscriptionViewHolder) {
AnchorItem anchorItem = mItems.get(position);
((SubscriptionAdapter.SubscriptionViewHolder) holder).tv_find_time.setText(anchorItem.getMaster());
((SubscriptionAdapter.SubscriptionViewHolder) holder).tv_commentnum.setText(position + "");
((SubscriptionAdapter.SubscriptionViewHolder) holder).tv_seenum.setText(position + 100 + "");
((SubscriptionAdapter.SubscriptionViewHolder) holder).tv_find_title.setText(anchorItem.getAddress());
//点击打赏按钮
((SubscriptionViewHolder) holder).ima_reward.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post("ima_reward");
}
});
//监听点击头像
((SubscriptionViewHolder) holder).ima_find_head.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post("ima_find_head");
}
});
//监听item
((SubscriptionViewHolder) holder).ll_sub_item.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post("ll_sub_item");
}
});
//监听分享
((SubscriptionViewHolder) holder).ima_share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post("ima_share");
}
});
if (position==3)
{
// Glide.with(mContext).load("http://shtml.asia-cloud.com/ZZSY/video_test2.png").into(((SubscriptionAdapter.SubscriptionViewHolder) holder).ima_find_show);
}
else if (position ==2)
{
// Glide.with(mContext).load("http://shtml.asia-cloud.com/ZZSY/video_test1.png").into(((SubscriptionAdapter.SubscriptionViewHolder) holder).ima_find_show);
}else{
// Glide.with(mContext).load("http://shtml.asia-cloud.com/ZZSY/video_test3.png").into(((SubscriptionAdapter.SubscriptionViewHolder) holder).ima_find_show);
}
}
}
public void setHeadView(View headView) {
this.headView = headView;
}
class SubscriptionViewHolder extends RecyclerView.ViewHolder {
private ImageView ima_find_show, ima_find_head, ima_share, ima_reward;
private TextView tv_find_title, tv_find_time, tv_seenum, tv_commentnum;
private LinearLayout ll_sub_item;
public SubscriptionViewHolder(View itemView) {
super(itemView);
//头像
ima_find_head = (ImageView) itemView.findViewById(R.id.ima_find_head);
//背景大图
ima_find_show = (ImageView) itemView.findViewById(R.id.ima_find_show);
//分享按钮
ima_share = (ImageView) itemView.findViewById(R.id.ima_share);
//打赏
ima_reward = (ImageView) itemView.findViewById(R.id.ima_reward);
//标题
tv_find_title = (TextView) itemView.findViewById(R.id.tv_find_title);
//时间
tv_find_time = (TextView) itemView.findViewById(R.id.tv_find_time);
//观看人数
tv_seenum = (TextView) itemView.findViewById(R.id.tv_seenum);
//评论数
tv_commentnum = (TextView) itemView.findViewById(R.id.tv_commentnum);
//item
ll_sub_item = (LinearLayout) itemView.findViewById(R.id.ll_sub_item);
}
}
}