diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/LinearLayoutManagerAccurateOffset.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/LinearLayoutManagerAccurateOffset.kt index 90a4ec92c3..cecfc65cc9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/LinearLayoutManagerAccurateOffset.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/LinearLayoutManagerAccurateOffset.kt @@ -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(R.id.category_title)?.marginTop ?: 0 else 0 - it.bottom >= inset + toolbarHeight - marginTop + val bottom = (if (isLibraryHeader) { + it.findViewById(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(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