$30 off During Our Annual Pro Sale. View Details »

Exploring View-Base Application with Conductor

Esa Firman
December 08, 2017

Exploring View-Base Application with Conductor

Esa Firman

December 08, 2017
Tweet

More Decks by Esa Firman

Other Decks in Programming

Transcript

  1. Exploring View-Based
    Application with Conductor
    Esa Firman

    View Slide

  2. What’s the worst thing that could happen
    when you’re using Android Activity as your
    page representation?

    View Slide

  3. ¯\_(ツ)_/¯
    #MintaPutus

    View Slide

  4. Caused by:
    android.content.ActivityNotFoundException: Unable to
    find explicit activity class {...}; have you declared this
    activity in your AndroidManifest.xml?

    View Slide

  5. View Slide

  6. Task and Back Stack
    Intent intent = new Intent(LoginActivity.this, MainMenuActivity.class);
    intent.addFlags(...) // FLAG_ACTIVITY_CLEAR_TOP, NEW_TASK, etc ...
    startActivity(intent);
    finish();
    Or use `launchMode` in AndroidManifest.xml

    View Slide

  7. Task and Back Stack
    TaskStackBuilder ->
    https://developer.android.com/reference/android/support/v4/app/TaskStackBuil
    der.html

    View Slide

  8. What about Fragment?
    ● Introduce more complex lifecycle
    ● Never use it since last year ( expect for Google Map )
    ● ¯\_(ツ)_/¯

    View Slide

  9. What about Fragment?
    IllegalStateException: Can not perform this action after
    onSaveInstanceState

    View Slide

  10. What about Fragment?
    Advocation Against Android Fragments - Piwai
    https://medium.com/square-corner-blog/advocating-against-android-fragments-81fd0b462c97

    View Slide

  11. What’s the option?
    ● Flow + Custom / Compound View
    ● Scoop
    ● Conductor

    View Slide

  12. Conductor
    A small, yet full-featured framework that allows building View-based Android applications.
    Conductor provides a light-weight wrapper around standard Android Views that does just about
    everything you'd want

    View Slide

  13. View Slide

  14. #SimpleTapiPasten

    View Slide

  15. Components
    ● Controller
    ● Router
    ● ControllerChangeHandler
    ● ControllerTransaction

    View Slide

  16. Controller
    The Controller is the View wrapper that will give you all of your lifecycle management features.
    Think of it as a lighter-weight and more predictable Fragment alternative with an easier to
    manage lifecycle.
    TL;DR this is your Fragment

    View Slide

  17. Controller

    View Slide

  18. Router
    A Router implements navigation and backstack handling for Controllers. Router objects are
    attached to Activity/containing ViewGroup pairs. Routers do not directly render or push Views to
    the container ViewGroup, but instead defer this responsibility to the ControllerChangeHandler
    specified in a given transaction.
    TL;DR this is your FragmentManager

    View Slide

  19. Router

    View Slide

  20. ControllerChangeHandlers
    ControllerChangeHandlers are responsible for swapping the View for one Controller to the View
    of another. They can be useful for performing animations and transitions between Controllers.
    Several default ControllerChangeHandlers are included.

    View Slide

  21. ControllerTransaction
    Transactions are used to define data about adding Controllers. RouterControllerTransactions
    are used to push a Controller to a Router with specified ControllerChangeHandlers, while
    ChildControllerTransactions are used to add child Controllers.
    TL;DR this is your FragmentTransaction

    View Slide

  22. ControllerTransaction

    View Slide

  23. View Slide

  24. View Slide

  25. DEMO TIME!

    View Slide

  26. View Slide

  27. #CodeRelationshipGoal

    View Slide

  28. Bonus ~
    Conductor
    Extra
    #Kemevvahan

    View Slide

  29. Bonus ~
    Android
    Conductor
    Generator
    #SayaSukaKemevvahan

    View Slide

  30. Links
    ● https://github.com/bluelinelabs/Conductor
    ● https://github.com/esafirm/conductor-extra
    ● https://github.com/esafirm/generator-android-conductor
    ● https://github.com/esafirm/android-conductor-boilerplate
    ● https://github.com/esafirm/android-playground

    View Slide

  31. Thank You!
    Esa Firman
    Github: https://github.com/esafirm
    Twitter: https://twitter.com/esafirm
    Telegram: @esafirm
    Tinder: Belum buat
    Check out my portfolio -> bit.ly/re-portfolio

    View Slide