@@ -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,11 +36,12 @@ 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<RecyclerView >(R .id.rv_code_content)
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,
@@ -227,9 +232,9 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
227
232
RightBorder -> GradientDrawable .Orientation .LEFT_RIGHT to theme.bgContent
228
233
NumBottom -> GradientDrawable .Orientation .TOP_BOTTOM to theme.bgNum
229
234
ContentBottom -> GradientDrawable .Orientation .TOP_BOTTOM to theme.bgContent
230
- }.let {
231
- val colors = arrayOf(android.R .color.transparent, it.second )
232
- 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())
233
238
}
234
239
}
235
240
}
0 commit comments