From 8f2b5ac043f47cc44f43c3788d1377083fb339a2 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 18 Jul 2017 20:16:23 -0700 Subject: 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 --- .../kau/adapters/FastItemThemedAdapter.kt | 15 ++--- .../allanwang/kau/animators/AnimatorInterfaces.kt | 31 +++++++++ .../allanwang/kau/animators/BaseDelayAnimator.kt | 45 ------------- .../kau/animators/BaseSlideAlphaAnimator.kt | 52 --------------- .../allanwang/kau/animators/FadeScaleAnimator.kt | 76 ++++++++++++---------- .../ca/allanwang/kau/animators/KauAnimator.kt | 76 ++++++++++++++++++++++ .../ca/allanwang/kau/animators/SlideAnimator.kt | 64 ++++++++++++++++++ .../kau/animators/SlideUpExitRightAnimator.kt | 23 ------- .../kotlin/ca/allanwang/kau/iitems/CardIItem.kt | 41 +++++------- adapter/src/main/res/layout/kau_iitem_card.xml | 33 ++++------ adapter/src/main/res/layout/kau_iitem_header.xml | 1 - 11 files changed, 249 insertions(+), 208 deletions(-) create mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/animators/AnimatorInterfaces.kt delete mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/animators/BaseDelayAnimator.kt delete mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/animators/BaseSlideAlphaAnimator.kt create mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/animators/KauAnimator.kt create mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt delete mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideUpExitRightAnimator.kt (limited to 'adapter/src/main') 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>( notifyAdapterDataSetChanged() } - override fun add(position: Int, items: MutableList): FastItemAdapter { + override fun add(position: Int, items: List): FastItemAdapter { injectTheme(items) return super.add(position, items) } @@ -73,13 +73,12 @@ class FastItemThemedAdapter>( return super.add(item) } - override fun add(items: MutableList): FastItemAdapter { - injectTheme(items) + override fun add(items: List?): FastItemAdapter { injectTheme(items) return super.add(items) } - override fun set(items: MutableList?): FastItemAdapter { + override fun set(items: List?): FastItemAdapter { injectTheme(items) return super.set(items) } @@ -89,17 +88,17 @@ class FastItemThemedAdapter>( return super.set(position, item) } - override fun setNewList(items: MutableList?, retainFilter: Boolean): FastItemAdapter { + override fun setNewList(items: List?, retainFilter: Boolean): FastItemAdapter { injectTheme(items) return super.setNewList(items, retainFilter) } - override fun setNewList(items: MutableList?): FastItemAdapter { + override fun setNewList(items: List?): FastItemAdapter { injectTheme(items) return super.setNewList(items) } - override fun setSubItems(collapsible: T, subItems: MutableList?): T where S : IItem<*, *>?, T : IItem<*, *>?, T : IExpandable?, S : ISubItem? { + override fun setSubItems(collapsible: T, subItems: List?): T where S : IItem<*, *>?, T : IItem<*, *>?, T : IExpandable?, S : ISubItem? { 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(), ThemableIItem by ThemableIItemDelegate() { +class CardIItem(val builder: Config.() -> Unit = {}) : KauIItem(R.layout.kau_iitem_card, { ViewHolder(it) }, R.id.kau_item_card), + ThemableIItem by ThemableIItemDelegate() { companion object { - @JvmStatic fun bindClickEvents(fastAdapter: FastAdapter>) { - fastAdapter.withEventHook(object : ClickEventHook>() { + @JvmStatic fun bindClickEvents(fastAdapter: FastAdapter>) { + fastAdapter.withEventHook(object : ClickEventHook>() { override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List? { return if (viewHolder is ViewHolder) listOf(viewHolder.card, viewHolder.button) else null } - override fun onClick(v: View, position: Int, adapter: FastAdapter>, item: IItem<*,*>) { + override fun onClick(v: View, position: Int, adapter: FastAdapter>, 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?) { 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) diff --git a/adapter/src/main/res/layout/kau_iitem_card.xml b/adapter/src/main/res/layout/kau_iitem_card.xml index 621da2e..249f3b8 100644 --- a/adapter/src/main/res/layout/kau_iitem_card.xml +++ b/adapter/src/main/res/layout/kau_iitem_card.xml @@ -8,29 +8,27 @@ android:id="@+id/kau_card_container" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/kau_padding_normal" android:background="?android:selectableItemBackground" android:minHeight="?android:listPreferredItemHeight"> + android:padding="@dimen/kau_padding_normal"> - + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0" /> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@id/kau_card_title" /> + app:layout_constraintTop_toBottomOf="@id/kau_card_description">