diff options
author | Allan Wang <me@allanwang.ca> | 2017-07-18 20:16:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-18 20:16:23 -0700 |
commit | 8f2b5ac043f47cc44f43c3788d1377083fb339a2 (patch) | |
tree | 8f91042414de211cbfe67a76298300884f46a765 /adapter/src/main/kotlin/ca/allanwang | |
parent | 4eee8d59c21b2061b9f5fd0e805ca60ab84c3585 (diff) | |
download | kau-8f2b5ac043f47cc44f43c3788d1377083fb339a2.tar.gz kau-8f2b5ac043f47cc44f43c3788d1377083fb339a2.tar.bz2 kau-8f2b5ac043f47cc44f43c3788d1377083fb339a2.zip |
Dev 2.1 (#8)
* Rewrite animation interfaces
* Update changelog
* Add scale factor for slide
* Remove margins in iitems and replace with decorators
* Remove mutable list
* Switch cardiitem to use lambdas for click
* status
* Utils update and imagepicker fixes
* Remove stringholder
* Add fade in fade out
* Increment about version
* Rename fromedge to direction in javadocs
* More logging
* Add logging and docs
* Make card icons visible
* Update email builder and icon padding
* Create elastic recycler activity
* Fix card iitem
* Add lint check and plurals
* Inline all the things
* Format and sort xml
* Update dependencies and increment version
Diffstat (limited to 'adapter/src/main/kotlin/ca/allanwang')
9 files changed, 235 insertions, 188 deletions
diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt index 1ceab3c..1349a35 100644 --- a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt +++ b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt @@ -58,7 +58,7 @@ class FastItemThemedAdapter<Item : IItem<*, *>>( notifyAdapterDataSetChanged() } - override fun add(position: Int, items: MutableList<Item>): FastItemAdapter<Item> { + override fun add(position: Int, items: List<Item>): FastItemAdapter<Item> { injectTheme(items) return super.add(position, items) } @@ -73,13 +73,12 @@ class FastItemThemedAdapter<Item : IItem<*, *>>( return super.add(item) } - override fun add(items: MutableList<Item>): FastItemAdapter<Item> { - injectTheme(items) + override fun add(items: List<Item>?): FastItemAdapter<Item> { injectTheme(items) return super.add(items) } - override fun set(items: MutableList<Item>?): FastItemAdapter<Item> { + override fun set(items: List<Item>?): FastItemAdapter<Item> { injectTheme(items) return super.set(items) } @@ -89,17 +88,17 @@ class FastItemThemedAdapter<Item : IItem<*, *>>( return super.set(position, item) } - override fun setNewList(items: MutableList<Item>?, retainFilter: Boolean): FastItemAdapter<Item> { + override fun setNewList(items: List<Item>?, retainFilter: Boolean): FastItemAdapter<Item> { injectTheme(items) return super.setNewList(items, retainFilter) } - override fun setNewList(items: MutableList<Item>?): FastItemAdapter<Item> { + override fun setNewList(items: List<Item>?): FastItemAdapter<Item> { injectTheme(items) return super.setNewList(items) } - override fun <T, S> setSubItems(collapsible: T, subItems: MutableList<S>?): T where S : IItem<*, *>?, T : IItem<*, *>?, T : IExpandable<T, S>?, S : ISubItem<Item, T>? { + override fun <T, S> setSubItems(collapsible: T, subItems: List<S>?): T where S : IItem<*, *>?, T : IItem<*, *>?, T : IExpandable<T, S>?, S : ISubItem<Item, T>? { injectTheme(subItems) return super.setSubItems(collapsible, subItems) } @@ -176,8 +175,8 @@ class ThemableIItemDelegate : ThemableIItem, ThemableIItemColors by ThemableIIte } override fun bindBackgroundRipple(vararg views: View?) { - val foreground = accentColor ?: textColor ?: return val background = backgroundColor ?: return + val foreground = accentColor ?: textColor ?: backgroundColor ?: return //default to normal background val ripple = createSimpleRippleDrawable(foreground, background) views.forEach { it?.background = ripple } } diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/animators/AnimatorInterfaces.kt b/adapter/src/main/kotlin/ca/allanwang/kau/animators/AnimatorInterfaces.kt new file mode 100644 index 0000000..3cf13df --- /dev/null +++ b/adapter/src/main/kotlin/ca/allanwang/kau/animators/AnimatorInterfaces.kt @@ -0,0 +1,31 @@ +package ca.allanwang.kau.animators + +import android.support.v7.widget.RecyclerView +import android.view.View +import android.view.ViewPropertyAnimator + +/** + * Created by Allan Wang on 2017-07-11. + */ +class KauAnimatorException(message: String) : RuntimeException(message) + +interface KauAnimatorAdd { + fun animationPrepare(holder: RecyclerView.ViewHolder): View.() -> Unit + fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit + fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit + fun getDelay(remove: Long, move: Long, change: Long): Long + var itemDelayFactor: Float +} + +interface KauAnimatorRemove { + fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit + fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit + fun getDelay(remove: Long, move: Long, change: Long): Long + var itemDelayFactor: Float +} + +interface KauAnimatorChange { + fun changeOldAnimation(holder: RecyclerView.ViewHolder, changeInfo: BaseItemAnimator.ChangeInfo): ViewPropertyAnimator.() -> Unit + fun changeNewAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit + fun changeAnimationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit +} diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/animators/BaseDelayAnimator.kt b/adapter/src/main/kotlin/ca/allanwang/kau/animators/BaseDelayAnimator.kt deleted file mode 100644 index c649376..0000000 --- a/adapter/src/main/kotlin/ca/allanwang/kau/animators/BaseDelayAnimator.kt +++ /dev/null @@ -1,45 +0,0 @@ -package ca.allanwang.kau.animators - -import android.support.v7.widget.RecyclerView -import android.view.ViewPropertyAnimator - -/** - * Created by Allan Wang on 2017-06-27. - * - * Base for delayed animators - * item delay factor by default can be 0.125f - */ -abstract class BaseDelayAnimator(val itemDelayFactor: Float) : DefaultAnimator() { - - override abstract fun addAnimationPrepare(holder: RecyclerView.ViewHolder) - - override fun addAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return holder.itemView.animate().apply { - startDelay = Math.max(0L, (holder.adapterPosition * addDuration * itemDelayFactor).toLong()) - duration = this@BaseDelayAnimator.addDuration - interpolator = this@BaseDelayAnimator.interpolator - } - } - - - override abstract fun addAnimationCleanup(holder: RecyclerView.ViewHolder) - - override fun getAddDelay(remove: Long, move: Long, change: Long): Long = 0 - - override fun getRemoveDelay(remove: Long, move: Long, change: Long): Long = 0 - - /** - * Partial removal animation - * As of now, all it does it change the alpha - * To have it slide, add onto it in a sub class - */ - override fun removeAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return holder.itemView.animate().apply { - duration = this@BaseDelayAnimator.removeDuration - startDelay = Math.max(0L, (holder.adapterPosition * removeDuration * itemDelayFactor).toLong()) - interpolator = this@BaseDelayAnimator.interpolator - } - } - - override abstract fun removeAnimationCleanup(holder: RecyclerView.ViewHolder) -}
\ No newline at end of file diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/animators/BaseSlideAlphaAnimator.kt b/adapter/src/main/kotlin/ca/allanwang/kau/animators/BaseSlideAlphaAnimator.kt deleted file mode 100644 index a963358..0000000 --- a/adapter/src/main/kotlin/ca/allanwang/kau/animators/BaseSlideAlphaAnimator.kt +++ /dev/null @@ -1,52 +0,0 @@ -package ca.allanwang.kau.animators - -import android.support.v7.widget.RecyclerView -import android.view.ViewPropertyAnimator - -/** - * Created by Allan Wang on 2017-06-27. - * - * Base for sliding animators - * item delay factor by default can be 0.125f - */ -abstract class BaseSlideAlphaAnimator(itemDelayFactor: Float) : BaseDelayAnimator(itemDelayFactor) { - - override fun addAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return super.addAnimation(holder).apply { - translationY(0f) - translationX(0f) - alpha(1f) - } - } - - final override fun addAnimationCleanup(holder: RecyclerView.ViewHolder) { - with(holder.itemView) { - translationY = 0f - translationX = 0f - alpha = 1f - } - } - - override fun getAddDelay(remove: Long, move: Long, change: Long): Long = 0 - - override fun getRemoveDelay(remove: Long, move: Long, change: Long): Long = 0 - - /** - * Partial removal animation - * As of now, all it does it change the alpha - * To have it slide, add onto it in a sub class - */ - override fun removeAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return super.addAnimation(holder).apply { - alpha(0f) - } - } - - override final fun removeAnimationCleanup(holder: RecyclerView.ViewHolder) { - with(holder.itemView) { - translationY = 0f - translationX = 0f - alpha = 1f - } - } -}
\ No newline at end of file diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/animators/FadeScaleAnimator.kt b/adapter/src/main/kotlin/ca/allanwang/kau/animators/FadeScaleAnimator.kt index e968cda..cc73100 100644 --- a/adapter/src/main/kotlin/ca/allanwang/kau/animators/FadeScaleAnimator.kt +++ b/adapter/src/main/kotlin/ca/allanwang/kau/animators/FadeScaleAnimator.kt @@ -1,51 +1,59 @@ package ca.allanwang.kau.animators import android.support.v7.widget.RecyclerView +import android.view.View import android.view.ViewPropertyAnimator /** - * Created by Allan Wang on 2017-06-29. + * Created by Allan Wang on 2017-07-11. */ -open class FadeScaleAnimator(val scaleFactor: Float = 0.7f, itemDelayFactor: Float = 0.125f) : BaseDelayAnimator(itemDelayFactor) { - - override fun addAnimationPrepare(holder: RecyclerView.ViewHolder) { - with(holder.itemView) { - scaleX = scaleFactor - scaleY = scaleFactor - alpha = 0f - } - } +class FadeScaleAnimatorAdd(val scaleFactor: Float = 1.0f, override var itemDelayFactor: Float = 0.125f) : KauAnimatorAdd { - override final fun addAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return super.addAnimation(holder).apply { - scaleX(1f) - scaleY(1f) - alpha(1f) - } + override fun animationPrepare(holder: RecyclerView.ViewHolder): View.() -> Unit = { + scaleX = scaleFactor + scaleY = scaleFactor + alpha = 0f } + override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { + scaleX(1f) + scaleY(1f) + alpha(1f) + } - final override fun addAnimationCleanup(holder: RecyclerView.ViewHolder) { - with(holder.itemView) { - scaleX = 1f - scaleY = 1f - alpha = 1f - } + override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { + scaleX = 1f + scaleY = 1f + alpha = 1f } - override fun removeAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return super.removeAnimation(holder).apply { - scaleX(scaleFactor) - scaleY(scaleFactor) - alpha(0f) - } + override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L + +} + +class FadeScaleAnimatorRemove(val scaleFactor: Float = 1.0f, override var itemDelayFactor: Float = 0.125f) : KauAnimatorRemove { + + override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { + scaleX(scaleFactor) + scaleY(scaleFactor) + alpha(0f) } - override final fun removeAnimationCleanup(holder: RecyclerView.ViewHolder) { - with(holder.itemView) { - translationY = 0f - translationX = 0f - alpha = 1f - } + override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { + scaleX = 1f + scaleY = 1f + alpha = 1f } + + override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L +} + +class FadeAnimatorChange : KauAnimatorChange { + + override fun changeOldAnimation(holder: RecyclerView.ViewHolder, changeInfo: BaseItemAnimator.ChangeInfo): ViewPropertyAnimator.() -> Unit = { alpha(0f) } + + override fun changeNewAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { alpha(1f) } + + override fun changeAnimationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { alpha = 1f } + }
\ No newline at end of file diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/animators/KauAnimator.kt b/adapter/src/main/kotlin/ca/allanwang/kau/animators/KauAnimator.kt new file mode 100644 index 0000000..5b36551 --- /dev/null +++ b/adapter/src/main/kotlin/ca/allanwang/kau/animators/KauAnimator.kt @@ -0,0 +1,76 @@ +package ca.allanwang.kau.animators + +import android.support.v7.widget.RecyclerView +import android.view.ViewPropertyAnimator +import ca.allanwang.kau.utils.KAU_BOTTOM +import ca.allanwang.kau.utils.KAU_RIGHT + +/** + * Created by Allan Wang on 2017-06-27. + */ +class KauAnimator( + val addAnimator: KauAnimatorAdd = SlideAnimatorAdd(KAU_BOTTOM), + val removeAnimator: KauAnimatorRemove = SlideAnimatorRemove(KAU_RIGHT), + val changeAnimator: KauAnimatorChange = FadeAnimatorChange() +) : BaseItemAnimator() { + + fun startDelay(holder: RecyclerView.ViewHolder, duration: Long, factor: Float) + = Math.max(0L, (holder.adapterPosition * duration * factor).toLong()) + + override fun removeAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { + return holder.itemView.animate().apply { + startDelay = startDelay(holder, removeDuration, removeAnimator.itemDelayFactor) + duration = removeDuration + interpolator = this@KauAnimator.interpolator + removeAnimator.animation(holder)() + } + } + + override fun removeAnimationCleanup(holder: RecyclerView.ViewHolder) { + holder.itemView.apply { removeAnimator.animationCleanup(holder)() } + } + + override fun getRemoveDelay(remove: Long, move: Long, change: Long): Long + = removeAnimator.getDelay(remove, move, change) + + override fun addAnimationPrepare(holder: RecyclerView.ViewHolder) { + holder.itemView.apply { addAnimator.animationPrepare(holder)() } + } + + override fun addAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { + return holder.itemView.animate().apply { + startDelay = startDelay(holder, addDuration, addAnimator.itemDelayFactor) + duration = addDuration + interpolator = this@KauAnimator.interpolator + addAnimator.animation(holder)() + } + } + + override fun addAnimationCleanup(holder: RecyclerView.ViewHolder) { + holder.itemView.apply { addAnimator.animationCleanup(holder)() } + } + + override fun getAddDelay(remove: Long, move: Long, change: Long): Long + = addAnimator.getDelay(remove, move, change) + + override fun changeOldAnimation(holder: RecyclerView.ViewHolder, changeInfo: ChangeInfo): ViewPropertyAnimator { + return holder.itemView.animate().apply { + duration = changeDuration + interpolator = this@KauAnimator.interpolator + changeAnimator.changeOldAnimation(holder, changeInfo)() + } + } + + override fun changeNewAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { + return holder.itemView.animate().apply { + duration = changeDuration + interpolator = this@KauAnimator.interpolator + changeAnimator.changeNewAnimation(holder)() + } + } + + override fun changeAnimationCleanup(holder: RecyclerView.ViewHolder) { + holder.itemView.apply { changeAnimator.changeAnimationCleanup(holder)() } + } + +}
\ No newline at end of file diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt b/adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt new file mode 100644 index 0000000..f8f71a5 --- /dev/null +++ b/adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt @@ -0,0 +1,64 @@ +package ca.allanwang.kau.animators + +import android.support.v7.widget.RecyclerView +import android.view.View +import android.view.ViewPropertyAnimator +import ca.allanwang.kau.utils.KAU_BOTTOM +import ca.allanwang.kau.utils.KAU_LEFT +import ca.allanwang.kau.utils.KAU_RIGHT +import ca.allanwang.kau.utils.KAU_TOP + +/** + * Created by Allan Wang on 2017-07-11. + */ +class SlideAnimatorAdd(val fromEdge: Int, val slideFactor: Float = 1f, override var itemDelayFactor: Float = 0.125f) : KauAnimatorAdd { + + override fun animationPrepare(holder: RecyclerView.ViewHolder): View.() -> Unit = { + when (fromEdge) { + KAU_TOP -> translationY = slideFactor * -height + KAU_LEFT -> translationX = slideFactor * -width + KAU_BOTTOM -> translationY = slideFactor * height + KAU_RIGHT -> translationX = slideFactor * width + else -> throw KauAnimatorException("Invalid edge flag used in Slide Animator; use one of KAU_*") + } + alpha = 0f + } + + override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { + translationY(0f) + translationX(0f) + alpha(1f) + } + + override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { + translationY = 0f + translationX = 0f + alpha = 1f + } + + override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L + +} + +class SlideAnimatorRemove(val fromEdge: Int, val slideFactor: Float = 1f, override var itemDelayFactor: Float = 0.125f) : KauAnimatorRemove { + override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { + with(holder.itemView) { + when (fromEdge) { + KAU_TOP -> translationY(slideFactor * -height) + KAU_LEFT -> translationX(slideFactor * -width) + KAU_BOTTOM -> translationY(slideFactor * height) + KAU_RIGHT -> translationX(slideFactor * width) + else -> throw KauAnimatorException("Invalid edge flag used in Slide Animator; use one of KAU_*") + } + } + alpha(0f) + } + + override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { + translationY = 0f + translationX = 0f + alpha = 1f + } + + override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L +}
\ No newline at end of file diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideUpExitRightAnimator.kt b/adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideUpExitRightAnimator.kt deleted file mode 100644 index 8670493..0000000 --- a/adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideUpExitRightAnimator.kt +++ /dev/null @@ -1,23 +0,0 @@ -package ca.allanwang.kau.animators - -import android.support.v7.widget.RecyclerView -import android.view.ViewPropertyAnimator - -/** - * Created by Allan Wang on 2017-06-27. - */ -class SlideUpExitRightAnimator(itemDelayFactor: Float = 0.125f) : BaseSlideAlphaAnimator(itemDelayFactor) { - - override fun addAnimationPrepare(holder: RecyclerView.ViewHolder) { - with(holder.itemView) { - translationY = height.toFloat() - alpha = 0f - } - } - - override fun removeAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return super.removeAnimation(holder).apply { - translationX(holder.itemView.width.toFloat()) - } - } -}
\ No newline at end of file diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt index 68b247c..85f86bd 100644 --- a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt +++ b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt @@ -15,7 +15,6 @@ import ca.allanwang.kau.adapters.ThemableIItemDelegate import ca.allanwang.kau.utils.* import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.IItem -import com.mikepenz.fastadapter.items.AbstractItem import com.mikepenz.fastadapter.listeners.ClickEventHook import com.mikepenz.iconics.typeface.IIcon @@ -25,22 +24,22 @@ import com.mikepenz.iconics.typeface.IIcon * Simple generic card item with an icon, title, description and button * The icon and button are hidden by default unless values are given */ -class CardIItem(val builder: Config.() -> Unit = {} -) : AbstractItem<CardIItem, CardIItem.ViewHolder>(), ThemableIItem by ThemableIItemDelegate() { +class CardIItem(val builder: Config.() -> Unit = {}) : KauIItem<CardIItem, CardIItem.ViewHolder>(R.layout.kau_iitem_card, { ViewHolder(it) }, R.id.kau_item_card), + ThemableIItem by ThemableIItemDelegate() { companion object { - @JvmStatic fun bindClickEvents(fastAdapter: FastAdapter<IItem<*,*>>) { - fastAdapter.withEventHook(object : ClickEventHook<IItem<*,*>>() { + @JvmStatic fun bindClickEvents(fastAdapter: FastAdapter<IItem<*, *>>) { + fastAdapter.withEventHook(object : ClickEventHook<IItem<*, *>>() { override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? { return if (viewHolder is ViewHolder) listOf(viewHolder.card, viewHolder.button) else null } - override fun onClick(v: View, position: Int, adapter: FastAdapter<IItem<*,*>>, item: IItem<*,*>) { + override fun onClick(v: View, position: Int, adapter: FastAdapter<IItem<*, *>>, item: IItem<*, *>) { if (item !is CardIItem) return with(item.configs) { when (v.id) { - R.id.kau_card_container -> cardClick?.onClick(v) - R.id.kau_card_button -> buttonClick?.onClick(v) + R.id.kau_card_container -> cardClick?.invoke() + R.id.kau_card_button -> buttonClick?.invoke() else -> { } } @@ -59,37 +58,29 @@ class CardIItem(val builder: Config.() -> Unit = {} var descRes: Int = -1 var button: String? = null var buttonRes: Int = -1 - var buttonClick: View.OnClickListener? = null - var cardClick: View.OnClickListener? = null + var buttonClick: (() -> Unit)? = null + var cardClick: (() -> Unit)? = null var image: Drawable? = null var imageIIcon: IIcon? = null var imageIIconColor: Int = Color.WHITE var imageRes: Int = -1 } - - override fun getType(): Int = R.id.kau_item_card - - override fun getLayoutRes(): Int = R.layout.kau_iitem_card - override fun bindView(holder: ViewHolder, payloads: MutableList<Any>?) { super.bindView(holder, payloads) with(holder.itemView.context) context@ { with(configs) { holder.title.text = string(titleRes, title) - holder.description.text = string(descRes, desc) + val descText = string(descRes, desc) + if (descText != null) holder.description.visible().text = descText val buttonText = string(buttonRes, button) if (buttonText != null) { holder.bottomRow.visible() holder.button.text = buttonText - holder.button.setOnClickListener(buttonClick) } - holder.icon.setImageDrawable( - if (imageRes > 0) drawable(imageRes) - else if (imageIIcon != null) imageIIcon!!.toDrawable(this@context, sizeDp = 40, color = imageIIconColor) - else image - ) - holder.card.setOnClickListener(cardClick) + val icon = if (imageRes > 0) drawable(imageRes) + else imageIIcon?.toDrawable(this@context, sizeDp = 24, color = imageIIconColor) ?: image + if (icon != null) holder.icon.visible().setImageDrawable(icon) } with(holder) { bindTextColor(title) @@ -106,15 +97,13 @@ class CardIItem(val builder: Config.() -> Unit = {} with(holder) { icon.gone().setImageDrawable(null) title.text = null - description.text = null + description.gone().text = null bottomRow.gone() button.setOnClickListener(null) card.setOnClickListener(null) } } - override fun getViewHolder(v: View): ViewHolder = ViewHolder(v) - class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { val card: CardView by bindView(R.id.kau_card_container) val icon: ImageView by bindView(R.id.kau_card_image) |