Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
DiffUtil
Search
Takuji Nishibayashi
August 31, 2016
Technology
0
190
DiffUtil
About DiffUtil in Kanmoba #17
Takuji Nishibayashi
August 31, 2016
Tweet
Share
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
compose-hot-reload を試そうとした話
takuji31
0
110
CameraX使ってみた
takuji31
0
260
kotlinx.datetime 使ってみた
takuji31
0
890
HiltのCustom Componentについて
takuji31
0
310
java.timeをAndroidで使う
takuji31
0
150
KSPを使ってコード生成
takuji31
0
410
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3k
kotlinx.serialization
takuji31
0
640
kanmoba-returns-02.pdf
takuji31
0
250
Other Decks in Technology
See All in Technology
ブラウザ拡張のセキュリティの話 / Browser Extension Security
flatt_security
0
210
TypeScript×CASLでつくるSaaSの認可 / Authz with CASL
saka2jp
2
160
TypeScript 6.0で非推奨化されるオプションたち
uhyo
15
5.6k
レガシーで硬直したテーブル設計から変更容易で柔軟なテーブル設計にする
red_frasco
4
650
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
970
PostgreSQL で列データ”ファイル”を利用する ~Arrow/Parquet を統合したデータベースの作成~
kaigai
0
180
スタートアップの事業成長を支えるアーキテクチャとエンジニアリング
doragt
1
9.3k
今すぐGoogle Antigravityを触りましょう
rfdnxbro
0
230
組織の“見えない壁”を越えよ!エンタープライズシフトに必須な3つのPMの「在り方」変革 #pmconf2025
masakazu178
1
1k
AI エージェントを評価するための温故知新と Spec Driven Evaluation
icoxfog417
PRO
2
960
事業状況で変化する最適解。進化し続ける開発組織とアーキテクチャ
caddi_eng
1
8.9k
Bedrock のコスト監視設計
fohte
2
250
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Site-Speed That Sticks
csswizardry
13
970
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
RailsConf 2023
tenderlove
30
1.3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.2k
The World Runs on Bad Software
bkeepers
PRO
72
12k
4 Signs Your Business is Dying
shpigford
186
22k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
GitHub's CSS Performance
jonrohan
1032
470k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.1k
Code Reviewing Like a Champion
maltzj
527
40k
Transcript
DiffUtil @takuji31
@takuji31 (Takuji Nishibayashi) Application Engineer at Hatena
Loves ! (AVG 160 ~ 170)
Loves Kotlin
Kansai.kt #2 Γ·͢
11݄ͷͲ͔͜ͷ༵ (༧ఆ)
࠷ۙPerlͱ TypeScriptॻ͍ͯ·͢
AGENDA • DiffUtilͱ • ͬͯΈΔ • ੍ݶࣄ߲
DiffUtilͱ
2ͭͷListͷࠩΛܭࢉ͢ ΔϢʔςΟϦςΟʔɻ
recyclerview-v7 24.2.0 ~
ܭࢉͰ͖Δมߋ • Ճ • আ • ߋ৽ • Ҡಈ •
Φϓγϣϯࢦఆ • ܭࢉίετ͕Ͷ্͕Δ
2ͭͷΫϥε • DiffUtil.Callback • DiffUtil.DiffResult
DiffUtil.Callback
มԽΛDiffUtilʹ͑Δ Callback
DiffUtil.Callback • getNewListSize() • getOldListSize() • areItemsTheSame(int, int) • areContentsTheSame(int,
int) • getChangePayload(int, int)
DiffUtil.DiffResult
ܭࢉͨ͠diffͷ݁Ռ
DiffResult.dispatchUp datesTo(RecyclerView .Adapter| ListUpdateCallback)
ͬͯΈΔ
※͍ͭ௨ΓKotlinͰ͢
build.gradle dependencies { compile 'com.android.support:recyclerview-v7:24.2.0' }
Model enum class Status { INTERESTED, LIKE, LOVE; } data
class Artist(val name: String, val status: Status) { companion object { val list: List<Artist> = listOf( Artist(name = "খ།", status = LOVE), Artist(name = "Ӎٶఱ", status = LOVE), //... ) } }
DiffUtil.Callback class DiffCallback( val oldList: List<Artist>, val newList: List<Artist>) :
DiffUtil.Callback() { override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { return oldList[oldItemPosition].name == newList[newItemPosition].name } override fun getOldListSize(): Int { return oldList.size } override fun getNewListSize(): Int { return newList.size } override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { return oldList[oldItemPosition] == newList[newItemPosition] } override fun getChangePayload( oldItemPosition: Int, newItemPosition: Int): Pair<Status, Status> { return Pair(oldList[oldItemPosition].status, newList[newItemPosition].status) } }
diffΛܭࢉ͢Δ fun updateItems(items : List<Artist>) { val oldItems = adapter.items
val diffResult = DiffUtil.calculateDiff( DiffCallback( oldList = oldItems, newList = items ), true ) adapter.items = items diffResult.dispatchUpdatesTo(adapter) }
None
RecylerViewҎ֎ͱ Έ߹Θ͍ͤͨ
Change payloadͷத ΛݟͯԿ͔͍ͨ͠ɺͳͲ ͱ͍ͬͨ߹
ListUpdateCallbackΛ ͏
੍ݶࣄ߲ • ৽͍͠Listͱݹ͍ListΛൺֱ͢Δ • × MutableͳList • RealmCollection • ×
ཁૉͦͷͷ͕ߋ৽͞ΕΔ • RealmObject • Listͷཁૉ2^26(=67108864)·Ͱ
·ͱΊ • DiffUtil Λ͏͜ͱͰ RecylerView ͷৄࡉͳߋ৽௨͕ ָʹͳΔ • RecylerView Ҏ֎ͱͷΈ߹ΘͤͳͲڽͬͨ͜ͱΛΓ͍ͨ
࣌ ListUpdateCallback Λ͏
takuji31/ DiffUtilSample
enjoy diff life !