@@ -22,7 +22,11 @@ import io.github.kbiakov.codeview.highlight.color
22
22
*
23
23
* @author Kirill Biakov
24
24
*/
25
- class CodeView (context : Context , attrs : AttributeSet ) : RelativeLayout(context, attrs) {
25
+ class CodeView @JvmOverloads constructor(
26
+ context : Context ,
27
+ attrs : AttributeSet ? = null ,
28
+ defStyleAttr : Int = 0
29
+ ) : RelativeLayout(context, attrs, defStyleAttr) {
26
30
27
31
private val vCodeList: RecyclerView
28
32
private val vShadows: Map <ShadowPosition , View >
@@ -32,17 +36,20 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
32
36
*/
33
37
init {
34
38
inflate(context, R .layout.layout_code_view, this )
35
- checkStartAnimation( attrs)
39
+ attrs?. let (::checkStartAnimation )
36
40
37
- vCodeList = findViewById(R .id.rv_code_content) as RecyclerView
38
- vCodeList.layoutManager = LinearLayoutManager (context)
39
- vCodeList.isNestedScrollingEnabled = true
41
+ vCodeList = findViewById<RecyclerView >(R .id.rv_code_content).apply {
42
+ layoutManager = LinearLayoutManager (context)
43
+ isNestedScrollingEnabled = true
44
+ }
40
45
41
46
vShadows = mapOf (
42
47
ShadowPosition .RightBorder to R .id.shadow_right_border,
43
48
ShadowPosition .NumBottom to R .id.shadow_num_bottom,
44
49
ShadowPosition .ContentBottom to R .id.shadow_content_bottom
45
- ).mapValues { findViewById(it.value) }
50
+ ).mapValues {
51
+ findViewById<View >(it.value)
52
+ }
46
53
}
47
54
48
55
private fun checkStartAnimation (attrs : AttributeSet ) {
@@ -52,8 +59,9 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
52
59
animate()
53
60
.setDuration(Const .DefaultDelay * 5 )
54
61
.alpha(Const .Alpha .Initial )
55
- } else
62
+ } else {
56
63
alpha = Const .Alpha .Initial
64
+ }
57
65
}
58
66
59
67
private fun AbstractCodeAdapter <* >.checkHighlightAnimation (action : () -> Unit ) {
@@ -65,7 +73,9 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
65
73
animate().alpha(Const .Alpha .Visible )
66
74
action()
67
75
}
68
- } else action()
76
+ } else {
77
+ action()
78
+ }
69
79
}
70
80
71
81
/* *
@@ -75,7 +85,7 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
75
85
private fun highlight () {
76
86
getAdapter()?.apply {
77
87
highlight {
78
- checkHighlightAnimation(this ::notifyDataSetChanged)
88
+ checkHighlightAnimation(::notifyDataSetChanged)
79
89
}
80
90
}
81
91
}
@@ -222,9 +232,9 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
222
232
RightBorder -> GradientDrawable .Orientation .LEFT_RIGHT to theme.bgContent
223
233
NumBottom -> GradientDrawable .Orientation .TOP_BOTTOM to theme.bgNum
224
234
ContentBottom -> GradientDrawable .Orientation .TOP_BOTTOM to theme.bgContent
225
- }.let {
226
- val colors = arrayOf(android.R .color.transparent, it.second )
227
- GradientDrawable (it.first , colors.map(Int ::color).toIntArray())
235
+ }.let { (orientation, color) ->
236
+ val colors = arrayOf(android.R .color.transparent, color )
237
+ GradientDrawable (orientation , colors.map(Int ::color).toIntArray())
228
238
}
229
239
}
230
240
}
0 commit comments