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

Paging Library Overview

Paging Library Overview

- Android Jetpack: manage infinite lists with RecyclerView and Paging (Google I/O '18)
- https://www.youtube.com/watch?v=BE5bsyGGLf4

- Architecture Components: Paging Library
- https://www.youtube.com/watch?v=QVMqCRs0BNA&t=29s

- Android Paging codelab
- https://codelabs.developers.google.com/codelabs/android-paging

- Android Developers: Paging library overview
- https://developer.android.com/topic/libraries/architecture/paging/

- Android JetPack
- https://developer.android.com/jetpack/

Ryosuke Horie

June 07, 2018
Tweet

More Decks by Ryosuke Horie

Other Decks in Programming

Transcript

  1. © Start Today Technologies Inc. ࣗݾ঺հ w ງߐ྄հ w ελʔττΡσΠςΫϊϩδʔζ

    w ৽ࣄۀ૑଄෦ϑϩϯτΤϯυνʔϜ w "OESPJEΤϯδχΞ w !)PSJF
  2. © Start Today Technologies Inc. -JTU6*T w ϞόΠϧΞϓϦͰΑ͘ݟΒΕΔ6* w ͔ͬ͠Γ࡞Δͷ͸݁ߏେม

    w ແݶ-JTUͷ࣮૷ ௥Ճϩʔυͷ࢓૊Έ w ύϑΥʔϚϯε w %#Λ࢖ͬͨΩϟογϡ w %J⒎6UJMʹΑΔࠩ෼ߋ৽
  3. © Start Today Technologies Inc. 1BHJOH-JCSBSZ w *OUFHSBUFEXJUI3FDZDMFS7JFX w -PBETEBUBHSBEVBMMZ

    w දࣔʹඞཁͳ෼͚ͩσʔλΛϩʔυ w 3PPNʹΑΔΩϟογϡ w %J⒎6UJMʹΑΔࠩ෼ߋ৽ w -BSHF CPVOEFEBOEVOCPVOEFEMJTUT w ༗ݶɾແݶ-JTUΛαϙʔτ
  4. © Start Today Technologies Inc. %BUB4PVSDFBOE%BUB4PVSDF'BDUPSZ w 1BHFE-JTUʹσʔλΛಡΈࠐΉ w %BUB4PVSDF'BDUPSZ͕%BUB4PVSDFΛੜ੒͢Δ੹຿Λෛ͏

    w %BUB4PVSDF͸Λࣗ࡞͢Δ͜ͱͰॊೈʹΧελϚΠζՄೳ w ࣍ͷछྨΛ%BUB4PVSDFʹಡΈࠐΉσʔλͷܗࣜʹΑͬͯબ୒ w 1BHF,FZFE%BUB4PVSDF w *UFN,FZFE%BUB4PVSDF w 1PTJUJPOBM%BUB4PVSDF
  5. © Start Today Technologies Inc. w -JWF1BHFE-JTU#VJMEFS w 3Y1BHFE-JTU#VJMEFS 1BHFE-JTU#VJMEFS

    val data: LiveData<PagedList<Repo>> = LivePagedListBuilder(dataSourceFactory, 30) val data: Observable<PagedList<Repo>> = RxPagedListBuilder(dataSourceFactory, 30)
  6. © Start Today Technologies Inc. w 1BHFE-JTU$POpH w 1BHJOHͷڍಈΛௐ੔Մೳ 1BHFE-JTU#VJMEFS

    val pagingConfig = PagedList.Config.Builder() .setPageSize(50) // 1ϖʔδ͋ͨΓʹදࣔ͢ΔΞΠςϜ਺ .setPrefetchDistance(10) // ௥Ճϩʔυͷᮢ஋ .setInitialLoadSizeHint(50) // ॳճϩʔυΞΠςϜ਺ .setEnablePlaceholders(true) // PlaceholderΛ࢖༻͢Δ͔ .build() val data = LivePagedListBuilder(dataSourceFactory, pagingConfig)
  7. © Start Today Technologies Inc. 1MBDFIPMEFS w σʔλ͕औಘͰ͖Δ·Ͱ1MBDFIPMEFSΛදࣔ w σʔλ͕औಘޙࣗಈతʹඳը

    w ϩʔσΟϯάը૾ෆཁ w "EBQUFSଆͰ͸OVMMΛϋϯυϦϯάͰ͖ΔΑ͏ରԠ w ྫσϑΥϧτ஋Λදࣔ override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { val repoItem: Repo? = getItem(position) (holder as RepoViewHolder).bind(repoItem) }
  8. © Start Today Technologies Inc. #PVOEBSZ$BMMCBDL w #PVOEBSZ$BMMCBDLPO;FSP*UFNT-PBEFE  w

    %BUB4PVSDF͕&NQUZͷ৔߹ʹ࣮ߦ w #PVOEBSZ$BMMCBDLPO*UFN"U&OE-PBEFE  w %BUB4PVSDF͔ΒऔಘՄೳͳσʔλΛશͯऔಘͨ͠৔߹ʹ࣮ߦ class RepoBoundaryCallback() : PagedList.BoundaryCallback<Repo>() { override fun onZeroItemsLoaded() { // API Request } override fun onItemAtEndLoaded(itemAtEnd: Repo) { // API Request } }
  9. © Start Today Technologies Inc. #PVOEBSZ$BMMCBDL w 1BHFE-JTU#VMEFSʹTFUͯ͠࢖༻ val data:

    LiveData<PagedList<Repo>> = LivePagedListBuilder(dataSourceFactory, 30) .setBoundaryCallback(boundaryCallback)
  10. © Start Today Technologies Inc. 1BHFE-JTU"EBQUFS Android Paging codelab w

    1BHFE-JTUΛαϙʔτ͢Δ"EBQUFS 1BHFE-JTU"EBQUFSTVCNJU-JTUͰ-JTUΛߋ৽
  11. © Start Today Technologies Inc. 1BHJOH-JCSBSZ͕-JTUΛߋ৽͢ΔྲྀΕ Android Paging codelab 

    -JTUऴ୺·ͰεΫϩʔϧ  #PVOEBSZ$BMMCBDLͷ
 PO*UFN"U&OE-PBEFEΛ࣮ߦ  σʔλΛऔಘ͠3PPNʹ௥Ճ
  12. © Start Today Technologies Inc. 1BHJOH-JCSBSZ͕-JTUΛߋ৽͢ΔྲྀΕ Android Paging codelab 

    -JTUऴ୺·ͰεΫϩʔϧ  #PVOEBSZ$BMMCBDLͷ
 PO*UFN"U&OE-PBEFEΛ࣮ߦ  σʔλΛऔಘ͠3PPNʹ௥Ճ  ৽͍͠1BHFE-JTU͕࡞੒
 -JWF%BUBͰ఻ୡ  1BHFE-JTU"EBQUFSTVCNJU-JTU
 Ͱ-JTUΛߋ৽
  13. © Start Today Technologies Inc. ·ͱΊ w 1BHJOH-JCSBSZΛ࢖͏ͱແݶεΫϩʔϧՄೳͳ-JTU6*Λ؆୯ʹ࡞ΕΔ w 1BHJOH

    +FUQBDL ͷ࢓૊Έʹ৐͔ͬͬͯ͠·͏ͱָͦ͏ w $PEFMBC͕Θ͔Γ΍͍͢ͷͰ1BHJOHʹֶ͍ͭͯͿʹ͸Φεεϝ w IUUQTDPEFMBCTEFWFMPQFSTHPPHMFDPNDPEFMBCTBOESPJEQBHJOH
  14. © Start Today Technologies Inc. ࢀߟࢿྉ w "OESPJE+FUQBDLNBOBHFJOpOJUFMJTUTXJUI3FDZDMFS7JFXBOE1BHJOH (PPHMF*0 

    w IUUQTXXXZPVUVCFDPNXBUDI W#&CTZ((-G w "SDIJUFDUVSF$PNQPOFOUT1BHJOH-JCSBSZ w IUUQTXXXZPVUVCFDPNXBUDI W27.R$3T#/"UT w "OESPJE1BHJOHDPEFMBC w IUUQTDPEFMBCTEFWFMPQFSTHPPHMFDPNDPEFMBCTBOESPJEQBHJOH w "OESPJE%FWFMPQFST1BHJOHMJCSBSZPWFSWJFX w IUUQTEFWFMPQFSBOESPJEDPNUPQJDMJCSBSJFTBSDIJUFDUVSFQBHJOH w "OESPJE+FU1BDL w IUUQTEFWFMPQFSBOESPJEDPNKFUQBDL