diff --git a/app/src/main/java/com/gh/gamecenter/home/video/ScrollCalculatorHelper.kt b/app/src/main/java/com/gh/gamecenter/home/video/ScrollCalculatorHelper.kt index 1433a12c13..614adac834 100644 --- a/app/src/main/java/com/gh/gamecenter/home/video/ScrollCalculatorHelper.kt +++ b/app/src/main/java/com/gh/gamecenter/home/video/ScrollCalculatorHelper.kt @@ -4,6 +4,8 @@ import android.graphics.Rect import android.os.Handler import android.os.Looper import android.view.View +import android.view.ViewGroup +import androidx.core.view.forEach import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.gh.gamecenter.common.constant.Constants @@ -88,6 +90,12 @@ class ScrollCalculatorHelper(val mListRv: RecyclerView, private val mPlayId: Int if (child is RecyclerView && child.layoutManager is LinearLayoutManager) { val hasChildVideoPlaying = playChildVideo(child) if (hasChildVideoPlaying) break + } else if (child is ViewGroup) { + val childList = findRecyclerView(child) + if (childList != null) { + val hasChildVideoPlaying = playChildVideo(childList) + if (hasChildVideoPlaying) break + } } val player: View? = child?.findViewById(mPlayId) @@ -163,6 +171,20 @@ class ScrollCalculatorHelper(val mListRv: RecyclerView, private val mPlayId: Int return false } + /** + * 如果布局层次结构复杂,这里递归可能过深,为避免此情况,这里暂时只考虑一层的情况 + */ + private fun findRecyclerView(container: ViewGroup): RecyclerView? { + val childCount = container.childCount + for (index in 0 until childCount) { + val child = container.getChildAt(index) + if (child is RecyclerView && child.layoutManager is LinearLayoutManager) { + return child + } + } + return null + } + private inner class PlayRunnable(var videoView: AutomaticVideoView?) : Runnable { override fun run() { if (videoView != null && !videoView!!.isInPlayingState) {