mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Fix findfirstpos not working correctly sometimes in library
This commit is contained in:
parent
94dfaf9be2
commit
6bc279cef4
1 changed files with 6 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue