From 5bce1d717bcce96613eecf2d3321e8f3204273b6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 8 Jan 2018 12:40:57 +0100 Subject: [PATCH] adding a couple scroll handle show/hide improvements --- build.gradle | 2 +- .../commons/views/FastScroller.kt | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index b55bed684..62ee513ec 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { propMinSdkVersion = 16 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 - propVersionName = '3.6.3' + propVersionName = '3.6.5' kotlin_version = '1.2.10' support_libs = '27.0.2' } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/views/FastScroller.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/views/FastScroller.kt index cd6fbdb67..cb0e26f6c 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/views/FastScroller.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/views/FastScroller.kt @@ -73,8 +73,15 @@ class FastScroller : FrameLayout { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { super.onScrollStateChanged(recyclerView, newState) - if (isScrollingEnabled && newState == RecyclerView.SCROLL_STATE_DRAGGING) { + if (!isScrollingEnabled) { + hideHandle() + return + } + + if (newState == RecyclerView.SCROLL_STATE_DRAGGING) { showHandle() + } else if (newState == RecyclerView.SCROLL_STATE_IDLE) { + hideHandle() } } }) @@ -109,7 +116,9 @@ class FastScroller : FrameLayout { fun setScrollTo(y: Int) { currScrollY = y + measureRecyclerView() updateHandlePosition() + hideHandle() } fun updatePrimaryColor() { @@ -161,7 +170,6 @@ class FastScroller : FrameLayout { handle!!.y = getValueInRange(0f, recyclerViewHeight - handleHeight.toFloat(), targetY) } showHandle() - hideHandle() } override fun onTouchEvent(event: MotionEvent): Boolean { @@ -269,11 +277,12 @@ class FastScroller : FrameLayout { private fun showHandle() { handleHideHandler.removeCallbacksAndMessages(null) - handle!!.animate().alpha(1f).start() // override the fadeout animation - handle!!.alpha = 1f - if (handleWidth == 0 && handleHeight == 0) { - handleWidth = handle!!.width - handleHeight = handle!!.height + if (handle!!.alpha != 1f) { + handle!!.alpha = 1f + if (handleWidth == 0 && handleHeight == 0) { + handleWidth = handle!!.width + handleHeight = handle!!.height + } } }