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

DiffUtil and ListAdapter

DiffUtil and ListAdapter

DiffUtil and ListAdapter
2018/04/19 potatotips 50

Masatoshi Kubode

April 19, 2018
Tweet

More Decks by Masatoshi Kubode

Other Decks in Programming

Transcript

  1. ©2018 Wantedly, Inc.
    DiffUtil and ListAdapter
    potatotips 50
    19.Apr.2018 - Masatoshi Kubode

    View full-size slide

  2. ©2018 Wantedly, Inc.
    Self introduction
    Masatoshi Kubode
    Twitter: @swiz_ard
    GitHub: @kubode
    Qiita: @kubode
    Wantedly Visit UserGrowth

    View full-size slide

  3. ©2018 Wantedly, Inc.
    1. DiffUtil
    2. ListAdapter
    3. Demo
    Agenda

    View full-size slide

  4. ©2018 Wantedly, Inc.
    DiffUtil

    View full-size slide

  5. ©2018 Wantedly, Inc.
    • Calculates the differences between 2 lists
    • Detects change, insert, remove, move
    • Move detection is optional
    • O(n)
    • 1000 / 50 modifications 4.6ms on Nexus 5X
    DiffUtil

    View full-size slide

  6. ©2018 Wantedly, Inc.
    ListAdapter

    View full-size slide

  7. ©2018 Wantedly, Inc.
    • Added in support library 27.1.0
    • A RecyclerView.Adapter using DiffUtil
    • Just submitList(newItems)
    • Calculates the diff on a background thread
    • Notify diff results on the main thread
    ListAdapter

    View full-size slide

  8. ©2018 Wantedly, Inc.
    Demo
    ListAdapter

    View full-size slide

  9. ©2018 Wantedly, Inc.
    • Should not use with MutableList
    • Does nothing if same instance submitted
    ListAdapter Important point

    View full-size slide

  10. ©2018 Wantedly, Inc.
    Conclusion

    View full-size slide

  11. ©2018 Wantedly, Inc.
    • DiffUtil automates the adapter notification
    • Simplify around the adapter operations
    Conclusion

    View full-size slide

  12. ©2018 Wantedly, Inc.
    https://github.com/kubode/DiffUtil-sample
    Repository

    View full-size slide

  13. ©2018 Wantedly, Inc.
    Thanks

    View full-size slide