Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RecycledViewPool

 RecycledViewPool

Moyuru Aizawa

June 28, 2019
Tweet

More Decks by Moyuru Aizawa

Other Decks in Programming

Transcript

  1. “To maximize view recycling we share the same view pool

    across all EpoxyRecyclerView instances in the same Activity.” BJSCOCFQPYZ&QPYZ3FDZDMFS7JFX
  2. class RecycledViewPoolFactory { private val viewPools = SparseArray<RecycledViewPool>() private fun

    create(lifecycleOwner: LifecycleOwner): RecycledViewPool { viewPools.get(lifecycleOwner.hashCode())?.let { return it } val viewPool = RecycledViewPool() viewPools.put(lifecycleOwner.hashCode(), viewPool) lifecycleOwner.lifecycle .addObserver(LifecycleEventObserver { _, event -> if (event == Lifecycle.Event.ON_DESTROY) { viewPool.clear() viewPools.remove(lifecycleOwner.hashCode()) } }) return viewPool } } 3FDZDMFE7JFX1PPM'BDUPSZ
  3. class RecycledViewPoolFactory { private val viewPools = SparseArray<RecycledViewPool>() private fun

    create(lifecycleOwner: LifecycleOwner): RecycledViewPool { viewPools.get(lifecycleOwner.hashCode())?.let { return it } val viewPool = RecycledViewPool() viewPools.put(lifecycleOwner.hashCode(), viewPool) lifecycleOwner.lifecycle .addObserver(LifecycleEventObserver { _, event -> if (event == Lifecycle.Event.ON_DESTROY) { viewPool.clear() viewPools.remove(lifecycleOwner.hashCode()) } }) return viewPool } } 3FDZDMFE7JFX1PPM'BDUPSZ
  4. class RecycledViewPoolFactory { private val viewPools = SparseArray<RecycledViewPool>() private fun

    create(lifecycleOwner: LifecycleOwner): RecycledViewPool { viewPools.get(lifecycleOwner.hashCode())?.let { return it } val viewPool = RecycledViewPool() viewPools.put(lifecycleOwner.hashCode(), viewPool) lifecycleOwner.lifecycle .addObserver(LifecycleEventObserver { _, event -> if (event == Lifecycle.Event.ON_DESTROY) { viewPool.clear() viewPools.remove(lifecycleOwner.hashCode()) } }) return viewPool } } 3FDZDMFE7JFX1PPM'BDUPSZ
  5. class RecycledViewPoolFactory { private val viewPools = SparseArray<RecycledViewPool>() private fun

    create(lifecycleOwner: LifecycleOwner): RecycledViewPool { viewPools.get(lifecycleOwner.hashCode())?.let { return it } val viewPool = RecycledViewPool() viewPools.put(lifecycleOwner.hashCode(), viewPool) lifecycleOwner.lifecycle .addObserver(LifecycleEventObserver { _, event -> if (event == Lifecycle.Event.ON_DESTROY) { viewPool.clear() viewPools.remove(lifecycleOwner.hashCode()) } }) return viewPool } } 3FDZDMFE7JFX1PPM'BDUPSZ
  6. class RecycledViewPoolFactory { private val viewPools = SparseArray<RecycledViewPool>() private fun

    create(lifecycleOwner: LifecycleOwner): RecycledViewPool { viewPools.get(lifecycleOwner.hashCode())?.let { return it } val viewPool = RecycledViewPool() viewPools.put(lifecycleOwner.hashCode(), viewPool) lifecycleOwner.lifecycle .addObserver(LifecycleEventObserver { _, event -> if (event == Lifecycle.Event.ON_DESTROY) { viewPool.clear() viewPools.remove(lifecycleOwner.hashCode()) } }) return viewPool } } 3FDZDMFE7JFX1PPM'BDUPSZ
  7. class RecycledViewPoolFactory { private val viewPools = SparseArray<RecycledViewPool>() private fun

    create(lifecycleOwner: LifecycleOwner): RecycledViewPool { viewPools.get(lifecycleOwner.hashCode())?.let { return it } val viewPool = RecycledViewPool() viewPools.put(lifecycleOwner.hashCode(), viewPool) lifecycleOwner.lifecycle .addObserver(LifecycleEventObserver { _, event -> if (event == Lifecycle.Event.ON_DESTROY) { viewPool.clear() viewPools.remove(lifecycleOwner.hashCode()) } }) return viewPool } } 3FDZDMFE7JFX1PPM'BDUPSZ
  8. class RecycledViewPoolFactory { private val viewPools = SparseArray<RecycledViewPool>() private fun

    create(lifecycleOwner: LifecycleOwner): RecycledViewPool { viewPools.get(lifecycleOwner.hashCode())?.let { return it } val viewPool = RecycledViewPool() viewPools.put(lifecycleOwner.hashCode(), viewPool) lifecycleOwner.lifecycle .addObserver(LifecycleEventObserver { _, event -> if (event == Lifecycle.Event.ON_DESTROY) { viewPool.clear() viewPools.remove(lifecycleOwner.hashCode()) } }) return viewPool } } 3FDZDMFE7JFX1PPM'BDUPSZ