mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
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:
parent
8e5d3016b6
commit
1c4215a371
1 changed files with 105 additions and 89 deletions
|
@ -4,7 +4,6 @@ import android.content.Context
|
|||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import kotlin.math.max
|
||||
|
||||
class GridLayoutManagerAccurateOffset(context: Context?, spanCount: Int) : GridLayoutManager(context, spanCount) {
|
||||
|
||||
|
@ -25,23 +24,23 @@ class GridLayoutManagerAccurateOffset(context: Context?, spanCount: Int) : GridL
|
|||
height
|
||||
}
|
||||
|
||||
override fun onLayoutCompleted(state: RecyclerView.State) {
|
||||
super.onLayoutCompleted(state)
|
||||
computedRange = null
|
||||
for (i in 0 until childCount) {
|
||||
val child = getChildAt(i) ?: return
|
||||
val position = getPosition(child)
|
||||
childSizesMap[position] = child.height
|
||||
childSpanMap[position] = spanSizeLookup.getSpanSize(getPosition(child))
|
||||
val type = getItemViewType(child)
|
||||
childTypeMap[position] = type
|
||||
if (childTypeHeightMap[type] != null) {
|
||||
childTypeHeightMap[type]!![position] = child.height
|
||||
} else {
|
||||
childTypeHeightMap[type] = hashMapOf(position to child.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
// override fun onLayoutCompleted(state: RecyclerView.State) {
|
||||
// super.onLayoutCompleted(state)
|
||||
// computedRange = null
|
||||
// for (i in 0 until childCount) {
|
||||
// val child = getChildAt(i) ?: return
|
||||
// val position = getPosition(child)
|
||||
// childSizesMap[position] = child.height
|
||||
// childSpanMap[position] = spanSizeLookup.getSpanSize(getPosition(child))
|
||||
// val type = getItemViewType(child)
|
||||
// childTypeMap[position] = type
|
||||
// if (childTypeHeightMap[type] != null) {
|
||||
// childTypeHeightMap[type]!![position] = child.height
|
||||
// } else {
|
||||
// childTypeHeightMap[type] = hashMapOf(position to child.height)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
override fun onAttachedToWindow(view: RecyclerView?) {
|
||||
super.onAttachedToWindow(view)
|
||||
|
@ -53,85 +52,102 @@ class GridLayoutManagerAccurateOffset(context: Context?, spanCount: Int) : GridL
|
|||
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 {
|
||||
if (childCount == 0) {
|
||||
return 0
|
||||
}
|
||||
rView ?: return super.computeVerticalScrollOffset(state)
|
||||
val firstChild = getChildAt(0) ?: return 0
|
||||
val firstChildPosition = (0 until childCount)
|
||||
val firstChild = (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
|
||||
}
|
||||
}
|
||||
.mapNotNull { pos -> (pos to getPosition(pos)).takeIf { it.second != RecyclerView.NO_POSITION } }
|
||||
.minByOrNull { it.second } ?: return 0
|
||||
val scrolledY: Int = -firstChild.first.y.toInt()
|
||||
return if (firstChild.second == 0) {
|
||||
scrolledY + paddingTop
|
||||
} else {
|
||||
super.computeVerticalScrollOffset(state)
|
||||
}
|
||||
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 {
|
||||
return getFirstPos(rView, toolbarHeight)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue