@@ -20,18 +20,29 @@ import io.github.kbiakov.codeview.adapters.Options
2020 */
2121class CodeView (context : Context , attrs : AttributeSet ) : RelativeLayout(context, attrs) {
2222
23- private val vShadowRight: View
24- private val vShadowBottomLine: View
25- private val vShadowBottomContent: View
26-
2723 private val vCodeList: RecyclerView
24+ private val vShadows: List <View >
2825
2926 /* *
3027 * Primary constructor.
3128 */
3229 init {
3330 inflate(context, R .layout.layout_code_view, this )
31+ checkInitialAnimation(attrs)
32+
33+ // TODO: add shadow color customization
34+ vShadows = listOf (
35+ R .id.v_shadow_right,
36+ R .id.v_shadow_bottom_line,
37+ R .id.v_shadow_bottom_content
38+ ).map(this ::findViewById)
3439
40+ vCodeList = findViewById(R .id.rv_code_content) as RecyclerView
41+ vCodeList.layoutManager = LinearLayoutManager (context)
42+ vCodeList.isNestedScrollingEnabled = true
43+ }
44+
45+ private fun checkInitialAnimation (attrs : AttributeSet ) {
3546 if (visibility == VISIBLE && isAnimateOnStart(context, attrs)) {
3647 alpha = Const .Alpha .Invisible
3748
@@ -41,15 +52,6 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
4152 } else {
4253 alpha = Const .Alpha .Initial
4354 }
44-
45- // TODO: add shadow color customization
46- vShadowRight = findViewById(R .id.v_shadow_right)
47- vShadowBottomLine = findViewById(R .id.v_shadow_bottom_line)
48- vShadowBottomContent = findViewById(R .id.v_shadow_bottom_content)
49-
50- vCodeList = findViewById(R .id.rv_code_content) as RecyclerView
51- vCodeList.layoutManager = LinearLayoutManager (context)
52- vCodeList.isNestedScrollingEnabled = true
5355 }
5456
5557 /* *
@@ -58,13 +60,11 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
5860 */
5961 private fun highlight () {
6062 getAdapter()?.highlight {
61-
6263 animate()
6364 .setDuration(Const .DefaultDelay * 2 )
6465 .alpha(.1f )
65-
6666 delayed {
67- animate().alpha(1f )
67+ animate().alpha(Const . Alpha . Visible )
6868 getAdapter()?.notifyDataSetChanged()
6969 }
7070 }
@@ -78,10 +78,7 @@ class CodeView(context: Context, attrs: AttributeSet) : RelativeLayout(context,
7878 */
7979 private fun setupShadows (isShadows : Boolean ) {
8080 val visibility = if (isShadows) VISIBLE else GONE
81-
82- vShadowRight.visibility = visibility
83- vShadowBottomLine.visibility = visibility
84- vShadowBottomContent.visibility = visibility
81+ vShadows.forEach { it.visibility = visibility }
8582 }
8683
8784 // - Initialization
0 commit comments