Taehwan-IO18_Extended_in_Suwon.pdf

7589a5a8fec022e8af4e46525150a291?s=47 TaeHwan
June 25, 2018

 Taehwan-IO18_Extended_in_Suwon.pdf

GDG Google I/O Extended in Suwon.

7589a5a8fec022e8af4e46525150a291?s=128

TaeHwan

June 25, 2018
Tweet

Transcript

  1. Kotlin / Android KTX Android Jetpack Tae-hwan

  2. ࣗѐ ! GDG Seoul ਍৔૓ ! RGP Korea ਃӝਃ উ٘۽੉٘

    ѐߊ ! Է ݆਷ ѐߊ੗о غ੗ ࠶۽Ӓ ਍৔
 http://thdev.tech / http://thdev.net ! Udemy ௏ౣܽ ъ੄
  3. Android Jetpack Foundation, Architecture, Behavior, UI

  4. Android Jetpack Jetpack Android ѐߊী ೙ਃೠ ੹߈੸ੋ ۄ੉࠳۞ܻ ݽ਺ ੉੗

    о੉٘ - Foundation, Architecture, Behavior, UI Jetpack : https://developer.android.com/jetpack/
  5. Android Jetpack Jetpack

  6. Android Jetpack AndroidX ӝઓ ۄ੉࠳۞ܻٜ੄ Package name ా೤ Jetpackীࢲח androidx.*

    ಁః૑ܳ ࢎਊ Compile version 28ࠗఠ ࢎਊ оמ AndroidX Release Note AndroidX convert ੿ܻ Ӗ - thdev Google Jetpack Sample - Android Sunflower (alpha)
  7. New Project ࢤࢿ Target API 28۽ ࢸ੿ೡ ҃਋

  8. Android Jetpack ViewModel - AS 3.2 Previewীࢲ ࢤࢿೞӝ

  9. Android Jetpack ViewModel - AS 3.2 Previewীࢲ ࢤࢿೞӝ

  10. Android Jetpack ViewModel - ViewModel ੸ਊ package ҳઑ

  11. Android Jetpack New androidx package compileSdkVersion Android 28 ੉࢚ ࢎਊ

    оמ dependencies { implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.0.0-alpha1' implementation 'androidx.constraintlayout:constraintlayout:1.1.0' implementation ‘androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.0-alpha3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3' }
  12. Android Jetpack Jetpack - MainFragment.kt class MainFragment : Fragment() {

    companion object { fun newInstance() = MainFragment() } private lateinit var viewModel: MainViewModel override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java) // TODO: Use the ViewModel } }
  13. Android Jetpack Jetpack - ViewModel.kt class MainViewModel : ViewModel() {

    // TODO: Implement the ViewModel override fun onCleared() { super.onCleared() // todo release } }
  14. Kotlin Kotlin ೟णೞח ߑߨ

  15. Kotlin Kotlin ೟णೞח ߑߨ? Reference ଵҊೞӝ : https://kotlinlang.org/docs/reference/ ଼ Kotlin

    in Action - ೠӖ/৔ޙ ழפ੄ ௏ౣܽ: ରࣁ؀ উ٘۽੉٘ ѐߊ੗ܳ ਤೠ ৡۄੋ ъ੄ Kotlin Bootcamp for Programmers - Udacity
 ઁ ъ੄ ௏ౣܽ द੘ೞӝ - Udemy
  16. Kotlin Kotlin ೟णೞח ߑߨ? - Java ੘ࢿ - Kotlin ஶߡ౴

    ೞӝ(بҳীࢲ ઁҕೞח ஶߡఠ/Kotlin ࢎ੉౟ীࢲ ઁҕೞח ஶߡఠ ഝਊ) - Java۽ ੘ࢿೞҊ, ࠂࢎ ࠢৈ֍ӝܳ ా೧ ஶߡఠೞҊ, ઑӘঀ ࣻ੿೧ ࠄ׮ - Kotlin ӝࠄ ޙߨ(Lambda, fun, class ੿੄ ١) ࣼ૑ റ ೞաঀ ੸ਊ೧ࠄ׮ Repeat. ੊ࣼ೧૓ ݅ఀ ௏٘ ઴੉ח ߑߨਸ णٙೞҊ, Extension ࢎਊ ١ਸ ੸ӓ ഝਊ೧ࠄ׮
  17. Kotlin ഥࢎী ੸ਊ਷? ѐੋ ࠶۽Ӓ ࣗѐ https://thdev.tech/kotlin/android/2018/01/02/Kotlin-Learning-and-Introduction.html ഥࢎ ࠶۽Ӓ ࣗѐ

    https://rgpkorea.github.io/posts/yogiyo-kotlin/
  18. Kotlin Android KTX ঌইࠁӝ ੹ী

  19. Kotlin Android KTX ঌইࠁӝ ੹ী - ҳࢿ Lambdas ಴അ Kotlin

    Extension Higher-Order Function
  20. Kotlin Lambdas Button button = findViewById(R.id.btn); button.setOnClickListener(new View.OnClickListener() { @Override

    public void onClick(View view) { // TODO } });
  21. Kotlin Lambdas Button button = findViewById(R.id.btn); button.setOnClickListener(new View.OnClickListener() { @Override

    public void onClick(View view) { // TODO } }); // kotlin val button = findViewById<Button>(R.id.btn) button.setOnClickListener { // TODO } ଵҊ : https://thdev.tech/kotlin/2018/03/17/Kotlin-Lambdas.html
  22. Kotlin Kotlin Extension Extension਷ ਗې ௿ېझীࢲ ઁҕೞח ӝמੋ Ѫ୊ۢ ഛ੢

    ೣࣻܳ ٜ݅ ࣻ ੓׮.
  23. Kotlin Kotlin Extension val name: String? = null if (name.isNullOrEmpty())

    { // ... } val name ߸ࣻо null ژח “”ੋ ҃਋ܳ ഛੋೞৈ ߹ب੄ ୊ܻܳ ೠ׮. ೞ૑݅ String class/CharSequence class উীח isNullOrEmpty() ݫࣗ٘ח ઓ੤ೞ૑ ঋח׮. @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract { returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } ଵҊ : https://kotlinlang.org/docs/reference/extensions.html
  24. Kotlin Higher-Order Function Higher-Order Functions਷ ೣࣻܳ ߸ࣻ۽ ֈѹ઱Ѣա, ੉ܳ ߈ജೞח

    Ѫਸ ݈೤פ׮.
  25. Kotlin Higher-Order Function Higher-Order Functions਷ ೣࣻܳ ߸ࣻ۽ ֈѹ઱Ѣա, ੉ܳ ߈ജೞח

    Ѫਸ ݈೤פ׮.
 fun print(body: () -> String) { println(body()) } print { “੉Ѣ ୹۱೧઻” } >> body: () -> T body : ߸ࣻ ੉ܴ () -> String : () ౵ۄݫఠо হח ݫࢲ٘ܳ ੿੄ೞ৓Ҋ, -> String return ఋੑਸ ੿੄೤פ׮. ଵҊ : https://thdev.tech/kotlin/2017/10/02/Kotlin-Higher-Order-Function.html
  26. Kotlin Android KTX

  27. Kotlin Android KTX What is Android KTX? Jetpack family Android

    - Kotlin ࢎਊ ಞ੄ܳ ذח extensions AndroidX ಁః૑۽ ઁҕ
 implementation ‘androidx.core:core-ktx:1.0.0-alpha1’ Android Open Source Project Apache License, Version 2.0 API : https://github.com/android/android-ktx API reference documentation : https://android.github.io/android-ktx/core-ktx/ Android Jetpack: sweetening Kotlin development with Android KTX (Google I/O '18)
  28. Kotlin Android KTX Modules androidx.core:core-ktx androidx.fragment:fragment-ktx androidx.sqlite:sqlite-ktx androidx.lifecycle:lifecycle-viewmodel-ktx android.arch.navigation:navigation-common-ktx android.arch.work:work-runtime-ktx

    More modules : https://developer.android.com/kotlin/ktx
  29. Kotlin Android KTX ઱ਃ௏٘ > kotlin sharedPreferences.edit() .putBoolean("key", value) .apply()

    > Android KTX sharedPreferences.edit { putBoolean("key", value) }
  30. Kotlin Android KTX ઱ਃ௏٘ > Android KTX sharedPreferences.edit { putBoolean("key",

    value) } > ղࠗ ௏٘ @SuppressLint("ApplySharedPref") inline fun SharedPreferences.edit( commit: Boolean = false, action: SharedPreferences.Editor.() -> Unit ) { val editor = edit() action(editor) if (commit) { editor.commit() } else { editor.apply() } }
  31. Kotlin Android KTX ௏٘ ୷ড੉ જ਷ Ѫ݅਷ ইפ׮ Kotlinਸ ೞݶ

    ௏٘ ୷ডਸ ݆੉ ೠ׮ Ӓѱ ޖઑѤ જ਷ Ѫ਷ ইפ׮
  32. Kotlin Android KTX ௏٘ ୷ড ৘ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)

    { // Something } ਤ ௏٘ܳ ઴੉۰ ݅ٚ ഛ੢ ೣࣻ inline fun onApi(level: Int, body: () -> Unit) { if (Build.VERSION.SDK_INT >= level) { body() } } onApi(Build.VERSION_CODES.P) { // Something }
  33. Kotlin Android KTX ௏٘ ୷ড ৘ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)

    { // Something } else { // Something } ਤ ௏٘ܳ ઴੉۰ ݅ٚ ഛ੢ ೣࣻ inline fun onApi(level: Int, body: () -> Unit, bodyElse: () -> Unit) { if (Build.VERSION.SDK_INT >= level) { body() } else { bodyElse() } }
  34. Kotlin Android KTX ௏٘ ୷ড ৘ onApi(Build.VERSION_CODES.P, { // if

    Something }) { // else Something } ਤ ௏٘ܳ ઴੉۰ ݅ٚ ഛ੢ ೣࣻ inline fun onApi(level: Int, body: () -> Unit, bodyElse: () -> Unit) { if (Build.VERSION.SDK_INT >= level) { body() } else { bodyElse() } }
  35. Kotlin Android KTX ௏٘ ୷ড ৘ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)

    { // Something } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // Something } else { // Something } ਤ ௏٘ܳ ઴੉۰ ݅ٚ ഛ੢ ೣࣻ inline fun onApi(level: Int, body: () -> Unit, levelTwo: Int, bodyTwo: () -> Unit, bodyElse: () -> Unit) { if (Build.VERSION.SDK_INT >= level) { body() } else if (Build.VERSION.SDK_INT >= levelTwo) { bodyTwo() } else { bodyElse() } }
  36. Kotlin Android KTX ௏٘ ୷ড ৘ onApi(Build.VERSION_CODES.P, { // if

    Something }, Build.VERSION_CODES.KITKAT, { // else if Something }) { // else Something } ਤ ௏٘ܳ ઴੉۰ ݅ٚ ഛ੢ ೣࣻ inline fun onApi(level: Int, body: () -> Unit, levelTwo: Int, bodyTwo: () -> Unit, bodyElse: () -> Unit) { if (Build.VERSION.SDK_INT >= level) { body() } else if (Build.VERSION.SDK_INT >= levelTwo) { bodyTwo() } else { bodyElse() } }
  37. Kotlin Android KTX KEEP-110 KEEP > Kotlin Evolution Enhancement Process

    KEEP-110 ೐۽ં౟ܳ ా೧ Javaীࢲب Kotlin੄ ಞ੄ࢿਸ ֫੉੗ @ExtensionFunction/@ExtensionProperty - Kotlin੄ ഛ੢ ೣࣻܳ ઁҕ @DefaultValue - Kotlin ٣ಫ౟ ౵ۄݫఠ ੿੄ ӝמ ઁҕ @KtName - function੄ ౵ۄݫఠী Kotlinীࢲ ࠗܳ ੉ܴਸ ߹ب ૑੿ оמ > ই૒ ֤੄઺ੋ ઱ઁ۽ য֢ప੉࣌ ੉ܴ਷ ߸҃ؼ ࣻ ੓਺ GitHub : https://github.com/Kotlin/KEEP
  38. KEEP-110 @ExtensionFunction/@ExtensionProperty @ExtensionFunction public static String getNonNullName(@Nullable String name) {

    return name != null ? name : ""; } Kotlin ഐ୹ val name: String? = null println(name.getNonNullName()) > Kotlinীࢲח ইې৬ э੉ ੘ࢿ fun String?.getNonNullName() = this?.takeIf { it.isNotEmpty() } ?: ""
  39. KEEP-110 @KtName - ౵ۄݫఠ ੉ܴ ૑੿ public static void setPadding(

    @KtName("left") int left, @KtName("top") int top, @KtName("right") int right, @KtName("bottom") int bottom) { /* todo... */ } Kotlinীࢲ ࠗܳٸ setPadding(left = 0, top = 15, right = 0, bottom = 0) > ࣽࢲо ߸҃غযب ޙઁо হ׮ setPadding(right = 0, bottom = 0, left = 0, top = 15)
  40. KEEP-110 @DefaultValue - ӝࠄч ૑੿ public static void setPadding( @KtName("left")

    @DefaultValue("paddingLeft") int left, @KtName("top") @DefaultValue("paddingTop") int top, @KtName("right") @DefaultValue("paddingRight") int right, @KtName("bottom") @DefaultValue("paddingBottom") int bottom) { /* todo... */ } Kotlinীࢲ ࠗܳٸ setPadding(top = 15) left, right, bottom = defaultValue۽ ୡӝച
  41. хࢎ೤פ׮ http://thdev.tech taehwan@thdev.net GDG Seoul ӂకജ ૕ޙೞप ѱ թਵ࣑׮ݶ,