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
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
75
CameraX使ってみた
takuji31
0
220
kotlinx.datetime 使ってみた
takuji31
0
690
HiltのCustom Componentについて
takuji31
0
280
java.timeをAndroidで使う
takuji31
0
130
KSPを使ってコード生成
takuji31
0
380
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
2.8k
kotlinx.serialization
takuji31
0
610
kanmoba-returns-02.pdf
takuji31
0
230
Other Decks in Technology
See All in Technology
Lakebaseを使ったAIエージェントを実装してみる
kameitomohiro
0
160
Rethinking Incident Response: Context-Aware AI in Practice
rrreeeyyy
1
130
いつの間にか入れ替わってる!?新しいAWS Security Hubとは?
cmusudakeisuke
0
140
AI エージェントと考え直すデータ基盤
na0
17
5.5k
United Airlines Customer Service– Call 1-833-341-3142 Now!
airhelp
0
170
60以上のプロダクトを持つ組織における開発者体験向上への取り組み - チームAPIとBackstageで構築する組織の可視化基盤 - / sre next 2025 Efforts to Improve Developer Experience in an Organization with Over 60 Products
vtryo
2
490
VGGT: Visual Geometry Grounded Transformer
peisuke
0
160
DatabricksにOLTPデータベース『Lakebase』がやってきた!
inoutk
0
140
インフラ寄りSREの生存戦略
sansantech
PRO
7
2.5k
データ基盤からデータベースまで?広がるユースケースのDatabricksについて教えるよ!
akuwano
3
140
Delegating the chores of authenticating users to Keycloak
ahus1
0
160
ビギナーであり続ける/beginning
ikuodanaka
3
790
Featured
See All Featured
Building an army of robots
kneath
306
45k
A Tale of Four Properties
chriscoyier
160
23k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The World Runs on Bad Software
bkeepers
PRO
69
11k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
980
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Code Reviewing Like a Champion
maltzj
524
40k
How to Ace a Technical Interview
jacobian
278
23k
Git: the NoSQL Database
bkeepers
PRO
430
65k
How to Think Like a Performance Engineer
csswizardry
25
1.7k
A designer walks into a library…
pauljervisheath
207
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 !