This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DragGestureDetector(private val onDragListener: OnDragListener) { | |
| var posX = 0f | |
| private set | |
| var posY = 0f | |
| private set | |
| private var activePointerId = -1 | |
| fun onTouchEvent(event: MotionEvent): Boolean { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RotateGestureDetector(private val onRotateListener: OnRotateListener) { | |
| val rotationDeltaDegrees: Float | |
| get() { | |
| val diffRadians = atan2(prevDiffY, prevDiffX) - atan2(currDiffY, currDiffX) | |
| return Math.toDegrees(diffRadians.toDouble()).toFloat() | |
| } | |
| var focusX = 0f | |
| private set |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal fun onItemCreatedOutside(viewType: Int) { | |
| itemsCreated[viewType] = itemsCreated.getOrZero(viewType) + 1 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typealias ViewHolderProducer = (parent: ViewGroup, viewType: Int) -> RecyclerView.ViewHolder |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected fun createItem(viewType: Int) { | |
| val created = itemsCreated.getOrZero(viewType) + 1 | |
| val queued = itemsQueued.getOrZero(viewType) | |
| if (created > queued) return | |
| val holder: RecyclerView.ViewHolder | |
| val start: Long | |
| val end: Long | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal fun setPrefetchBound(viewType: Int, count: Int) { | |
| if (itemsQueued.getOrZero(viewType) >= count) return | |
| itemsQueued[viewType] = count | |
| val created = itemsCreated.getOrZero(viewType) | |
| if (created >= count) return | |
| repeat(count - created) { enqueueItemCreation(viewType) } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typealias ViewHolderProducer = (parent: ViewGroup, viewType: Int) -> RecyclerView.ViewHolder | |
| typealias ViewHolderConsumer = (viewHolder: RecyclerView.ViewHolder, creationTimeNanos: Long) -> Unit | |
| abstract class ViewHolderSupplier( | |
| context: Context, | |
| private val viewHolderProducer: ViewHolderProducer | |
| ) { | |
| internal lateinit var viewHolderConsumer: ViewHolderConsumer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| init { | |
| attachToPreventFromClearing() | |
| viewHolderSupplier.viewHolderConsumer = ::putViewFromSupplier | |
| viewHolderSupplier.start() | |
| } | |
| private fun putViewFromSupplier(scrap: RecyclerView.ViewHolder, creationTimeNanos: Long) { | |
| factorInCreateTime(scrap.itemViewType, creationTimeNanos) | |
| putRecycledView(scrap) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun getRecycledView(viewType: Int): RecyclerView.ViewHolder? { | |
| val holder = super.getRecycledView(viewType) | |
| if (holder == null) viewHolderSupplier.onItemCreatedOutside(viewType) | |
| return holder | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun putRecycledView(scrap: RecyclerView.ViewHolder) { | |
| val viewType = scrap.itemViewType | |
| val maxRecycledViews = recycledViewsBounds.getOrPut(viewType) { defaultMaxRecycledViews } | |
| setMaxRecycledViews(viewType, maxRecycledViews) | |
| super.putRecycledView(scrap) | |
| } |
NewerOlder