Fix findfirstpos not working correctly sometimes in library

This commit is contained in:
Jays2Kings 2022-04-30 14:24:12 -04:00
parent 94dfaf9be2
commit 6bc279cef4

View file

@ -8,6 +8,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.rootWindowInsetsCompat
import kotlin.math.roundToInt
class LinearLayoutManagerAccurateOffset(context: Context?) : LinearLayoutManager(context) {
@ -103,8 +104,10 @@ fun RecyclerView.LayoutManager.getFirstPos(recyclerView: RecyclerView?, toolbarH
.mapNotNull { getChildAt(it) }
.filter {
val isLibraryHeader = getItemViewType(it) == R.layout.library_category_header_item
val marginTop = if (isLibraryHeader) it.findViewById<TextView>(R.id.category_title)?.marginTop ?: 0 else 0
it.bottom >= inset + toolbarHeight - marginTop
val bottom = (if (isLibraryHeader) {
it.findViewById<TextView>(R.id.category_title)?.bottom?.plus(it.y)?.roundToInt()
} else it.bottom) ?: it.bottom
bottom >= inset + toolbarHeight && it.height > 0
}
.mapNotNull { pos -> getPosition(pos).takeIf { it != RecyclerView.NO_POSITION } }
.minOrNull() ?: RecyclerView.NO_POSITION
@ -117,7 +120,7 @@ fun RecyclerView.LayoutManager.getFirstCompletePos(recyclerView: RecyclerView?,
.filter {
val isLibraryHeader = getItemViewType(it) == R.layout.library_category_header_item
val marginTop = if (isLibraryHeader) it.findViewById<TextView>(R.id.category_title)?.marginTop ?: 0 else 0
it.y >= inset + toolbarHeight - marginTop
it.y >= inset + toolbarHeight - marginTop && it.height > 0
}
.mapNotNull { pos -> getPosition(pos).takeIf { it != RecyclerView.NO_POSITION } }
.minOrNull() ?: RecyclerView.NO_POSITION