Remove NoLeakThumbView
Remove the old NoLeakThumbView class, apparently I didnt remove it before?
This commit is contained in:
parent
917540e626
commit
abd5b3ca8d
2 changed files with 0 additions and 171 deletions
|
@ -8,7 +8,6 @@ import android.util.AttributeSet
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.widget.AppCompatImageButton
|
import androidx.appcompat.widget.AppCompatImageButton
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.logD
|
|
||||||
import org.oxycblt.auxio.ui.toAnimDrawable
|
import org.oxycblt.auxio.ui.toAnimDrawable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,170 +0,0 @@
|
||||||
package org.oxycblt.auxio.recycler
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.res.ColorStateList
|
|
||||||
import android.graphics.drawable.GradientDrawable
|
|
||||||
import android.os.Build
|
|
||||||
import android.util.AttributeSet
|
|
||||||
import android.view.MotionEvent
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.ImageView
|
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
import androidx.core.view.children
|
|
||||||
import androidx.core.view.isVisible
|
|
||||||
import androidx.core.widget.TextViewCompat
|
|
||||||
import androidx.dynamicanimation.animation.DynamicAnimation
|
|
||||||
import androidx.dynamicanimation.animation.SpringAnimation
|
|
||||||
import androidx.dynamicanimation.animation.SpringForce
|
|
||||||
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
|
||||||
import com.reddit.indicatorfastscroll.FastScrollerView
|
|
||||||
import org.oxycblt.auxio.R
|
|
||||||
import org.oxycblt.auxio.ui.Accent
|
|
||||||
import org.oxycblt.auxio.ui.inflater
|
|
||||||
import org.oxycblt.auxio.ui.toColor
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A semi-copy, semi-custom implementation of [com.reddit.indicatorfastscroll.FastScrollerThumbView]
|
|
||||||
* that fixes a memory leak that occurs from a bug fix they added.
|
|
||||||
* All credit goes to the authors of the fast scroll library.
|
|
||||||
*
|
|
||||||
* https://github.com/reddit/IndicatorFastScroll
|
|
||||||
* @author Reddit, OxygenCobalt
|
|
||||||
*/
|
|
||||||
class NoLeakThumbView @JvmOverloads constructor(
|
|
||||||
context: Context,
|
|
||||||
attrs: AttributeSet? = null,
|
|
||||||
defStyleAttr: Int = R.attr.indicatorFastScrollerThumbStyle
|
|
||||||
) : ConstraintLayout(context, attrs, defStyleAttr),
|
|
||||||
FastScrollerView.ItemIndicatorSelectedCallback {
|
|
||||||
|
|
||||||
private val thumbColor = Accent.get().getStateList(context)
|
|
||||||
private val iconColor = R.color.background.toColor(context)
|
|
||||||
private val textAppearanceRes = R.style.TextAppearance_ThumbIndicator
|
|
||||||
private val textColor = R.color.background.toColor(context)
|
|
||||||
|
|
||||||
private val thumbView: ViewGroup
|
|
||||||
private val textView: TextView
|
|
||||||
private val iconView: ImageView
|
|
||||||
|
|
||||||
private val isSetup: Boolean get() = (fastScrollerView != null)
|
|
||||||
private var fastScrollerView: FastScrollerView? = null
|
|
||||||
|
|
||||||
private val thumbAnimation: SpringAnimation
|
|
||||||
|
|
||||||
init {
|
|
||||||
// --- VIEW SETUP ---
|
|
||||||
context.inflater.inflate(R.layout.fast_scroller_thumb_view, this, true)
|
|
||||||
|
|
||||||
thumbView = findViewById(R.id.fast_scroller_thumb)
|
|
||||||
textView = thumbView.findViewById(R.id.fast_scroller_thumb_text)
|
|
||||||
iconView = thumbView.findViewById(R.id.fast_scroller_thumb_icon)
|
|
||||||
|
|
||||||
// --- UI SETUP ---
|
|
||||||
|
|
||||||
isActivated = false
|
|
||||||
isVisible = false
|
|
||||||
|
|
||||||
thumbView.backgroundTintList = thumbColor
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT == 21) {
|
|
||||||
// Workaround for 21 background tint bug
|
|
||||||
(thumbView.background as GradientDrawable).apply {
|
|
||||||
mutate()
|
|
||||||
color = thumbColor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TextViewCompat.setTextAppearance(textView, textAppearanceRes)
|
|
||||||
|
|
||||||
textView.setTextColor(textColor)
|
|
||||||
iconView.imageTintList = ColorStateList.valueOf(iconColor)
|
|
||||||
|
|
||||||
thumbAnimation = SpringAnimation(thumbView, DynamicAnimation.TRANSLATION_Y).apply {
|
|
||||||
spring = SpringForce().apply {
|
|
||||||
dampingRatio = SpringForce.DAMPING_RATIO_NO_BOUNCY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup this view with a [FastScrollerView].
|
|
||||||
*/
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
|
||||||
fun setupWithFastScroller(fastScrollerView: FastScrollerView) {
|
|
||||||
check(!isSetup) { "Only set this view's FastScrollerView once!" }
|
|
||||||
|
|
||||||
this.fastScrollerView = fastScrollerView
|
|
||||||
|
|
||||||
fastScrollerView.itemIndicatorSelectedCallbacks += this
|
|
||||||
|
|
||||||
// FastScrollerView's "onItemIndicatorTouched" [Which I would've used here] is internal,
|
|
||||||
// so instead I just use a setOnTouchListener to get the same-ish effect.
|
|
||||||
fastScrollerView.setOnTouchListener { _, event ->
|
|
||||||
fastScrollerView.onTouchEvent(event)
|
|
||||||
fastScrollerView.performClick()
|
|
||||||
|
|
||||||
isVisible = true
|
|
||||||
|
|
||||||
if (event.actionMasked == MotionEvent.ACTION_UP ||
|
|
||||||
event.actionMasked == MotionEvent.ACTION_CANCEL
|
|
||||||
) {
|
|
||||||
isActivated = false
|
|
||||||
return@setOnTouchListener true
|
|
||||||
}
|
|
||||||
|
|
||||||
isActivated = isPointerOnItem(fastScrollerView, event.y.toInt())
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hack so that I can detect when the pointer is on the FastScrollerView's items
|
|
||||||
* without using onItemIndicatorTouched (Which is internal)
|
|
||||||
* @author OxygenCobalt
|
|
||||||
*/
|
|
||||||
private fun isPointerOnItem(fastScrollerView: FastScrollerView, touchY: Int): Boolean {
|
|
||||||
fun View.containsY(y: Int) = y in (top until bottom)
|
|
||||||
|
|
||||||
var consumed = false
|
|
||||||
|
|
||||||
fastScrollerView.apply {
|
|
||||||
children.forEach { view ->
|
|
||||||
if (view.containsY(touchY)) {
|
|
||||||
consumed = true
|
|
||||||
return@forEach
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return consumed
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemIndicatorSelected(
|
|
||||||
indicator: FastScrollItemIndicator,
|
|
||||||
indicatorCenterY: Int,
|
|
||||||
itemPosition: Int
|
|
||||||
) {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue