Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
No more Adapter with Epoxy and Data Binding
Search
Takuji Nishibayashi
March 01, 2019
Technology
1.1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
No more Adapter with Epoxy and Data Binding
Takuji Nishibayashi
March 01, 2019
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
compose-hot-reload を試そうとした話
takuji31
0
170
CameraX使ってみた
takuji31
0
330
kotlinx.datetime 使ってみた
takuji31
0
1.2k
HiltのCustom Componentについて
takuji31
0
450
java.timeをAndroidで使う
takuji31
0
220
KSPを使ってコード生成
takuji31
0
500
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.3k
kotlinx.serialization
takuji31
0
710
kanmoba-returns-02.pdf
takuji31
0
310
Other Decks in Technology
See All in Technology
生成AIで高い生産性を求められて、 悩み、乗り越えた話
mot_techtalk
2
110
Execution in the Kingdom of Agents: Reflections on Abstraction and Complexity
bcantrill
0
810
LLM機能を自作して分かるSnowflake Cortex AIの強み
nayuts
0
250
Databricksメトリクスビューはじめてのもくもく会
taka_aki
0
190
More Freedom on the Same Shared GPU Cluster: A Small Team’s Experience with vCluster
nttcom
0
120
VS Code × GitHub Copilot での Fabric 開発
ryomaru0825
1
260
企業の現実世界をグラフで写し取る
sansantech
PRO
0
260
The seven pitfalls of AI (revised version)
ufried
0
230
Codex概要
ymiya55
0
280
ai_cording_with_k8s_knowledge.pdf
mochizuki875
1
170
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
330
Incremental HTTP
kazuho
5
2k
Featured
See All Featured
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
480
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Amusing Abliteration
ianozsvald
1
320
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
300
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Building AI with AI
inesmontani
PRO
1
1.3k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Ethics towards AI in product and experience design
skipperchong
2
410
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
My Coaching Mixtape
mlcsv
0
340
Transcript
No more Adapter with Epoxy and Data Binding @takuji31 ژDev͔;͐
#5
ࣗݾհ
ࣗݾհ • @takuji31 id:takuji31 • Takuji Nishibayashi • Hatena Co.,
Ltd. • App Team • δϟϯϓϧʔΩʔʂ • ίϛοΫDAYS • ΧΫϤϜ
ࣗݾհ • Android • Kotlin • ! https://blog.takuji31.jp • "
https://nazuna.takuji31.jp • # $ https://photo.takuji31.jp
RecyclerView
ͬͯͳ͍ਓ͍·ͤΜΑͶʁ
ViewHolder + Adapter
ΦϓγϣϯͰ DiffUtil
blog.takuji31.jp/entry/kanmoba17
ෳࡶͳը໘
None
Ͳ͏࣮ݱ͢Δʁ
खͰؤுΔ
ViewHolderΛview type͝ͱʹ࡞Δ
onCreateViewHolderͰ֘͢Δ ViewHolderΛ࡞Δ
onBindViewHolderͰViewHolderͷ ܕΛݟͯΛઃఆ
มߋݕ
DiffUtilͰؤுΔ
!
Section Library
※ ͍͔ͭ͘ϥΠϒϥϦʔ͕͋Γ·͢ ͕ҰൠతͳͰ͢
view typeͷΘΓʹSectionͱ͍͏ ΫϥεΛ͏
Section class WorkSection(val items:List<Work>): Section<WorkViewHolder>() { override fun onCreateViewHolder(inflator: LayoutInflator,
parent: ViewGroup): WorkViewHolder { return WorkViewHolder(inflator.inflate(R.layout.recycle_item_work, parent, false)) } override fun onBindViewHolder(viewHolder: WorkViewHolder, position: Int) { val work = items[position] viewHolder.title = work.title Picasso.get().load(work.imageUri).into(viewHolder.imageView) } }
Adapter val adapter = Adapter() adapter.addSection(BannerSection(works)) adapter.addSection(WorkSection(works.take(10))) adapter.addSection(EntrySection(works)) adapter.addSection(WorkSection(works.drop(10)))
ύοͱݟ؆୯ͦ͏
ΫϦοΫΠϕϯτͷୡͲ͏͢Δ…ʁ class WorkSection(val items:List<Work>, val onClick: (Work) -> Unit): Section<WorkViewHolder>()
{ override fun onCreateViewHolder(inflator: LayoutInflator, parent: ViewGroup): WorkViewHolder { return WorkViewHolder(inflator.inflate(R.layout.recycle_item_work, parent, false)) } override fun onBindViewHolder(viewHolder: WorkViewHolder, position: Int) { val work = items[position] viewHolder.title = work.title Picasso.get().load(work.imageUri).into(viewHolder.imageView) viewHolder.itemView.setOnClickListener { onClick() } } }
Adapter val adapter = Adapter( {work -> viewModel.onWorkSelected(work)}, {entry ->
viewModel.onEntrySelected(entry)}, {banner -> viewModel.onBannerSelected(banner)}, ) adapter.addSection(BannerSection(works)) adapter.addSection(WorkSection(works.take(10))) adapter.addSection(EntrySection(works)) adapter.addSection(WorkSection(works.drop(10)))
ͪΐͬͱ໘
ͦͦ
Adapter -> Section -> ViewHolder
֊͕૿͑Δ
ঢ়ଶΛόϥόϥʹ͍࣋ͬͯͨΓ͢Δ ͱ෮ݩͰࢮ͵
Ϋϥε૿͑Δ
ॳݟͰΊͬͪΌΉ͍ͣ
Epoxy
github.com/airbnb/epoxy
No more
ViewHolder
notifyDataSetChanged()
Adapter
Carousel support
Data Binding Friendly
Kotlin DSL support!!!
build.gradle dependencies { implementation "com.airbnb.android:epoxy:3.3.0" implementation "com.airbnb.android:epoxy-databinding:3.3.0" kapt "com.airbnb.android:epoxy-processor:3.3.0" }
package-info.java @EpoxyDataBindingPattern(rClass = R.class, layoutPrefix = "recycler") package jp.takuji31.epoxyexample; import
com.airbnb.epoxy.EpoxyDataBindingPattern;
recycler_item_work.xml <layout> <data> <variable name="work" type="jp.takuji31.epoxyexample.model.Work" /> <variable name="onClick" type="android.view.View.OnClickListener"
/> </data> <androidx.cardview.widget.CardView android:onClick="@{onClick}"> <androidx.constraintlayout.widget.ConstraintLayout> <ImageView app:imageUri="@{work.imageUri}"/> <TextView android:text="@{work.title}"/> </androidx.constraintlayout.widget.ConstraintLayout> </androidx.cardview.widget.CardView> </layout>
Activity or Fragment recyclerView.withModels { works.forEach { work -> itemWork
{ id("work_${work.id}") work(work) } } }
None
!
Carousel
Carousel recyclerView.withModels { carousel { id("entryCaroucel") withModelsFrom(entries) { entry ->
ItemEntryBindingModel_() .id("entry_${entry.id}") .entry(entry) } } }
None
؆୯͗͢Ͱ
ෳࡶͳϨΠΞτ
ෳࡶͳϨΠΞτ Carousel.setDefaultGlobalSnapHelperFactory(null) carousel { id("bannerCarousel") withModelsFrom(banners) { ItemBannerBindingModel_() .id("banner_${it.id}") .banner(it)
} } works.take(10).forEach { work -> itemWork { id("work_${work.id}") work(work) } }
ෳࡶͳϨΠΞτ headerBlogEntry { id("blog_header") } carousel { id("entryCaroucel") withModelsFrom(entries) {
entry -> ItemEntryBindingModel_() .id("entry_${entry.id}") .entry(entry) } } works.drop(10).forEach { work -> itemWork { id("work_${work.id}") work(work) } }
ʂ
https://github.com/takuji31/epoxy- example
Enjoy RecyclerView life
! ࠾༻ใ
גࣜձࣾͯͳͰɺ ͱʹʮઓʯͰ͖Δ ؒΛืू͍ͯ͠·͢
͜ΜͳਓΛ୳͍ͯ͠·͢ • AndroidΞϓϦΛ࡞Γ͍ͨਓ • iOSΞϓϦΛ࡞Γ͍ͨਓ • ͋Δ͍྆ํ • ͳΜͳΒαʔόʔαΠυ
https://hatenacorp.jp/recruit/