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
Yuta Tomiyama
August 22, 2020
Programming
460
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Paging2から3に移行した話
Zli × CA 合同LT にて発表
Yuta Tomiyama
August 22, 2020
More Decks by Yuta Tomiyama
See All by Yuta Tomiyama
ビルドプロセスをデバッグしよう!
yt8492
2
480
モバイルアプリ開発を始めよう!
yt8492
0
120
Git勉強会
yt8492
0
210
なんでもやってみる勇気
yt8492
0
130
Android Autoが思ったよりしんどい話
yt8492
0
250
apollo-kotlinにcontributeした話
yt8492
0
190
DMM TVのSDカードダウンロード機能を実装した話
yt8492
1
1k
今だからこそ知りたいKotlin Multiplatform
yt8492
0
340
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で開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.3k
Contextとはなにか
chiroruxx
1
350
スマートグラスで並列バイブコーディング
hyshu
0
250
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
120
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
260
AI 輔助遺留系統現代化的經驗分享
jame2408
1
870
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
250
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.4k
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.3k
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
130
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
860
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Featured
See All Featured
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
WCS-LA-2024
lcolladotor
0
650
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
870
Heart Work Chapter 1 - Part 1
lfama
PRO
7
36k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
The Curse of the Amulet
leimatthew05
1
13k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
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