Skip to content

Commit

Permalink
Refactor bindigns as BaseViewHolder's extension
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Jul 17, 2021
1 parent 5b20fd7 commit a18b5a5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package com.skydoves.disneymotions.view.viewholder

import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.skydoves.baserecyclerviewadapter.BaseViewHolder

inline fun <reified T : ViewDataBinding> bindings(view: View): Lazy<T> =
inline fun <reified T : ViewDataBinding> BaseViewHolder.bindings(): Lazy<T> =
lazy(LazyThreadSafetyMode.NONE) {
requireNotNull(DataBindingUtil.bind<T>(view)) { "cannot find the matched view to layout." }
requireNotNull(DataBindingUtil.bind(itemView)) { "cannot find the matched view to layout." }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.skydoves.disneymotions.view.ui.details.PosterDetailActivity
class PosterCircleViewHolder(view: View) : BaseViewHolder(view) {

private lateinit var data: Poster
private val binding: ItemPosterCircleBinding by bindings(view)
private val binding: ItemPosterCircleBinding by bindings()

override fun bindData(data: Any) {
if (data is Poster) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.skydoves.disneymotions.view.ui.details.PosterDetailActivity
class PosterLineViewHolder(view: View) : BaseViewHolder(view) {

private lateinit var data: Poster
private val binding: ItemPosterLineBinding by bindings(view)
private val binding: ItemPosterLineBinding by bindings()

override fun bindData(data: Any) {
if (data is Poster) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.skydoves.disneymotions.view.ui.details.PosterDetailActivity
class PosterViewHolder(view: View) : BaseViewHolder(view) {

private lateinit var data: Poster
private val binding: ItemPosterBinding by bindings(view)
private val binding: ItemPosterBinding by bindings()

override fun bindData(data: Any) {
if (data is Poster) {
Expand Down

0 comments on commit a18b5a5

Please sign in to comment.