@@ -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,17 +36,20 @@ 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(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+ }
4045
4146 vShadows = mapOf (
4247 ShadowPosition .RightBorder to R .id.shadow_right_border,
4348 ShadowPosition .NumBottom to R .id.shadow_num_bottom,
4449 ShadowPosition .ContentBottom to R .id.shadow_content_bottom
45- ).mapValues { findViewById(it.value) }
50+ ).mapValues {
51+ findViewById<View >(it.value)
52+ }
4653 }
4754
4855 private fun checkStartAnimation (attrs : AttributeSet ) {
@@ -52,8 +59,9 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
5259 animate()
5360 .setDuration(Const .DefaultDelay * 5 )
5461 .alpha(Const .Alpha .Initial )
55- } else
62+ } else {
5663 alpha = Const .Alpha .Initial
64+ }
5765 }
5866
5967 private fun AbstractCodeAdapter <* >.checkHighlightAnimation (action : () -> Unit ) {
@@ -65,7 +73,9 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
6573 animate().alpha(Const .Alpha .Visible )
6674 action()
6775 }
68- } else action()
76+ } else {
77+ action()
78+ }
6979 }
7080
7181 /* *
@@ -75,7 +85,7 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
7585 private fun highlight () {
7686 getAdapter()?.apply {
7787 highlight {
78- checkHighlightAnimation(this ::notifyDataSetChanged)
88+ checkHighlightAnimation(::notifyDataSetChanged)
7989 }
8090 }
8191 }
@@ -222,9 +232,9 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
222232 RightBorder -> GradientDrawable .Orientation .LEFT_RIGHT to theme.bgContent
223233 NumBottom -> GradientDrawable .Orientation .TOP_BOTTOM to theme.bgNum
224234 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())
228238 }
229239 }
230240}
0 commit comments