potatotips-33

836437265cbba12ee1b24bbb359a6c15?s=47 Yuya Kaido
September 28, 2016

 potatotips-33

836437265cbba12ee1b24bbb359a6c15?s=128

Yuya Kaido

September 28, 2016
Tweet

Transcript

  1. ϖʔδϯάͷ ঢ়ଶ؅ཧ͔Β։์͞Ε͍ͨ potatotips #33 yuyakaido

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

    yuyakaido yuyakaido
  3. ϖʔδϯάͱ͸ʁ • ௥ՃಡΈࠐΈ • Ϧετͷ࠷Լ෦ʹ౸ୡͨ͠ΒDB΍API͔Β࣍ ϖʔδͷσʔλΛಡΈࠐΜͰදࣔ͢Δ 

  4. ࠓճͷγφϦΦ • RecyclerView • ࠷Լ෦·Ͱ౸ୡͨ͠ΒAPI͔ΒσʔλΛऔಘ • औಘͨ͠σʔλΛ࠷Լ෦ʹ௥Ճ 

  5. ࣮૷ͯ͠ΈΔ • εΫϩʔϧΛίʔϧόοΫͰड͚औΔ • RecyclerView#OnScrollListener • AbsListView#OnScrollListener • ࠷Լ෦·Ͱ౸ୡͨ͠ΒAPIΛୟ͘ 

  6. εΫϩʔϧΠϕϯτ recyclerView.scrollEvents() .filter { RecyclerViewUtil.shouldPaginate(layoutManager) }
 .subscribe({
 // Load next

    page
 }) fun shouldPaginate(manager: LinearLayoutManager): Boolean {
 val totalItemCount = manager.itemCount - 1
 val lastVisibleItemPosition = manager.findLastVisibleItemPosition()
 return totalItemCount == lastVisibleItemPosition
 }  εΫϩʔϧͷݕ஌ ࠷Լ෦ͷ൑ఆ
  7. QA͞Μͱͷ΍ΓऔΓ ΞΠςϜ͕ॏෳͯ͠දࣔ͞Ε·͢Ͷ ͦΜͳΘ͚ͳ͍΍Ζ ɾɾɾ ΄Μ·΍ 

  8. Կނͳͷ͔ • ίʔϧόοΫ͕Կ౓΋ݺ͹Ε͍ͯΔ • Demo 

  9. 

  10. ରॲํ๏ • ಡΈࠐΈதϑϥάΛ࣋ͭ • ϑϥάΛͲ͜ʹ͔࣋ͭ • Activity/FragmentͷϑΟʔϧυ • ؅ཧ͢Δঢ়ଶ͕૿͑Δͷ͸ΠϠ •

    ΫϩʔδϟΛ࢖͏ͱ͍͍ײ͡ʹ؅ཧͰ͖ΔͷͰ͸ 
  11. ΫϩʔδϟͰͷঢ়ଶ؅ཧ fun getFetcher(category: Category): () -> Observable<List<Article>> {
 var isFetching

    = false
 var offset = 0
 return fun () = Observable.just(isFetching)
 .filter { !isFetching }
 .doOnNext { isFetching = true }
 .flatMap { repository.getArticles(category, offset) }
 .doOnNext { isFetching = false }
 .doOnNext { offset += it.size }
 } • ಡΈࠐΈதϑϥάͱΦϑηοτΛ؅ཧ • ಡΈࠐΈதʹୟ͍ͯ΋Կ΋ى͜Βͳ͍ • Activity/Fragment͔ΒΈΔͱɺԿ΋ߟ͑ͣʹୟ͚͹OK 
  12. ·ͱΊ • ϖʔδϯάͰ͸ಡΈࠐΈঢ়ଶΛ؅ཧ͢Δඞཁ͋Γ • ঢ়ଶΛΫϥεͷϑΟʔϧυͰ؅ཧͨ͘͠ͳ͍ • KotlinΛ࢖͍ͬͯΔ৔߹ΫϩʔδϟΛɺJavaͷ৔ ߹͸ແ໊ΫϥεΛ࢖͏ͱ޾ͤʹͳΕΔ͔΋ • https://github.com/yuyakaido/Flow-Android

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