Skip to content

Commit c7a4181

Browse files
committed
Code cleanup
1 parent 7a0efcb commit c7a4181

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

codeview/src/main/java/io/github/kbiakov/codeview/CodeView.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ class CodeView @JvmOverloads constructor(
3838
inflate(context, R.layout.layout_code_view, this)
3939
attrs?.let(::checkStartAnimation)
4040

41-
vCodeList = findViewById<RecyclerView>(R.id.rv_code_content)
42-
vCodeList.layoutManager = LinearLayoutManager(context)
43-
vCodeList.isNestedScrollingEnabled = true
41+
vCodeList = findViewById<RecyclerView>(R.id.rv_code_content).apply {
42+
layoutManager = LinearLayoutManager(context)
43+
isNestedScrollingEnabled = true
44+
}
4445

4546
vShadows = mapOf(
4647
ShadowPosition.RightBorder to R.id.shadow_right_border,

codeview/src/main/java/io/github/kbiakov/codeview/views/BidirectionalScrollView.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,18 @@ class BidirectionalScrollView : HorizontalScrollView {
6868
}
6969

7070
override fun measureChild(child: View, parentWidthMeasureSpec: Int, parentHeightMeasureSpec: Int) {
71-
val measureSpecZero = makeMeasureSpec(0)
72-
child.measure(measureSpecZero, measureSpecZero)
71+
val zeroMeasureSpec = makeMeasureSpec(0)
72+
child.measure(zeroMeasureSpec, zeroMeasureSpec)
7373
}
7474

75-
override fun measureChildWithMargins(child: View,
76-
parentWidthMeasureSpec: Int, widthUsed: Int,
77-
parentHeightMeasureSpec: Int, heightUsed: Int) {
78-
val params = child.layoutParams as MarginLayoutParams
79-
val childWidthMeasureSpec = makeMeasureSpec(params.leftMargin + params.rightMargin)
80-
val childHeightMeasureSpec = makeMeasureSpec(params.topMargin + params.bottomMargin)
81-
child.measure(childWidthMeasureSpec, childHeightMeasureSpec)
75+
override fun measureChildWithMargins(
76+
child: View,
77+
parentWidthMeasureSpec: Int, widthUsed: Int,
78+
parentHeightMeasureSpec: Int, heightUsed: Int
79+
) = with(child.layoutParams as MarginLayoutParams) {
80+
val widthMeasureSpec = makeMeasureSpec(leftMargin + rightMargin, MeasureSpec.UNSPECIFIED)
81+
val heightMeasureSpec = makeMeasureSpec(topMargin + bottomMargin, MeasureSpec.UNSPECIFIED)
82+
child.measure(widthMeasureSpec, heightMeasureSpec)
8283
}
8384

8485
private fun makeMeasureSpec(size: Int) = makeMeasureSpec(size, MeasureSpec.UNSPECIFIED)

0 commit comments

Comments
 (0)