Skip to content

Instantly share code, notes, and snippets.

@sumeetph
Last active February 7, 2022 10:55
Show Gist options
  • Select an option

  • Save sumeetph/0615d00c4ba1fa55164845ba4879363d to your computer and use it in GitHub Desktop.

Select an option

Save sumeetph/0615d00c4ba1fa55164845ba4879363d to your computer and use it in GitHub Desktop.
RecyclerView and View level caching
//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