108 lines
3.6 KiB
Kotlin
108 lines
3.6 KiB
Kotlin
//package com.gh.common.view
|
|
//
|
|
//import android.content.Context
|
|
//import android.util.AttributeSet
|
|
//import android.view.MotionEvent
|
|
//import android.widget.LinearLayout
|
|
//import androidx.annotation.Nullable
|
|
//import androidx.core.view.children
|
|
//import androidx.lifecycle.Lifecycle
|
|
//import androidx.lifecycle.LifecycleObserver
|
|
//import androidx.lifecycle.OnLifecycleEvent
|
|
//import androidx.recyclerview.widget.RecyclerView
|
|
//import com.gh.common.AppExecutor
|
|
//import java.lang.ref.WeakReference
|
|
//
|
|
// TODO 多页面会出现问题
|
|
//class AutoScrollRecyclerViewContainerView(context: Context, @Nullable attrs: AttributeSet?)
|
|
// : LinearLayout(context, attrs), LifecycleObserver {
|
|
//
|
|
// var autoScrollTask: AutoScrollTask?
|
|
//
|
|
// private var mIsScrolling = false
|
|
// private var mIsScrollable = false
|
|
// private var mLastScrollTime = 0L
|
|
//
|
|
// private var mOnItemTouchListener: RecyclerView.OnItemTouchListener? = null
|
|
//
|
|
// init {
|
|
// autoScrollTask = AutoScrollTask(this)
|
|
// }
|
|
//
|
|
// override fun onAttachedToWindow() {
|
|
// super.onAttachedToWindow()
|
|
//
|
|
// if (mOnItemTouchListener == null) {
|
|
// mOnItemTouchListener = object : RecyclerView.OnItemTouchListener {
|
|
// override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {}
|
|
// override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent) = rv.scrollState == RecyclerView.SCROLL_STATE_DRAGGING
|
|
// override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {}
|
|
// }
|
|
// }
|
|
//
|
|
// for (child in children) {
|
|
// if (child is RecyclerView) {
|
|
// child.removeOnItemTouchListener(mOnItemTouchListener!!)
|
|
// child.addOnItemTouchListener(mOnItemTouchListener!!)
|
|
// }
|
|
// }
|
|
//
|
|
// resumeScrolling()
|
|
// }
|
|
//
|
|
// override fun onDetachedFromWindow() {
|
|
// super.onDetachedFromWindow()
|
|
//
|
|
// pauseScrolling()
|
|
// }
|
|
//
|
|
// @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
// fun resumeScrolling() {
|
|
// if (mIsScrolling) return
|
|
//
|
|
// mIsScrollable = true
|
|
// mIsScrolling = true
|
|
//
|
|
// AppExecutor.lightWeightIoExecutor.execute {
|
|
// while (mIsScrolling && autoScrollTask != null) {
|
|
// if (System.currentTimeMillis() - mLastScrollTime >= AUTO_SCROLL_INTERVAL) {
|
|
// mLastScrollTime = System.currentTimeMillis()
|
|
// AppExecutor.uiExecutor.execute(autoScrollTask!!)
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
// fun pauseScrolling() {
|
|
// mIsScrolling = false
|
|
// }
|
|
//
|
|
// fun setLifeCycleOwner(lifeCycleOwner: Lifecycle) {
|
|
// lifeCycleOwner.addObserver(this)
|
|
// }
|
|
//
|
|
// companion object {
|
|
// private const val AUTO_SCROLL_INTERVAL: Long = 16
|
|
// private const val SCROLL_SLOP = 1
|
|
// }
|
|
//
|
|
// class AutoScrollTask(reference: AutoScrollRecyclerViewContainerView?) : Runnable {
|
|
// private val mReference: WeakReference<AutoScrollRecyclerViewContainerView?>?
|
|
//
|
|
// init {
|
|
// mReference = WeakReference(reference)
|
|
// }
|
|
//
|
|
// override fun run() {
|
|
// val containerView: AutoScrollRecyclerViewContainerView? = mReference?.get()
|
|
// if (containerView != null && containerView.mIsScrolling && containerView.mIsScrollable) {
|
|
// for (child in containerView.children) {
|
|
// if (child is RecyclerView) {
|
|
// child.scrollBy(SCROLL_SLOP, SCROLL_SLOP)
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//} |