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

Taehwan-IO18_Extended_in_Suwon.pdf

TaeHwan
June 25, 2018

 Taehwan-IO18_Extended_in_Suwon.pdf

GDG Google I/O Extended in Suwon.

TaeHwan

June 25, 2018
Tweet

More Decks by TaeHwan

Other Decks in Education

Transcript

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

    ѐߊ ! Է ݆਷ ѐߊ੗о غ੗ ࠶۽Ӓ ਍৔
 http://thdev.tech / http://thdev.net ! Udemy ௏ౣܽ ъ੄
  2. Android Jetpack Jetpack Android ѐߊী ೙ਃೠ ੹߈੸ੋ ۄ੉࠳۞ܻ ݽ਺ ੉੗

    о੉٘ - Foundation, Architecture, Behavior, UI Jetpack : https://developer.android.com/jetpack/
  3. Android Jetpack AndroidX ӝઓ ۄ੉࠳۞ܻٜ੄ Package name ా೤ Jetpackীࢲח androidx.*

    ಁః૑ܳ ࢎਊ Compile version 28ࠗఠ ࢎਊ оמ AndroidX Release Note AndroidX convert ੿ܻ Ӗ - thdev Google Jetpack Sample - Android Sunflower (alpha)
  4. 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' }
  5. 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 } }
  6. Android Jetpack Jetpack - ViewModel.kt class MainViewModel : ViewModel() {

    // TODO: Implement the ViewModel override fun onCleared() { super.onCleared() // todo release } }
  7. Kotlin Kotlin ೟णೞח ߑߨ? Reference ଵҊೞӝ : https://kotlinlang.org/docs/reference/ ଼ Kotlin

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

    ೞӝ(بҳীࢲ ઁҕೞח ஶߡఠ/Kotlin ࢎ੉౟ীࢲ ઁҕೞח ஶߡఠ ഝਊ) - Java۽ ੘ࢿೞҊ, ࠂࢎ ࠢৈ֍ӝܳ ా೧ ஶߡఠೞҊ, ઑӘঀ ࣻ੿೧ ࠄ׮ - Kotlin ӝࠄ ޙߨ(Lambda, fun, class ੿੄ ١) ࣼ૑ റ ೞաঀ ੸ਊ೧ࠄ׮ Repeat. ੊ࣼ೧૓ ݅ఀ ௏٘ ઴੉ח ߑߨਸ णٙೞҊ, Extension ࢎਊ ١ਸ ੸ӓ ഝਊ೧ࠄ׮
  9. 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
  10. 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
  11. 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
  12. 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)
  13. Kotlin Android KTX ઱ਃ௏٘ > kotlin sharedPreferences.edit() .putBoolean("key", value) .apply()

    > Android KTX sharedPreferences.edit { putBoolean("key", value) }
  14. 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() } }
  15. Kotlin Android KTX ௏٘ ୷ড੉ જ਷ Ѫ݅਷ ইפ׮ Kotlinਸ ೞݶ

    ௏٘ ୷ডਸ ݆੉ ೠ׮ Ӓѱ ޖઑѤ જ਷ Ѫ਷ ইפ׮
  16. 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 }
  17. 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() } }
  18. 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() } }
  19. 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() } }
  20. 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() } }
  21. 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
  22. 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() } ?: ""
  23. 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)
  24. 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۽ ୡӝച