From 0007d7d79072c361cd6d8e542c0804d1f2ec518d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Thu, 20 Jan 2022 20:00:55 +0100 Subject: [PATCH] Reducing duplicate code. I have moved the isVisible declaration outside the switch to enhance readability and reduce duplicate code. Since iconView is only true when textView isn't the assignment of iconView.isVisible is the inverse of textView.isVisible. --- .../FastScrollerThumbView.kt | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerThumbView.kt b/indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerThumbView.kt index f7f266c..ef37399 100644 --- a/indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerThumbView.kt +++ b/indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerThumbView.kt @@ -146,20 +146,13 @@ class FastScrollerThumbView @JvmOverloads constructor( ) { val thumbTargetY = indicatorCenterY.toFloat() - (thumbView.measuredHeight / 2) thumbAnimation.animateToFinalPosition(thumbTargetY) - - when (indicator) { - is FastScrollItemIndicator.Text -> { - textView.isVisible = true - iconView.isVisible = false - - textView.text = indicator.text - } - is FastScrollItemIndicator.Icon -> { - textView.isVisible = false - iconView.isVisible = true - - iconView.setImageResource(indicator.iconRes) - } + + textView.isVisible = indicator is FastScrollItemIndicator.Text + iconView.isVisible = !textView.isVisible + + when (textView.isVisible) { + true -> textView.text = indicator.text + false -> iconView.setImageResource(indicator.iconRes) } } }