Last active
March 3, 2022 14:21
-
-
Save sumeetph/d93ca2876c7923f7031929d9acb9841e to your computer and use it in GitHub Desktop.
Cache OnItem Removed
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 onItemRangeRemoved(positionStart: Int, itemCount: Int) { | |
| Timber.d("On Item range removed called for adapter observer") | |
| if (cachedItems.isEmpty()) | |
| return | |
| val iterator: MutableIterator<String> = cachedItems.keys.iterator() | |
| while (iterator.hasNext()) { | |
| val cachedItemId = iterator.next() | |
| val index = cachedItems[cachedItemId]?.bindingAdapterPosition ?: -1 | |
| if (index != -1 && positionStart <= index && index < positionStart + itemCount) { | |
| Timber.d("Removing view from adapter observer for position:$index") | |
| val holder = cachedItems[cachedItemId] | |
| holder?.itemView?.let { view -> | |
| if (view.isAttachedToWindow || view.parent != null) { | |
| recyclerView?.removeView(view) | |
| view.visibility = View.GONE | |
| } | |
| } | |
| iterator.remove() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment