Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Paging2から3に移行した話
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yuta Tomiyama
August 22, 2020
Programming
0
450
Paging2から3に移行した話
Zli × CA 合同LT にて発表
Yuta Tomiyama
August 22, 2020
Tweet
Share
More Decks by Yuta Tomiyama
See All by Yuta Tomiyama
ビルドプロセスをデバッグしよう!
yt8492
1
410
モバイルアプリ開発を始めよう!
yt8492
0
95
Git勉強会
yt8492
0
190
なんでもやってみる勇気
yt8492
0
120
Android Autoが思ったよりしんどい話
yt8492
0
240
apollo-kotlinにcontributeした話
yt8492
0
170
DMM TVのSDカードダウンロード機能を実装した話
yt8492
1
940
今だからこそ知りたいKotlin Multiplatform
yt8492
0
320
State management and API calls in Jetpack Compose: Learning Apollo + Jetpack Compose through React Hooks
yt8492
0
1.3k
Other Decks in Programming
See All in Programming
AI駆動開発の本音 〜Claude Code並列開発で見えたエンジニアの新しい役割〜
hisuzuya
4
510
Ruby x Terminal
a_matsuda
7
600
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
460
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
180
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
290
OTP を自動で入力する裏技
megabitsenmzq
0
110
エンジニアの「手元の自動化」を加速するn8n 2026.02.27
symy2co
0
160
最初からAWS CDKで技術検証してもいいんじゃない?
akihisaikeda
4
150
Go 1.26でのsliceのメモリアロケーション最適化 / Go 1.26 リリースパーティ #go126party
mazrean
1
410
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
560
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
110
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
360
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
280
The Limits of Empathy - UXLibs8
cassininazir
1
260
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Navigating Weather and Climate Data
rabernat
0
140
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
120
A Modern Web Designer's Workflow
chriscoyier
698
190k
Docker and Python
trallard
47
3.8k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
150
How to Ace a Technical Interview
jacobian
281
24k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Transcript
Paging2から3に移行した話 2020/08/22 Zli × CA 合同LT会
自己紹介 HN: マヤミト 本名: 富山雄太 会津大学26期 (学部3年) Zli 現代表 GitHub:
https://github.com/yt8492 好きな技術: Android, Kotlin, gRPC 趣味: Kotlin, 同人音声, VTuber Twitter: yt8492
Pagingってどんなの? ページング ライブラリを使用すると、データの小さなチャンクを一度に読み込んで表示す ることができます。 部分的なデータをオンデマンドで読み込むことで、ネットワーク帯域 幅とシステム リソースの使用量を削減できます。 (https://developer.android.com/topic/libraries/architecture/paging?hl=ja より引用) RecyclerViewのページング処理を簡単に実装できるライブラリ
最新の安定版リリースは2.1.2だが、先日アルファ版で3.0.0がリリースされた
Paging3で変わったこと(一部) - Kotlin Coroutinesのサポート - PagingDataやState、ErrorをCoroutineのFlowで扱うように - データを取得するloadメソッドがsuspend関数に - APIの簡易化
- 2ではデータ取得の処理の実装に DataSourceやDataSource.Factoryを実装する必要があったが、 3ではPagingSourceの実装のみで済む - 2ではDataSourceのデータ取得の処理に初回ロード、次ページ読み込み、前ページ読み込みでメ ソッドが3つに分かれていたが、 3では1つのメソッドに統合
実際に移行してみよう
before: PageKeyedDataSource - ロードの種類でメソッドが分かれる - Coroutineを使いたい場合は自前で CoroutineScopeを用意する必要がある - 表示させたいリストのデータと次のkey をコールバックに渡す
- DataSource.Factoryも実装する必要が ある
after: PagingSource - メソッドが1つに - suspend関数として実装 - 返り値の型が成功と失敗の 直和型 -
初回ロードの場合はkeyがnull
before: ViewModel - PagedListはLiveDataで提供される - 更新処理はDataSource.invalidate を呼び出す
after: ViewModel - PagingDataをFlowで扱うかLiveDataで扱うか選ぶことができる - 更新処理はPagingDataAdapterで用意されているため自前で実装する必要がない - Flowを使う場合、cachedInで引数に渡したCoroutineScopeの間キャッシュされる
before: Fragment - 更新処理はViewModelに生やしたrefreshを呼ぶ - PagedListのLiveDataをobserveし、変更が走るたびにPagedListAdapterにsubmitList する - ローディングなどのアニメーションがある場合、refreshを呼ぶタイミングでアニメーション を発火し変更が走ったタイミングで止める
after: Fragment - 更新処理はPagingDataAdapterに 生えているrefreshを呼ぶ - PagingDataをFlowで扱う場合は collectLatestでsubmitDataする - PagingDataAdapter.dataRefreshFlow
には更新が終わったタイミングで trueが流れてくる - PagingDataAdapter.loadStateFlowに はロードの状態が流れてくるため、 アニメーションを細かく設定するな らこっちのほうが向いてるかも
使ってみた感想 - Paging3はよりKotlinフレンドリーになっている - Paging2より簡潔かつ強力になっている - 単純に移行するだけならすぐ終わるので、一度試す価値はあると思う - 早く安定版リリースされてくれーーッ(出たばかりなので恐らく当分先)
今回のコード QiitaClient https://github.com/yt8492/QiitaClient Paging2を使ったコードは paging2 ブランチに、Paging3を使ったコードはmasterブラン チにあります
参考資料 ページング ライブラリの概要 https://developer.android.com/topic/libraries/architecture/paging Paging 3 library overview https://developer.android.com/topic/libraries/architecture/paging/v3-overview Android
Paging codelab https://codelabs.developers.google.com/codelabs/android-paging