Last active
February 7, 2022 10:55
-
-
Save sumeetph/0615d00c4ba1fa55164845ba4879363d to your computer and use it in GitHub Desktop.
RecyclerView and View level caching
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
| //Return cached view holder for particular position | |
| private val viewCacheExtension = object : ViewCacheExtension() { | |
| override fun getViewForPositionAndType( | |
| recycler: Recycler, | |
| position: Int, | |
| type: Int | |
| ): View? { | |
| val cachedItemId = getItemId(position) | |
| if (cachedViewHolderTypes.contains(type) && cachedItemId != NO_CACHED_ITEM_ID | |
| && cachedItems.containsKey(cachedItemId) | |
| ) { | |
| Timber.d("Returning view from custom cache for position:$position") | |
| return cachedItems[cachedItemId]?.itemView | |
| } | |
| return null | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment