-
Notifications
You must be signed in to change notification settings - Fork 0
/
RvItemDecorationBuilder.java
112 lines (91 loc) · 4.51 KB
/
RvItemDecorationBuilder.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
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
package ysn.com.recyclerview;
import android.support.annotation.ColorInt;
/**
* @Author yangsanning
* @ClassName RvItemDecorationBuilder
* @Description 通过 RvItemDecorationBuilder, 自由定义属于你的分割线 (默认四角留白, 如有需要自行通过padding填充)
* @Date 2019/4/28
* @History 2019/4/28 author: description:
*/
public class RvItemDecorationBuilder {
private Decoration leftDecoration;
private Decoration topDecoration;
private Decoration rightDecoration;
private Decoration bottomDecoration;
public RvItemDecorationBuilder buildLeft(@ColorInt int color, float width) {
this.leftDecoration = new Decoration(color, width);
return this;
}
public RvItemDecorationBuilder buildLeft(boolean isShow, @ColorInt int color, float width) {
this.leftDecoration = new Decoration(isShow, color, width);
return this;
}
public RvItemDecorationBuilder buildLeft(@ColorInt int color, float width, float paddingStart, float paddingEnd) {
this.leftDecoration = new Decoration(color, width, paddingStart, paddingEnd);
return this;
}
public RvItemDecorationBuilder buildLeft(boolean isShow, @ColorInt int color, float width, float paddingStart, float paddingEnd) {
this.leftDecoration = new Decoration(isShow, color, width, paddingStart, paddingEnd);
return this;
}
public RvItemDecorationBuilder buildTop(@ColorInt int color, float width) {
this.topDecoration = new Decoration(color, width);
return this;
}
public RvItemDecorationBuilder buildTop(boolean isShow, @ColorInt int color, float width) {
this.topDecoration = new Decoration(isShow, color, width);
return this;
}
public RvItemDecorationBuilder buildTop(@ColorInt int color, float width, float paddingStart, float paddingEnd) {
this.topDecoration = new Decoration(color, width, paddingStart, paddingEnd);
return this;
}
public RvItemDecorationBuilder buildTop(boolean isShow, @ColorInt int color, float width, float paddingStart, float paddingEnd) {
this.topDecoration = new Decoration(isShow, color, width, paddingStart, paddingEnd);
return this;
}
public RvItemDecorationBuilder buildRight(@ColorInt int color, float width) {
this.rightDecoration = new Decoration(color, width);
return this;
}
public RvItemDecorationBuilder buildRight(boolean isShow, @ColorInt int color, float width) {
this.rightDecoration = new Decoration(isShow, color, width);
return this;
}
public RvItemDecorationBuilder buildRight(@ColorInt int color, float width, float paddingStart, float paddingEnd) {
this.rightDecoration = new Decoration(color, width, paddingStart, paddingEnd);
return this;
}
public RvItemDecorationBuilder buildRight(boolean isShow, @ColorInt int color, float width, float paddingStart, float paddingEnd) {
this.rightDecoration = new Decoration(isShow, color, width, paddingStart, paddingEnd);
return this;
}
public RvItemDecorationBuilder buildBottom(@ColorInt int color, float width) {
this.bottomDecoration = new Decoration(color, width);
return this;
}
public RvItemDecorationBuilder buildBottom(boolean isShow, @ColorInt int color, float width) {
this.bottomDecoration = new Decoration(isShow, color, width);
return this;
}
public RvItemDecorationBuilder buildBottom(@ColorInt int color, float width, float paddingStart, float paddingEnd) {
this.bottomDecoration = new Decoration(color, width, paddingStart, paddingEnd);
return this;
}
public RvItemDecorationBuilder buildBottom(boolean isShow, @ColorInt int color, float width, float paddingStart, float paddingEnd) {
this.bottomDecoration = new Decoration(isShow, color, width, paddingStart, paddingEnd);
return this;
}
/**
* 最后必须调用
*/
public RvItemDecoration finish() {
// 提供一个默认不显示的 Decoration, 防止空指针
Decoration decoration = new Decoration();
leftDecoration = (leftDecoration != null ? leftDecoration : decoration);
topDecoration = (topDecoration != null ? topDecoration : decoration);
rightDecoration = (rightDecoration != null ? rightDecoration : decoration);
bottomDecoration = (bottomDecoration != null ? bottomDecoration : decoration);
return new RvItemDecoration(leftDecoration, topDecoration, rightDecoration, bottomDecoration);
}
}