Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Tweak RvAdapterDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jun 24, 2024
1 parent ac2d819 commit 54b3dbe
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.goooler.demoapp.adapter.rv.core

import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView

/**
Expand All @@ -14,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
*/
@Suppress("TooManyFunctions")
abstract class BaseRvAdapter<M : IVhModelType> private constructor(
private val delegate: RvAdapterDelegate<M>,
private val delegate: RvAdapterDelegate<M, BaseRvAdapter<M>>,
) : RecyclerView.Adapter<BindingViewHolder>(),
IRvBinding<M>,
IMutableRvAdapter<M>,
Expand All @@ -33,14 +32,6 @@ abstract class BaseRvAdapter<M : IVhModelType> private constructor(
notifyDataSetChanged()
}

override fun onCreateVHForAll(binding: ViewDataBinding) {
onCreateVH(binding)
}

override fun onBindVHForAll(binding: ViewDataBinding, model: M, payloads: List<Any>) {
onBindVH(binding, model, payloads)
}

override fun refreshItems(items: List<M>) {
delegate.refreshItems(items, ::notifyItemChanged)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ internal interface IRvAdapterDelegate<M : IVhModelType, VH : BindingViewHolder>
* @since 1.0.0
*/
@Suppress("TooManyFunctions")
internal class RvAdapterDelegate<M : IVhModelType> : IRvAdapterDelegate<M, BindingViewHolder> {
internal class RvAdapterDelegate<M : IVhModelType, AP> : IRvAdapterDelegate<M, BindingViewHolder>
where AP : IRvAdapter<M>,
AP : IRvBinding<M> {

private val ivdManager = ViewTypeDelegateManager<M>()
private val _list = mutableListOf<M>()

lateinit var adapter: IRvAdapter<M>
lateinit var adapter: AP

override var list: List<M>
get() = _list.toImmutableList()
Expand Down Expand Up @@ -121,11 +123,11 @@ internal class RvAdapterDelegate<M : IVhModelType> : IRvAdapterDelegate<M, Bindi
}

override fun onCreateVHForAll(binding: ViewDataBinding) {
error("Shouldn't call this in delegate.")
adapter.onCreateVH(binding)
}

override fun onBindVHForAll(binding: ViewDataBinding, model: M, payloads: List<Any>) {
error("Shouldn't call this in delegate.")
adapter.onBindVH(binding, model, payloads)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.goooler.demoapp.adapter.rv.diff

import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.AsyncDifferConfig
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
Expand All @@ -21,7 +20,7 @@ import io.goooler.demoapp.adapter.rv.core.RvAdapterDelegate
*/
abstract class BaseRvDiffAdapter<M : IDiffVhModelType> private constructor(
callback: AsyncDifferConfig<M>,
private val delegate: RvAdapterDelegate<M>,
private val delegate: RvAdapterDelegate<M, BaseRvDiffAdapter<M>>,
) : ListAdapter<M, BindingViewHolder>(callback),
IRvBinding<M>,
IMutableRvAdapter<M>,
Expand All @@ -47,14 +46,6 @@ abstract class BaseRvDiffAdapter<M : IDiffVhModelType> private constructor(
submitList(delegate.transform(value))
}

override fun onCreateVHForAll(binding: ViewDataBinding) {
onCreateVH(binding)
}

override fun onBindVHForAll(binding: ViewDataBinding, model: M, payloads: List<Any>) {
onBindVH(binding, model, payloads)
}

/**
* Please do not use it with setList() !
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import io.goooler.demoapp.adapter.rv.diff.IDiffVhModelType
*/
abstract class BaseRvPagingAdapter<M : IDiffVhModelType> private constructor(
callback: DiffCallBack<M>,
private val delegate: RvAdapterDelegate<M>,
private val delegate: RvAdapterDelegate<M, BaseRvPagingAdapter<M>>,
) : PagingDataAdapter<M, BindingViewHolder>(callback),
IRvBinding<M>,
IRvAdapter<M>,
Expand Down

0 comments on commit 54b3dbe

Please sign in to comment.