temporarily comment out the extra methods for grid manager offset

the main one needed is the computeVerticalScrollOffset for the app bar anyway
This commit is contained in:
Jays2Kings 2022-05-04 02:25:05 -04:00
parent 8e5d3016b6
commit 1c4215a371

View file

@ -4,7 +4,6 @@ import android.content.Context
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import kotlin.math.max
class GridLayoutManagerAccurateOffset(context: Context?, spanCount: Int) : GridLayoutManager(context, spanCount) { class GridLayoutManagerAccurateOffset(context: Context?, spanCount: Int) : GridLayoutManager(context, spanCount) {
@ -25,23 +24,23 @@ class GridLayoutManagerAccurateOffset(context: Context?, spanCount: Int) : GridL
height height
} }
override fun onLayoutCompleted(state: RecyclerView.State) { // override fun onLayoutCompleted(state: RecyclerView.State) {
super.onLayoutCompleted(state) // super.onLayoutCompleted(state)
computedRange = null // computedRange = null
for (i in 0 until childCount) { // for (i in 0 until childCount) {
val child = getChildAt(i) ?: return // val child = getChildAt(i) ?: return
val position = getPosition(child) // val position = getPosition(child)
childSizesMap[position] = child.height // childSizesMap[position] = child.height
childSpanMap[position] = spanSizeLookup.getSpanSize(getPosition(child)) // childSpanMap[position] = spanSizeLookup.getSpanSize(getPosition(child))
val type = getItemViewType(child) // val type = getItemViewType(child)
childTypeMap[position] = type // childTypeMap[position] = type
if (childTypeHeightMap[type] != null) { // if (childTypeHeightMap[type] != null) {
childTypeHeightMap[type]!![position] = child.height // childTypeHeightMap[type]!![position] = child.height
} else { // } else {
childTypeHeightMap[type] = hashMapOf(position to child.height) // childTypeHeightMap[type] = hashMapOf(position to child.height)
} // }
} // }
} // }
override fun onAttachedToWindow(view: RecyclerView?) { override fun onAttachedToWindow(view: RecyclerView?) {
super.onAttachedToWindow(view) super.onAttachedToWindow(view)
@ -53,85 +52,102 @@ class GridLayoutManagerAccurateOffset(context: Context?, spanCount: Int) : GridL
rView = null rView = null
} }
override fun computeVerticalScrollRange(state: RecyclerView.State): Int {
if (childCount == 0) return 0
computedRange?.let {
return it
}
rView ?: return super.computeVerticalScrollRange(state)
var scrolledY = 0
var spanC = 0
var maxHeight = 0
val childAvgHeightMap = HashMap<Int, Int>()
for (i in 0 until itemCount) {
val height: Int = getItemHeight(i, childAvgHeightMap)
val spanCurrentSize = childSpanMap[i] ?: spanSizeLookup.getSpanSize(i)
if (spanCount <= spanCurrentSize) {
scrolledY += height
scrolledY += maxHeight
maxHeight = 0
spanC = 0
} else if (spanCurrentSize == 1) {
maxHeight = max(maxHeight, height)
spanC++
if (spanC <= spanCount) {
scrolledY += maxHeight
maxHeight = 0
spanC = 0
}
}
}
computedRange = scrolledY
return scrolledY
}
override fun computeVerticalScrollOffset(state: RecyclerView.State): Int { override fun computeVerticalScrollOffset(state: RecyclerView.State): Int {
if (childCount == 0) { if (childCount == 0) {
return 0 return 0
} }
rView ?: return super.computeVerticalScrollOffset(state) rView ?: return super.computeVerticalScrollOffset(state)
val firstChild = getChildAt(0) ?: return 0 val firstChild = (0 until childCount)
val firstChildPosition = (0 until childCount)
.mapNotNull { getChildAt(it) } .mapNotNull { getChildAt(it) }
.mapNotNull { pos -> getPosition(pos).takeIf { it != RecyclerView.NO_POSITION } } .mapNotNull { pos -> (pos to getPosition(pos)).takeIf { it.second != RecyclerView.NO_POSITION } }
.minOrNull() ?: 0 .minByOrNull { it.second } ?: return 0
var scrolledY: Int = -firstChild.y.toInt() val scrolledY: Int = -firstChild.first.y.toInt()
var spanC = 0 return if (firstChild.second == 0) {
var maxHeight = 0 scrolledY + paddingTop
val childAvgHeightMap = HashMap<Int, Int>() } else {
for (i in 0 until firstChildPosition) { super.computeVerticalScrollOffset(state)
val height: Int = getItemHeight(i, childAvgHeightMap)
val spanCurrentSize = childSpanMap[i] ?: spanSizeLookup.getSpanSize(i)
if (spanCount <= spanCurrentSize) {
scrolledY += height
scrolledY += maxHeight
maxHeight = 0
spanC = 0
} else if (spanCurrentSize == 1) {
maxHeight = max(maxHeight, height)
spanC++
if (spanC <= spanCount) {
scrolledY += maxHeight
maxHeight = 0
spanC = 0
}
}
} }
scrolledY += maxHeight
return scrolledY + paddingTop
}
private fun getItemHeight(pos: Int, childAvgHeightMap: HashMap<Int, Int>): Int {
return EstimatedItemHeight.itemOrEstimatedHeight(
pos,
rView?.adapter?.getItemViewType(pos),
childSizesMap,
childTypeMap,
childTypeHeightMap,
childTypeEstimateMap,
childAvgHeightMap,
)
} }
//
// override fun computeVerticalScrollRange(state: RecyclerView.State): Int {
// if (childCount == 0) return 0
// computedRange?.let {
// return it
// }
// rView ?: return super.computeVerticalScrollRange(state)
// var scrolledY = 0
// var spanC = 0
// var maxHeight = 0
// val childAvgHeightMap = HashMap<Int, Int>()
// for (i in 0 until itemCount) {
// val height: Int = getItemHeight(i, childAvgHeightMap)
// val spanCurrentSize = childSpanMap[i] ?: spanSizeLookup.getSpanSize(i)
// if (spanCount <= spanCurrentSize) {
// scrolledY += height
// scrolledY += maxHeight
// maxHeight = 0
// spanC = 0
// } else if (spanCurrentSize == 1) {
// maxHeight = max(maxHeight, height)
// spanC++
// if (spanC <= spanCount) {
// scrolledY += maxHeight
// maxHeight = 0
// spanC = 0
// }
// }
// }
// computedRange = scrolledY
// return scrolledY
// }
//
// override fun computeVerticalScrollOffset(state: RecyclerView.State): Int {
// if (childCount == 0) {
// return 0
// }
// rView ?: return super.computeVerticalScrollOffset(state)
// val firstChild = getChildAt(0) ?: return 0
// val firstChildPosition = (0 until childCount)
// .mapNotNull { getChildAt(it) }
// .mapNotNull { pos -> getPosition(pos).takeIf { it != RecyclerView.NO_POSITION } }
// .minOrNull() ?: 0
// var scrolledY: Int = -firstChild.y.toInt()
// var spanC = 0
// var maxHeight = 0
// val childAvgHeightMap = HashMap<Int, Int>()
// for (i in 0 until firstChildPosition) {
// val height: Int = getItemHeight(i, childAvgHeightMap)
// val spanCurrentSize = childSpanMap[i] ?: spanSizeLookup.getSpanSize(i)
// if (spanCount <= spanCurrentSize) {
// scrolledY += height
// scrolledY += maxHeight
// maxHeight = 0
// spanC = 0
// } else if (spanCurrentSize == 1) {
// maxHeight = max(maxHeight, height)
// spanC++
// if (spanC <= spanCount) {
// scrolledY += maxHeight
// maxHeight = 0
// spanC = 0
// }
// }
// }
// scrolledY += maxHeight
// return scrolledY + paddingTop
// }
//
// private fun getItemHeight(pos: Int, childAvgHeightMap: HashMap<Int, Int>): Int {
// return EstimatedItemHeight.itemOrEstimatedHeight(
// pos,
// rView?.adapter?.getItemViewType(pos),
// childSizesMap,
// childTypeMap,
// childTypeHeightMap,
// childTypeEstimateMap,
// childAvgHeightMap,
// )
// }
override fun findFirstVisibleItemPosition(): Int { override fun findFirstVisibleItemPosition(): Int {
return getFirstPos(rView, toolbarHeight) return getFirstPos(rView, toolbarHeight)