Skip to content

Latest commit

 

History

History
15 lines (11 loc) · 1.26 KB

README.md

File metadata and controls

15 lines (11 loc) · 1.26 KB

RecyclerViewDelegate

An example of Hannes Dorfmann AdapterDelegate pattern impl.

The reason of this project is to show how simple is to design and write your own "AdapterDelegate" implementation.

There an example of using AdapterDelegate in simple Android project :sample.

Just be careful with few moments:

  • don't put adapter into viewmodel. it's ok to have link to viewmodel in adapter, but adapter shouldn't have link to viewmodel, bcs viewmodel have different scope and alive longer
  • each item should be possible to be compared - it's the same unit and it was changed. Easy way for it, set for same unit key layout id and for was changed make delegate data class and use Any::equals
  • remember, if you don't clear listeners on onViewRecycled/onUnbindViewHolder, it could affect on onBindViewHolder/onBind
  • DiffUtil work rly slow on big diffs
  • don't make Entity an RecyclerViewDelegate for reusabilyty
  • RecyclerViewDelegate has access to event listener only on bind state. otherwise user may create leak by refs viewmodel as event listener and delegates in livedata