CourseXrecAdapter.java
3.8 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
package com.hh.xuetubao.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
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.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.hh.xuetubao.R;
import com.hh.xuetubao.bean.FreeCourseBean;
import java.util.List;
public class CourseXrecAdapter extends RecyclerView.Adapter<CourseXrecAdapter.ViewHolder> {
private List<FreeCourseBean.bean> mlist;
private Context mcontext;
public CourseXrecAdapter(List<FreeCourseBean.bean> mlist, Context mcontext) {
this.mlist = mlist;
this.mcontext = mcontext;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mcontext).inflate(R.layout.xrv_home, parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
if (mlist.get(position) != null) {
if (mlist.get(position).getLessonName() != null)
holder.title.setText(mlist.get(position).getLessonName());
if (mlist.get(position).getDifficult() != null)
holder.nanyi.setText(mlist.get(position).getDifficult());
if (mlist.get(position).getLearningPeopleCount() != null)
holder.count.setText(mlist.get(position).getLearningPeopleCount());
if (mlist.get(position).getLessonCoverPic() != null) {
}
RoundedCorners roundedCorners = new RoundedCorners(10);//数字为圆角度数
RequestOptions coverRequestOptions = new RequestOptions()
.transforms(new CenterCrop(), roundedCorners)
.diskCacheStrategy(DiskCacheStrategy.NONE)//不做磁盘缓存
.skipMemoryCache(true);//不做内存缓存
Glide.with(mcontext).load(mlist.get(position).getLessonCoverPic()).apply(coverRequestOptions).into(holder.img);
if (position == mlist.size() - 1) {
holder.line.setVisibility(View.GONE);
} else {
holder.line.setVisibility(View.VISIBLE);
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (turn != null) {
turn.turnTo(mlist.get(position).getLessonOid());
}
}
});
}
}
@Override
public int getItemCount() {
return mlist.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private final TextView title;
private final TextView nanyi;
private final TextView count;
private final ImageView img;
private final View line;
public ViewHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.title);
nanyi = (TextView) itemView.findViewById(R.id.tv_nanyi);
count = (TextView) itemView.findViewById(R.id.tv_count);
img = (ImageView) itemView.findViewById(R.id.img);
line = itemView.findViewById(R.id.line);
}
}
private Turn turn;
public void setTurn(Turn turn) {
this.turn = turn;
}
public interface Turn {
void turnTo(String lessonOid);
}
}