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

Modern Java Libraries with Kotlin

Modern Java Libraries with Kotlin

potatotips #40

85cab5fdf09afe3ee78ce3667681915a?s=128

Keisuke Kobayashi

May 24, 2017
Tweet

Transcript

  1. Modern Java Libraries with Kotlin Keisuke Kobayashi / @kobakei potatotips

    #40
  2. About me • Keisuke Kobayashi • GitHub, Qiita: @kobakei •

    Twitter: @kobakei122 • Kyash, Inc
  3. None
  4. ࠓ೔࿩͢͜ͱ • ݪଇJavaϥΠϒϥϦ͸KotlinͰ΋
 େମͦͷ··࢖͑·͢ • Ұ෦ಛผʹରԠ͕ඞཁͳ΋ͷΛ঺հ͠·͢

  5. Dagger2 + Orma

  6. Dagger2 + Orma • kaptͰࣗಈੜ੒͞ΕΔΫϥε͸DaggerͰ provideͰ͖ͳ͍ • ͭ·ΓOrmaDatabase

  7. NG: Ϗϧυ͕௨Βͳ͍ @Module class AppModule(private val context: Context) { @Singleton

    @Provides fun provideOrmaDatabase(context: Context): OrmaDatabase { return OrmaDatabase.builder(context).build() } }
  8. ղܾࡦ • OrmaDatabaseΛϥοϓ͢Δ͚ͩͷΫϥεΛ ࡞ͬͯɺͦΕΛprovide͢Δ

  9. OrmaHolder class OrmaHolder(val context: Context) { val ormaDatabase = OrmaDatabase.builder(context).build()

    }
  10. Dagger Module @Module class AppModule(private val context: Context) { @Singleton

    @Provides fun provideOrmaHolder(context: Context): OrmaHolder { return OrmaHolder(context) } }
  11. Data Binding

  12. Data binding • dependenciesʹkaptͰ௥Ճ android { dataBinding { enabled true

    } } dependencies { kapt 'com.android.databinding:compiler:x.y.z' }
  13. Parceler

  14. Parceler • ParcelableͷϘΠϥʔϓϨʔτΛࣗಈੜ੒͢Δ ϥΠϒϥϦ • data classͰParcelerΛ࢖͍͍ͨ

  15. data class • toString, hasCodeͷ࣮૷ෆཁ data class User ( val

    email: String?, val userName: String?, )
  16. data class with Parceler • ͜Εͩͱಈ͔ͳ͍ʢϓϩύςΟ͸͋Δ͕ϑΟʔϧυ Ͱ͸ͳ͍ͨΊʣ @Parcel data class

    User ( val email: String?, val userName: String?, )
  17. data class with Parceler • ͜ΕͰϓϩύςΟܦ༝ͰಡΈॻ͖ͯ͘͠ΕΔ @Parcel(Parcel.Serialization.BEAN) data class User

    @ParcelConstructor constructor( val email: String?, val userName: String?, )
  18. ͓·͚: αϯϓϧॻ͖·ͨ͠ • https://github.com/kobakei/Android-Kotlin- Example

  19. Thanks!