Upgrade to Pro — share decks privately, control downloads, hide ads and more …

No more Adapter with Epoxy and Data Binding

No more Adapter with Epoxy and Data Binding

Takuji Nishibayashi

March 01, 2019
Tweet

More Decks by Takuji Nishibayashi

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • @takuji31 id:takuji31 • Takuji Nishibayashi • Hatena Co.,

    Ltd. • App Team • δϟϯϓϧʔΩʔʂ • ίϛοΫDAYS • ΧΫϤϜ
  2. ࣗݾ঺հ • Android • Kotlin • ! https://blog.takuji31.jp • "

    https://nazuna.takuji31.jp • # $ https://photo.takuji31.jp
  3. !

  4. 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) } }
  5. ΫϦοΫΠϕϯτͷ఻ୡͲ͏͢Δ…ʁ 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() } } }
  6. 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)))
  7. 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>
  8. !

  9. Carousel recyclerView.withModels { carousel { id("entryCaroucel") withModelsFrom(entries) { entry ->

    ItemEntryBindingModel_() .id("entry_${entry.id}") .entry(entry) } } }
  10. ෳࡶͳϨΠΞ΢τ 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) } }