Slide 1

Slide 1 text

Modern Java Libraries with Kotlin Keisuke Kobayashi / @kobakei potatotips #40

Slide 2

Slide 2 text

About me • Keisuke Kobayashi • GitHub, Qiita: @kobakei • Twitter: @kobakei122 • Kyash, Inc

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

ࠓ೔࿩͢͜ͱ • ݪଇJavaϥΠϒϥϦ͸KotlinͰ΋
 େମͦͷ··࢖͑·͢ • Ұ෦ಛผʹରԠ͕ඞཁͳ΋ͷΛ঺հ͠·͢

Slide 5

Slide 5 text

Dagger2 + Orma

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

NG: Ϗϧυ͕௨Βͳ͍ @Module class AppModule(private val context: Context) { @Singleton @Provides fun provideOrmaDatabase(context: Context): OrmaDatabase { return OrmaDatabase.builder(context).build() } }

Slide 8

Slide 8 text

ղܾࡦ • OrmaDatabaseΛϥοϓ͢Δ͚ͩͷΫϥεΛ ࡞ͬͯɺͦΕΛprovide͢Δ

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Dagger Module @Module class AppModule(private val context: Context) { @Singleton @Provides fun provideOrmaHolder(context: Context): OrmaHolder { return OrmaHolder(context) } }

Slide 11

Slide 11 text

Data Binding

Slide 12

Slide 12 text

Data binding • dependenciesʹkaptͰ௥Ճ android { dataBinding { enabled true } } dependencies { kapt 'com.android.databinding:compiler:x.y.z' }

Slide 13

Slide 13 text

Parceler

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

data class • toString, hasCodeͷ࣮૷ෆཁ data class User ( val email: String?, val userName: String?, )

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

͓·͚: αϯϓϧॻ͖·ͨ͠ • https://github.com/kobakei/Android-Kotlin- Example

Slide 19

Slide 19 text

Thanks!