aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core-ui/src/main/res-public/values/public.xml6
-rw-r--r--core/src/main/res-public/values/public.xml34
-rw-r--r--fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt60
-rw-r--r--fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/FastBindingAdapter.kt45
4 files changed, 43 insertions, 102 deletions
diff --git a/core-ui/src/main/res-public/values/public.xml b/core-ui/src/main/res-public/values/public.xml
index f62ed25..c8c2e56 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 @@
<resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
<!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task -->
+ <public name='kau_recycler_detached_background' type='layout' />
+ <public name='kau_elastic_recycler_activity' type='layout' />
+ <public name='kau_recycler_textslider' type='layout' />
<public name='Kau.Translucent' type='style' />
<public name='Kau.Translucent.NoAnimation' type='style' />
<public name='Kau.Translucent.SlideBottom' type='style' />
<public name='Kau.Translucent.SlideTop' type='style' />
- <public name='kau_recycler_detached_background' type='layout' />
- <public name='kau_elastic_recycler_activity' type='layout' />
- <public name='kau_recycler_textslider' type='layout' />
</resources> \ 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 443f32e..211c539 100644
--- a/core/src/main/res-public/values/public.xml
+++ b/core/src/main/res-public/values/public.xml
@@ -1,25 +1,20 @@
<resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
<!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task -->
+ <public name='kau_slide_in_top' type='anim' />
<public name='kau_slide_in_left' type='anim' />
- <public name='kau_slide_out_left' type='anim' />
+ <public name='kau_slide_out_right' type='anim' />
<public name='kau_slide_out_right_top' type='anim' />
+ <public name='kau_fade_in' type='anim' />
+ <public name='kau_slide_out_top' type='anim' />
+ <public name='kau_slide_out_bottom' type='anim' />
<public name='kau_fade_out' type='anim' />
+ <public name='kau_slide_out_left' type='anim' />
<public name='kau_slide_out_left_top' type='anim' />
- <public name='kau_fade_in' type='anim' />
<public name='kau_slide_in_bottom' type='anim' />
<public name='kau_slide_in_right' type='anim' />
- <public name='kau_slide_in_top' type='anim' />
- <public name='kau_slide_out_top' type='anim' />
- <public name='kau_slide_out_bottom' type='anim' />
- <public name='kau_slide_out_right' type='anim' />
- <public name='kau_enter_slide_right' type='transition' />
- <public name='kau_exit_slide_right' type='transition' />
- <public name='kau_exit_slide_top' type='transition' />
- <public name='kau_enter_slide_bottom' type='transition' />
- <public name='kau_enter_slide_left' type='transition' />
- <public name='kau_exit_slide_left' type='transition' />
- <public name='kau_enter_slide_top' type='transition' />
- <public name='kau_exit_slide_bottom' type='transition' />
+ <public name='kau_transparent' type='drawable' />
+ <public name='kau_selectable_white' type='drawable' />
+ <public name='kau_shadow_overlay' type='color' />
<public name='kau_activity_horizontal_margin' type='dimen' />
<public name='kau_activity_vertical_margin' type='dimen' />
<public name='kau_dialog_margin' type='dimen' />
@@ -105,7 +100,6 @@
<public name='kau_bullet_point' type='string' />
<public name='Kau' type='style' />
<public name='Kau.Translucent' type='style' />
- <public name='kau_shadow_overlay' type='color' />
<public name='KauFadeIn' type='style' />
<public name='KauFadeInFadeOut' type='style' />
<public name='KauSlideInRight' type='style' />
@@ -113,6 +107,12 @@
<public name='KauSlideInFadeOut' type='style' />
<public name='KauSlideInSlideOutRight' type='style' />
<public name='KauSlideInSlideOutBottom' type='style' />
- <public name='kau_transparent' type='drawable' />
- <public name='kau_selectable_white' type='drawable' />
+ <public name='kau_enter_slide_bottom' type='transition' />
+ <public name='kau_enter_slide_top' type='transition' />
+ <public name='kau_exit_slide_bottom' type='transition' />
+ <public name='kau_exit_slide_top' type='transition' />
+ <public name='kau_enter_slide_right' type='transition' />
+ <public name='kau_exit_slide_right' type='transition' />
+ <public name='kau_exit_slide_left' type='transition' />
+ <public name='kau_enter_slide_left' type='transition' />
</resources> \ No newline at end of file
diff --git a/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt b/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt
index e52838b..d800fcd 100644
--- a/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt
+++ b/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt
@@ -1,25 +1,24 @@
package ca.allanwang.fastadapter.databinding
-
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.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
-import ca.allanwang.gitdroid.logger.L
-import ca.allanwang.gitdroid.views.BR
-import com.bumptech.glide.Glide
+import ca.allanwang.kau.logging.KL
import com.mikepenz.fastadapter.FastAdapter
+import com.mikepenz.fastadapter.GenericItem
import com.mikepenz.fastadapter.items.AbstractItem
import com.mikepenz.fastadapter.listeners.ClickEventHook
-typealias GenericBindingItem = BindingItem<*>
+interface VhModel {
+ fun vh(): GenericItem
+}
-abstract class BindingItem<Binding : ViewDataBinding>(open val data: Any?) : AbstractItem<BindingItem.ViewHolder>(),
+abstract class BindingItem<Binding : ViewDataBinding>(open val data: Any?) :
+ AbstractItem<BindingItem.ViewHolder>(),
BindingLayout<Binding> {
override val type: Int
@@ -29,22 +28,22 @@ abstract class BindingItem<Binding : ViewDataBinding>(open val data: Any?) : Abs
val binding: ViewDataBinding = DataBindingUtil.inflate(
LayoutInflater.from(ctx),
layoutRes, parent,
- false,
- null
+ false
)
return binding.root
}
+ fun getBinding(holder: ViewHolder): Binding? =
+ DataBindingUtil.getBinding<Binding>(holder.itemView)
+
final override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
- val binding = DataBindingUtil.getBinding<Binding>(holder.itemView) ?: return
+ val binding = getBinding(holder) ?: return
binding.bindView(holder, payloads)
binding.executePendingBindings()
}
- open fun Binding.bindView(holder: ViewHolder, payloads: MutableList<Any>) {
- setVariable(BR.model, data)
- }
+ abstract fun Binding.bindView(holder: ViewHolder, payloads: MutableList<Any>)
final override fun unbindView(holder: ViewHolder) {
super.unbindView(holder)
@@ -58,40 +57,26 @@ abstract class BindingItem<Binding : ViewDataBinding>(open val data: Any?) : Abs
final override fun getViewHolder(v: View): ViewHolder = ViewHolder(v, layoutRes)
override fun failedToRecycle(holder: ViewHolder): Boolean {
- L.e { "Failed to recycle" }
+ KL.e { "Failed to recycle" }
return super.failedToRecycle(holder)
}
- companion object {
- @JvmStatic
- protected fun unbindGlide(vararg imageView: ImageView) {
- if (imageView.isEmpty()) {
- return
- }
- val manager = Glide.with(imageView.first().context)
- imageView.forEach { manager.clear(it) }
- }
-
- @JvmStatic
- protected fun unbind(vararg imageView: ImageView) {
- imageView.forEach { it.setImageDrawable(null) }
- }
-
- @JvmStatic
- protected fun unbind(vararg textView: TextView) {
- textView.forEach { it.text = null }
- }
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is BindingItem<*>) return false
+ return identifier == other.identifier && data == other.data
}
- class ViewHolder(itemView: View, internal val layoutRes: Int) : RecyclerView.ViewHolder(itemView)
+ override fun hashCode(): Int = data.hashCode()
+ class ViewHolder(itemView: View, internal val layoutRes: Int) :
+ RecyclerView.ViewHolder(itemView)
}
interface BindingLayout<Binding : ViewDataBinding> {
val layoutRes: Int
}
-
abstract class BindingClickEventHook<Binding : ViewDataBinding, Item : BindingItem<Binding>>(val identifier: BindingLayout<Binding>) :
ClickEventHook<Item>() {
@@ -111,7 +96,8 @@ abstract class BindingClickEventHook<Binding : ViewDataBinding, Item : BindingIt
final override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? =
viewHolder.binding()?.onBindMany(viewHolder) ?: super.onBindMany(viewHolder)
- open fun Binding.onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? = super.onBindMany(viewHolder)
+ open fun Binding.onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? =
+ super.onBindMany(viewHolder)
final override fun onClick(v: View, position: Int, fastAdapter: FastAdapter<Item>, item: Item) {
val binding: Binding = DataBindingUtil.findBinding(v) ?: return
diff --git a/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/FastBindingAdapter.kt b/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/FastBindingAdapter.kt
deleted file mode 100644
index 2270b5d..0000000
--- a/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/FastBindingAdapter.kt
+++ /dev/null
@@ -1,45 +0,0 @@
-package ca.allanwang.fastadapter.databinding
-
-import com.mikepenz.fastadapter.FastAdapter
-import com.mikepenz.fastadapter.IAdapter
-import com.mikepenz.fastadapter.IItemAdapter
-import com.mikepenz.fastadapter.adapters.ItemAdapter
-import com.mikepenz.fastadapter.diff.FastAdapterDiffUtil
-
-class FastBindingAdapter private constructor(private val adapter: ItemAdapter<GenericBindingItem>) :
- FastAdapter<GenericBindingItem>(),
- IItemAdapter<GenericBindingItem, GenericBindingItem> by adapter {
-
- constructor() : this(ItemAdapter())
-
- var lastClearTime: Long = -1
-
- init {
- super.addAdapter(0, adapter)
- }
-
- override fun clear(): FastBindingAdapter {
- if (itemCount != 0) {
- adapter.clear()
- lastClearTime = System.currentTimeMillis()
- }
- return this
- }
-
- override fun <A : IAdapter<GenericBindingItem>> addAdapter(
- index: Int,
- adapter: A
- ): FastAdapter<GenericBindingItem> {
- throw IllegalArgumentException("FastBindingAdapter only allows one adapter")
- }
-
- fun setWithDiff(items: List<GenericBindingItem>, detectMoves: Boolean = true) {
- FastAdapterDiffUtil.set(
- adapter,
- items,
- null,
- detectMoves
- )
- }
-
-} \ No newline at end of file