@@ -22,7 +22,11 @@ import io.github.kbiakov.codeview.highlight.color
2222 *
2323 * @author Kirill Biakov
2424 */
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) {
2630
2731 private val vCodeList: RecyclerView
2832 private val vShadows: Map <ShadowPosition , View >
@@ -32,11 +36,12 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
3236 */
3337 init {
3438 inflate(context, R .layout.layout_code_view, this )
35- checkStartAnimation( attrs)
39+ attrs?. let (::checkStartAnimation )
3640
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+ }
4045
4146 vShadows = mapOf (
4247 ShadowPosition .RightBorder to R .id.shadow_right_border,
@@ -227,9 +232,9 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
227232 RightBorder -> GradientDrawable .Orientation .LEFT_RIGHT to theme.bgContent
228233 NumBottom -> GradientDrawable .Orientation .TOP_BOTTOM to theme.bgNum
229234 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())
233238 }
234239 }
235240}
0 commit comments