From b8ca2b0c07a72149e531a55de0269fba8d5d28b6 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 13 Nov 2019 14:28:03 -0800 Subject: Add unbind functions --- core-ui/src/main/res-public/values/public.xml | 6 ++-- core/src/main/res-public/values/public.xml | 34 +++++++++++----------- .../fastadapter/viewbinding/BindingItem.kt | 22 ++++++++++---- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/core-ui/src/main/res-public/values/public.xml b/core-ui/src/main/res-public/values/public.xml index c8c2e56..f62ed25 100644 --- a/core-ui/src/main/res-public/values/public.xml +++ b/core-ui/src/main/res-public/values/public.xml @@ -1,10 +1,10 @@ - - - + + + \ No newline at end of file diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml index 9f8780e..a912019 100644 --- a/core/src/main/res-public/values/public.xml +++ b/core/src/main/res-public/values/public.xml @@ -1,20 +1,25 @@ - - + - - - - + - - - + + + + + + + + + + + + @@ -99,6 +104,7 @@ + @@ -106,12 +112,6 @@ - - - - - - - - + + \ No newline at end of file diff --git a/fastadapter-viewbinding/src/main/kotlin/ca/allanwang/fastadapter/viewbinding/BindingItem.kt b/fastadapter-viewbinding/src/main/kotlin/ca/allanwang/fastadapter/viewbinding/BindingItem.kt index a475615..543a9ef 100644 --- a/fastadapter-viewbinding/src/main/kotlin/ca/allanwang/fastadapter/viewbinding/BindingItem.kt +++ b/fastadapter-viewbinding/src/main/kotlin/ca/allanwang/fastadapter/viewbinding/BindingItem.kt @@ -19,6 +19,8 @@ import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding import ca.allanwang.kau.fastadapter.viewbinding.R @@ -40,8 +42,8 @@ interface BindingLayout { } abstract class BindingItem(open val data: Any?) : - AbstractItem(), - BindingLayout { + AbstractItem(), + BindingLayout { override val type: Int get() = layoutRes @@ -62,6 +64,14 @@ abstract class BindingItem(open val data: Any?) : abstract fun Binding.bindView(holder: ViewHolder, payloads: MutableList) + protected fun unbind(vararg textViews: TextView) { + textViews.forEach { it.text = null } + } + + protected fun unbind(vararg imageViews: ImageView) { + imageViews.forEach { it.setImageDrawable(null) } + } + final override fun unbindView(holder: ViewHolder) { super.unbindView(holder) val binding = holder.getBinding() @@ -71,7 +81,7 @@ abstract class BindingItem(open val data: Any?) : open fun Binding.unbindView(holder: ViewHolder) {} final override fun getViewHolder(v: View): ViewHolder = - ViewHolder(v, layoutRes) + ViewHolder(v, layoutRes) override fun failedToRecycle(holder: ViewHolder): Boolean { KL.e { "Failed to recycle" } @@ -87,7 +97,7 @@ abstract class BindingItem(open val data: Any?) : override fun hashCode(): Int = data.hashCode() class ViewHolder(itemView: View, internal val layoutRes: Int) : - RecyclerView.ViewHolder(itemView) { + RecyclerView.ViewHolder(itemView) { /** * Retrieves a binding. @@ -109,7 +119,7 @@ abstract class BindingItem(open val data: Any?) : } abstract class BindingClickEventHook>(val identifier: BindingLayout) : - ClickEventHook() { + ClickEventHook() { private fun RecyclerView.ViewHolder.binding(): Binding? { val holder = this as? BindingItem.ViewHolder ?: return null @@ -136,7 +146,7 @@ abstract class BindingClickEventHook? = - super.onBindMany(viewHolder) + super.onBindMany(viewHolder) final override fun onClick(v: View, position: Int, fastAdapter: FastAdapter, item: Item) { BindingItem.getBinding(v).onClick(v, position, fastAdapter, item) -- cgit v1.2.3