retty-tech-cafe-8

836437265cbba12ee1b24bbb359a6c15?s=47 Yuya Kaido
December 09, 2016

 retty-tech-cafe-8

836437265cbba12ee1b24bbb359a6c15?s=128

Yuya Kaido

December 09, 2016
Tweet

Transcript

  1. Kotlin × Data Binding Retty Tech Cafe #8 yuyakaido

  2. ࣗݾ঺հ • ւ౻༏໻ʢ͔͍Ͳ͏Ώ͏΍ʣ • גࣜձࣾΤ΢ϨΧ • ໿1೥ͷΠϯλʔϯΛܦͯɺ2015೥4݄ʹ৽ଔೖࣾ  yuyakaido yuyakaido

  3. None
  4. ໨࣍ • Kotlin͔ΒBindingΫϥεͷࢀর • BindingΫϥε͕ࢀরͰ͖ͳ͍ • BindingAdapter • ΧελϜόΠϯσΟϯά͕ಈ͔ͳ͍ 

  5. BindingΫϥε͕ࢀরͰ͖ͳ͍ • Kotlin͔ΒBindingΫϥεΛࢀর͢Δͱ • ίϯύΠϧॱɿKotlin → Java  Unresolved reference:

    databinding Unresolved reference: ItemArticleBinding Unresolved reference: ItemArticleBinding
  6. ղܾࡦ • generateStubsΛ༗ޮʹ͢Δ • kotlin-kaptΛ࢖͏ 

  7. generateStubsΛ༗ޮʹ͢Δ • Kotlin → Java • Stub → Kotlin →

    Java  kapt { generateStubs = true }
  8. kotlin-kaptΛ࢖͏ • KotlinʹΑΔAnnotation Processing࣮૷ • apply plugin: ‘kotlin-kapt' • ؆୯ͳαϯϓϧ͸ಈ࡞͠·ͨ͠

     The new annotation processing still has known issues and may not be compatible with all annotation processors. You should enable it only if you’ve run into problems with the default kapt annotation processing implementation.
  9. ΧελϜόΠϯσΟϯά͕ಈ͔ͳ͍ • Glide΍PicassoΛ࢖ͬͯImageViewʹURLΛό Πϯυ͢Δ  public class CustomBinder {
 @BindingAdapter("app:imageUrl")


    public static void imageUrl(ImageView imageView, String url) {
 Glide.with(imageView.getContext()).load(url).into(imageView);
 }
 } class CustomBinder {
 companion object {
 @BindingAdapter("app:imageUrl")
 fun imageUrl(imageView: ImageView, url: String) {
 Glide.with(imageView.context).load(url).into(imageView)
 }
 }
 }
  10. ղܾࡦ • JvmStaticΞϊςʔγϣϯΛ෇༩͢Δ • ֦ுؔ਺ͱ࣮ͯ͠૷͢Δ 

  11. JvmStaticΞϊςʔγϣϯΛ෇༩͢Δ  class CustomBinder {
 companion object {
 @JvmStatic
 @BindingAdapter("app:imageUrl")


    fun imageUrl(imageView: ImageView, url: String) {
 Glide.with(imageView.context).load(url).into(imageView)
 }
 }
 } object CustomBinder {
 @JvmStatic
 @BindingAdapter("app:imageUrl")
 fun imageUrl(imageView: ImageView, url: String?) {
 Glide.with(imageView.context).load(url).into(imageView)
 }
 }
  12. ֦ுؔ਺ͱ࣮ͯ͠૷͢Δ  @BindingAdapter("android:imageUrl")
 fun ImageView.imageUrl(url: String?) {
 Glide.with(context).load(url).into(this)
 }

  13. ·ͱΊ • BindingΫϥε͕Kotlin͔ΒࢀরͰ͖ͳ͍ • generateStubsΛ༗ޮʹ͢Δ • kotlin-kaptΛ࢖͏ • ΧελϜόΠϯσΟϯά͕ಈ͔ͳ͍ •

    JvmStaticΞϊςʔγϣϯΛ෇༩͢Δ • ֦ுؔ਺ͱ࣮ͯ͠૷͢Δ 
  14. ࢿྉɾαϯϓϧίʔυ • Kotlin×Data Bindingͷ໰୊఺ͱղܾ๏ • http://qiita.com/yuyakaido/items/ e5acf5f8ac31c4ed8c77 • https://github.com/yuyakaido/Flow-Android 

  15. Thank you :) Credit: NASA Earth Observatory/NOAA NGDC