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

Introducing Smoothie

Lucas Rocha
January 23, 2014

Introducing Smoothie

Smoothie is an open-source library that provides a simple API to load ListView/GridView items asynchronously, off the UI thread. Besides the obvious view recycling handling, Smoothie is gesture-aware and supports powerful features such as off-screen item pre-loading and multi-part items. In this session, you will get overview of Smoothie's features and implementation; and learn how to use it in your apps through a series of practical examples.

Lucas Rocha

January 23, 2014
Tweet

More Decks by Lucas Rocha

Other Decks in Technology

Transcript

  1. Smoothie!

    View Slide

  2. Lucas Rocha
    @lucasratmundo • +LucasRocha

    View Slide

  3. Android and me
    Firefox for Android
    http://bit.ly/firefox-for-android
    Pattrn Wallpapers
    http://bit.ly/pattrn-app
    Smoothie
    http://github.com/lucasr/smoothie
    TwoWayView
    http://github.com/lucasr/twoway-view

    View Slide

  4. AdapterView
    Children provided by an Adapter.
    View recycling support.
    ListView and GridView.

    View Slide

  5. http://bit.ly/listview-perf
    How ListView works

    View Slide

  6. Async in ListView
    Async vs View recycling.
    Trivial to implement.

    View Slide

  7. Non-trivial bits
    Gesture awareness.
    Preloading off-screen items.
    Multi-part items.

    View Slide

  8. Smoothie!
    Easy async item loading for
    ListViews with all these non-trivial
    bits built in.
    Factored out from Pattrn.
    Nice and simple API.
    Not an image-loading library.
    (But can be used to load images off UI thread)
    https://github.com/lucasr/smoothie

    View Slide

  9. How to use it
    Add an AsyncListView to your layout.
    Implement an ItemLoader with
    your app-specific logic for loading
    and displaying items.
    Instantiate an ItemManager with
    your ItemLoader and set it on the
    AsyncListView.
    1
    https://bit.ly/smoothie-intro
    2
    3

    View Slide

  10. AsyncListView
    Encapsulates async logic.
    Behaves exactly like a ListView.
    AsyncGridView is analogous.
    1

    View Slide

  11. ItemLoader

    1. Fetch parameters
    2. Memory load
    3. Async load
    (Off main thread)
    4. Display
    API assumes loaded items are
    cached in memory.
    2

    View Slide

  12. SimpleItemLoader
    2

    View Slide

  13. ItemManager
    Defines the async loading
    behaviour for an AsyncListView.
    ItemManager.Builder sample here
    3

    View Slide

  14. Gesture awareness
    Async loading is disabled while the
    ListView is scrolling with finger up.
    Async loading is only enabled when
    the ListView is either idle or scrolling
    with finger down.
    In-memory items are displayed
    immediately in any ListView state.

    View Slide

  15. Preloading
    Improve perceived performance
    by showing placeholders less
    often.
    Load off-screen items ahead of
    scroll position.

    View Slide

  16. Multi-part items
    Items that require multiple
    async operations to load.
    Sets relative priorities between
    item parts.
    Inherit from ItemLoader instead.
    loadItem() loadItemPart()

    loadItemFromMemory() loadItemPartFromMemory()

    displayItem() displayItemPart()

    https://bit.ly/smoothie-multipart

    View Slide

  17. View Slide

  18. Limitations
    Hard to blend with libraries using
    custom ListViews or GridViews.
    Hard to blend with your existing
    async loading libraries e.g. Volley.
    Preloading logic assumes user is
    scrolling the list down.
    Single type for multi-part items.

    View Slide

  19. Implementation
    Custom ThreadPoolExecutor.
    Dynamic priorities as the user
    scrolls the view.
    Checkpoints to invalidate
    obsolete async operations.

    View Slide

  20. That's all!
    Questions?

    View Slide