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
DiffUtil
Search
Takuji Nishibayashi
August 31, 2016
Technology
0
180
DiffUtil
About DiffUtil in Kanmoba #17
Takuji Nishibayashi
August 31, 2016
Tweet
Share
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
CameraX使ってみた
takuji31
0
64
kotlinx.datetime 使ってみた
takuji31
0
260
HiltのCustom Componentについて
takuji31
0
150
java.timeをAndroidで使う
takuji31
0
59
KSPを使ってコード生成
takuji31
0
290
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
960
kotlinx.serialization
takuji31
0
540
kanmoba-returns-02.pdf
takuji31
0
180
AndroidXとKotlin Coroutines
takuji31
0
330
Other Decks in Technology
See All in Technology
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
Terraform Stacks入門 #HashiTalks
msato
0
350
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
470
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
410
Application Development WG Intro at AppDeveloperCon
salaboy
0
190
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
Introduction to Works of ML Engineer in LY Corporation
lycorp_recruit_jp
0
120
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
120
Featured
See All Featured
The Language of Interfaces
destraynor
154
24k
Why Our Code Smells
bkeepers
PRO
334
57k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Building Your Own Lightsaber
phodgson
103
6.1k
Fireside Chat
paigeccino
34
3k
Scaling GitHub
holman
458
140k
Designing for humans not robots
tammielis
250
25k
The Cult of Friendly URLs
andyhume
78
6k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
We Have a Design System, Now What?
morganepeng
50
7.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
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 !