Slide 1

Slide 1 text

(6*ΞϓϦέʔγϣϯͷߏ଄ͱઃܭ

Slide 2

Slide 2 text

(6*ΞϓϦέʔγϣϯͷߏ଄ͱઃܭ w εϚʔτϑΥϯʢJ04"OESPJEʣ w σεΫτοϓ w 8FCʢ3FBDUʣ

Slide 3

Slide 3 text

ΞϓϦέʔγϣϯͷઃܭ J04 $PDPBUPVDI "QQ -JCSBSJFT "OESPJE BOESPJE "QQ -JCSBSJFT 8FC %0. "QQ -JCSBSJFT ʜ ʜ "QQ -JCSBSJFT ͜͜

Slide 4

Slide 4 text

εςʔτϑϧ w (6*ΞϓϦέʔγϣϯͷຊ࣭తͳ೉͠͞ w ঢ়ଶΛͲ͏΍ͬͯѻ͏ͷ͔

Slide 5

Slide 5 text

w 0CTFSWFSύλʔϯ w ΦϒδΣΫτͷੜ੒ɾ؅ཧ w ඇಉظॲཧͷந৅Խ

Slide 6

Slide 6 text

"OESPJEBQQ ,PUMJO 3Y+BWB %BHHFS %BUB#JOEJOH "SDIJUFDUVSF$PNQPOFOUT

Slide 7

Slide 7 text

0CTFSWFSύλʔϯ

Slide 8

Slide 8 text

0CTFSWFSύλʔϯ w (P'ͷͷσβΠϯύλʔϯʹ΋਺͑ΒΕΔ w ঢ়ଶΛ؂ࢹͰ͖Δ w Ϟσϧͷঢ়ଶΛ6*ʹ൓өͤ͞Δ
 ˠ6*͸Ϟσϧͷঢ়ଶͷࣸ૾

Slide 9

Slide 9 text

୯७ͳ0CTFSWFSύλʔϯ w +BWB#FBOT w ,FZ7BMVF0CTFSWBUJPO J04 w 3FEVYʹ͓͚Δ4UPSFͷTVCTDSJCF 8FC

Slide 10

Slide 10 text

όΠϯσΟϯά w %BUB#JOEJOH "OESPJE w $PDPB#JOEJOHT J04 w 3FBDU 8FC

Slide 11

Slide 11 text

%BUB#JOEJOH ...

Slide 12

Slide 12 text

%BUB#JOEJOH class EntryViewHolder(private val binding: EntryItemBinding): RecyclerView.ViewHolder(binding.root) { companion object { fun create(parent: ViewGroup) = EntryViewHolder( EntryItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) ) } fun bindTo(entry: Entry?) { binding.entry = entry } }

Slide 13

Slide 13 text

σʔλϕʔε w 3PPN "OESPJE w 3FBMN w $PSF%BUB J04

Slide 14

Slide 14 text

3PPN @Entity(tableName = "entry", indices = arrayOf( Index(value = "date") )) data class Entry( @PrimaryKey(autoGenerate = true) val id: Int = 0, val title: String, val body: String, val date: Date )

Slide 15

Slide 15 text

3PPN @Dao interface EntryDao { @Insert fun insertEntry(entry: Entry) @Update fun updateEntry(entry: Entry) @Delete fun deleteEntry(entry: Entry) @Query("SELECT * FROM entry ORDER BY date DESC") fun entriesByDate(): Flowable> // RxJava 2 }

Slide 16

Slide 16 text

3PPN @Dao interface EntryDao { @Insert fun insertEntry(entry: Entry) @Update fun updateEntry(entry: Entry) @Delete fun deleteEntry(entry: Entry) @Query("SELECT * FROM entry ORDER BY date DESC") fun entriesByDate(): LiveData> // LiveData }

Slide 17

Slide 17 text

3PPN @Dao interface EntryDao { @Insert fun insertEntry(entry: Entry) @Update fun updateEntry(entry: Entry) @Delete fun deleteEntry(entry: Entry) @Query("SELECT * FROM entry ORDER BY date DESC") fun entriesByDate(): LivePagedListProvider // Paging Library }

Slide 18

Slide 18 text

3PPN class EntriesViewModel @Inject constructor(entryDao: EntryDao): ViewModel() { val entries: LiveData> = entryDao.entriesByDate().create(0, 50) } class EntriesAdapter: PagedListAdapter(EntryDiffCallback()) { override fun onBindViewHolder(holder: EntryViewHolder?, position: Int) { val entry = getItem(position) holder?.bindTo(entry) } ... } val entriesAdapter = EntriesAdapter() viewModel.entries.observe(this, Observer { list -> entriesAdapter.setList(list) }) recyclerView.adapter = entriesAdapter

Slide 19

Slide 19 text

3FBDUJWF1SPHSBNNJOH w 3Y+BWB "OESPJE w -JWF%BUB "OESPJE w 3Y4XJGU J04 w 3FBDUJWF$PDPB J04 w 3Y+4 8FC

Slide 20

Slide 20 text

3Y+BWB fun createEntry(title: String, body: String) = Completable.create { emitter -> val entry = Entry(title = title, body = body, date = Date()) // Slow entryDao.insertEntry(entry) emitter.onComplete() }

Slide 21

Slide 21 text

ΦϒδΣΫτͷੜ੒ɾ؅ཧ

Slide 22

Slide 22 text

ΦϒδΣΫτͷੜ੒ɾ؅ཧ w ϝϞϦ্ͷΦϒδΣΫτͱ͍͏ঢ়ଶʹ͍ͭͯ w ΦϒδΣΫτΛͲ͏؅ཧ͢Δ͔ w ΦϒδΣΫτ΁ͷࢀরΛͲ͏औಘ͢Δ͔ w ը໘ؒͰͷ৘ใͷ΍ΓऔΓ

Slide 23

Slide 23 text

4JOHMFUPOύλʔϯ w 4JOHMFUPO w άϩʔόϧม਺ w 3FEVYͷ4UPSF 8FC

Slide 24

Slide 24 text

%FQFOEFODZ*OKFDUJPO w %BHHFS "OESPJE w 3FBDU3FEVYͷDPOOFDU 8FC

Slide 25

Slide 25 text

%BHHFS w %*$POUBJOFSϑϨʔϜϫʔΫ w ΦϒδΣΫτΛఏڙ͢Δ.PEVMFͱ
 ͦΕΛอ࣋͢Δ$PNQPOFOU w "OESPJE޲͚ͷػೳ͕ॆ࣮

Slide 26

Slide 26 text

%BHHFS class App: Application(), HasActivityInjector { @Inject lateinit var activityInjector: DispatchingAndroidInjector private fun applicationInjector() = DaggerAppComponent.builder() .app(this) .build() override fun onCreate() { super.onCreate() applicationInjector().inject(this) } override fun activityInjector() = activityInjector }

Slide 27

Slide 27 text

%BHHFS @Singleton @Component(modules = arrayOf( AndroidSupportInjectionModule::class, AppModule::class, DatabaseModule::class, ActivityBuilder::class )) interface AppComponent { @Component.Builder interface Builder { @BindsInstance fun app(app: App): Builder fun build(): AppComponent } fun inject(app: App) }

Slide 28

Slide 28 text

%BHHFS @Module abstract class AppModule { @Binds abstract fun bindsContext(app: App): Context } @Module abstract class ActivityBuilder { @ContributesAndroidInjector abstract fun contributesMainActivity(): MainActivity } @Module object DatabaseModule { @JvmStatic @Singleton @Provides fun providesAppDatabase(context: Context): Database = Room.databaseBuilder(context, Database::class.java, "diary_db").build() @JvmStatic @Provides fun providesEntryDao(database: Database) = database.entryDao() }

Slide 29

Slide 29 text

%BHHFS class MainActivity : AppCompatActivity() { @Inject lateinit var entryDao: EntryDao ... override fun onCreate(savedInstanceState: Bundle?) { AndroidInjection.inject(this) super.onCreate(savedInstanceState) ... } ... }

Slide 30

Slide 30 text

ͦͷଞ w "SDIJUFDUVSF$PNQPOFOUTͷ7JFX.PEFM "OESPJE w $PSF%BUB J04

Slide 31

Slide 31 text

ඇಉظॲཧͷந৅Խ

Slide 32

Slide 32 text

ඇಉظॲཧͷந৅Խ w ඇಉظతͳॲཧ͸ͦΕࣗମ͕ঢ়ଶͱݴ͑Δ w ॲཧதͳͷ͔Ͳ͏͔ w ਖ਼ৗʹऴྃͨ͠ͷ͔ࣦഊͨ͠ͷ͔ w ϝΠϯεϨουΛࢭΊΒΕͳ͍

Slide 33

Slide 33 text

ݴޠػೳͷར༻ w ίʔϧόοΫ w ؔ਺ϙΠϯλ w Ϋϩʔδϟ w HFOFSBUPS w BTZOD BXBJU

Slide 34

Slide 34 text

ந৅දݱ w ΩϡʔΠϯά w 5ISFBE1PPM&YFDVUPS +BWB w 0QFSBUJPO2VFVF J04 w 1SPNJTF

Slide 35

Slide 35 text

3FBDUJWF1SPHSBNNJOH w 3Y+BWB "OESPJE w 3Y4XJGU J04 w 3FBDUJWF$PDPB J04 w 3Y+4 8FC

Slide 36

Slide 36 text

3Y+BWB val compositeDisposable = CompositeDisposable() fun createEntry(title: String, body: String) = Completable.create { emitter -> val entry = Entry(title = title, body = body, date = Date()) entryDao.insertEntry(entry) emitter.onComplete() } fun create() { val disposable = createEntry( "ࠓ೔ͷ೔ه", "ࠓ೔ͷ൩͝൧͸ϋϯόʔάͩͬͨɻ͓͍͔ͬͨ͠ɻ") .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe() compositeDisposable.add(disposable) }

Slide 37

Slide 37 text

·ͱΊ

Slide 38

Slide 38 text

(6*ΞϓϦέʔγϣϯͷಛੑ w Ϟσϧͷঢ়ଶΛ΋ͱʹ6*Λߋ৽͠ଓ͚Δ w ը໘ؒͰͷσʔλͷ΍ΓऔΓ͕ඞཁ w ϝΠϯεϨουΛࢭΊͯ͸͍͚ͳ͍

Slide 39

Slide 39 text

ͭͷߏ଄ w 0CTFSWFSύλʔϯ w ΦϒδΣΫτͷੜ੒ɾ؅ཧ w ඇಉظॲཧͷந৅Խ

Slide 40

Slide 40 text

"OESPJEBQQ ,PUMJO 3Y+BWB %BHHFS %BUB#JOEJOH "SDIJUFDUVSF$PNQPOFOUT

Slide 41

Slide 41 text

"DUJWJUZ 'SBHNFOU 'SBHNFOU "QQMJDBUJPO "QQ
 $PNQPOFOU "QQ.PEVMF 7JFX.PEFM %BHHFS 3Y+BWB "SDIJUFDUVSF $PNQPOFOUT 0UIFS
 .PEFMT 7JFX 7JFX %BUB#JOEJOH "DUJWJUZ
 $PNQPOFOU "DUJWJUZ.PE

Slide 42

Slide 42 text

0CTFSWFSύλʔϯ w %BUB#JOEJOH w 3PPN "SDIJUFDUVSF$PNQPOFOUT w -JWF%BUB "OESPJE w 3Y+BWB

Slide 43

Slide 43 text

ΦϒδΣΫτͷੜ੒ɾ؅ཧ w %BHHFS w 7JFX.PEFM "SDIJUFDUVSF$PNQPOFOUT

Slide 44

Slide 44 text

ඇಉظॲཧͷந৅Խ w Ϋϩʔδϟ ,PUMJO w 3Y+BWB

Slide 45

Slide 45 text

(6*ΞϓϦέʔγϣϯͷߏ଄ͱઃܭ w యܕతͳ(6*ΞϓϦέʔγϣϯͷઃܭ͸ͭͷߏ଄Ͱ
 આ໌Ͱ͖Δ w ͜ͷߏ଄ʹண؟͢Δ͜ͱͰෳࡶͳ(6*ΞϓϦέʔγϣϯΛ ͏·͘ઃܭͰ͖Δ