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

Android KTX: 25 dicas em 25 minutos!

Android KTX: 25 dicas em 25 minutos!

Slides do um talk realizado na trilha Android da The Developer Conference São Paulo, que aconteceu em São Paulo, no dia 18 de julho de 2018.

O talk foi sobre uma breve introdução ao Android KTX, a estrutura do projeto, alguns exemplos rápidos e como utilizá-la no seu projeto!

Link: http://www.thedevelopersconference.com.br/tdc/2018/saopaulo/trilha-android

Walmyr Carvalho

July 18, 2018
Tweet

More Decks by Walmyr Carvalho

Other Decks in Technology

Transcript

  1. Walmyr Carvalho
    #TheDevConf
    #trilhaAndroid
    Android KTX:
    25 dicas em 25 minutos!
    +

    View full-size slide

  2. Walmyr Carvalho
    @walmyrcarvalho

    View full-size slide

  3. Fato: Kotlin veio pra ficar! —

    View full-size slide

  4. Outro fato:
    Todo profissional Android quer boas ferramentas para se trabalhar.

    View full-size slide

  5. Módulo (artefato) Versão Pacotes
    androidx.core:core-ktx 1.0.0-alpha1 Todos os pacotes core abaixo
    androidx.fragment:fragment-ktx 1.0.0-alpha1 androidx.fragment.app
    androidx.palette:palette-ktx 1.0.0-alpha1 androidx.palette.graphics
    androidx.sqlite:sqlite-ktx 1.0.0-alpha1 androidx.sqlite.db
    androidx.collection:collection-ktx 1.0.0-alpha1 androidx.collection
    androidx.lifecycle:lifecycle-viewmodel-ktx 2.0.0-alpha1 androidx.lifecycle
    androidx.lifecycle:lifecycle-reactivestreams-ktx 2.0.0-alpha1 androidx.lifecycle
    android.arch.navigation:navigation-common-ktx 1.0.0-alpha01 androidx.navigation
    android.arch.navigation:navigation-fragment-ktx 1.0.0-alpha01 androidx.navigation.fragment
    android.arch.navigation:navigation-runtime-ktx 1.0.0-alpha01 androidx.navigation
    android.arch.navigation:navigation-testing-ktx 1.0.0-alpha01 androidx.navigation.testing
    android.arch.navigation:navigation-ui-ktx 1.0.0-alpha01 androidx.navigation.ui
    android.arch.work:work-runtime-ktx 1.0.0-alpha01 androidx.work.ktx
    Fonte: developer.android.com/kotlin/ktx

    View full-size slide

  6. repositories {
    google()
    }
    build.gradle

    View full-size slide

  7. dependencies {
    implementation 'androidx.core:core-ktx:1.0.0-alpha1'
    }
    app/build.gradle

    View full-size slide

  8. // Kotlin
    sharedPreferences.edit()
    .putBoolean("key", value)
    .apply()
    // Kotlin + Android KTX
    sharedPreferences.edit {
    putBoolean("key", value)
    }

    View full-size slide

  9. // Kotlin
    db.beginTransaction()
    try {
    // insira os dados
    db.setTransactionSuccessful()
    } finally {
    db.endTransaction()
    }
    // Kotlin + Android KTX
    db.transaction {
    // insira os dados
    }

    View full-size slide

  10. // Kotlin
    view.viewTreeObserver.addOnPreDrawListener(
    object : ViewTreeObserver.OnPreDrawListener {
    override fun onPreDraw(): Boolean {
    viewTreeObserver.removeOnPreDrawListener(this)
    actionToBeTriggered()
    return true
    }
    }
    )
    // Kotlin + Android KTX
    view.doOnPreDraw {
    actionToBeTriggered()
    }

    View full-size slide

  11. context.withStyledAttributes(set = someAttributeSet,
    attrs = attributes,
    defStyleAttr = ...,
    defStyleRes = ...) {
    // do your rolê
    }
    context.withStyledAttributes(set = someAttributeSet, attrs =
    attributes) {
    // do your rolê
    }

    View full-size slide

  12. Demonstração

    View full-size slide

  13. Android KTX - GitHub
    github.com/android/android-ktx

    View full-size slide

  14. Dever de:
    Use o Android KTX como referência e crie as suas próprias extensions!

    View full-size slide

  15. Links úteis

    View full-size slide

  16. Android Sunflower (alpha)
    github.com/googlesamples/android-sunflower

    View full-size slide

  17. Android KTX - GitHub
    github.com/android/android-ktx

    View full-size slide

  18. Kotlin & Android KTX - Jake Wharton (Google I/O ’18)
    youtu.be/st1XVfkDWqk

    View full-size slide

  19. Android Jetpack
    developer.android.com/jetpack/

    View full-size slide

  20. Kotlin - Site Oficial
    kotlinlang.org

    View full-size slide

  21. Kotlin Meetup SP
    meetup.com/kotlin-meetup-sp

    View full-size slide

  22. Android Dev BR
    slack.androiddevbr.org

    View full-size slide

  23. Muito obrigado! ♥

    View full-size slide

  24. Créditos de imagem
    NeONBRAND (Unsplash)
    bit.ly/2zR1rw2

    View full-size slide