From 1d71665d55876980ae0926d55b537db62cba4b17 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 31 Dec 2019 19:45:06 -0800 Subject: Apply tint list in setIcon --- .../kotlin/ca/allanwang/kau/utils/ViewUtils.kt | 31 +++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt index d576be1..a1b96f5 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt @@ -20,6 +20,7 @@ package ca.allanwang.kau.utils import android.animation.ValueAnimator import android.annotation.SuppressLint import android.content.Context +import android.content.res.ColorStateList import android.graphics.Color import android.os.Build import android.view.LayoutInflater @@ -66,7 +67,8 @@ inline fun T.gone(): T { } @KauUtils -inline fun T.invisibleIf(invisible: Boolean): T = if (invisible) invisible() else visible() +inline fun T.invisibleIf(invisible: Boolean): T = + if (invisible) invisible() else visible() @KauUtils inline fun T.visibleIf(visible: Boolean): T = if (visible) visible() else gone() @@ -87,16 +89,24 @@ inline val View.isGone: Boolean get() = visibility == View.GONE @KauUtils -inline fun View.setBackgroundColorRes(@ColorRes color: Int) = setBackgroundColor(context.color(color)) +inline fun View.setBackgroundColorRes(@ColorRes color: Int) = + setBackgroundColor(context.color(color)) -fun View.snackbar(text: String, duration: Int = Snackbar.LENGTH_LONG, builder: Snackbar.() -> Unit = {}): Snackbar { +fun View.snackbar( + text: String, + duration: Int = Snackbar.LENGTH_LONG, + builder: Snackbar.() -> Unit = {} +): Snackbar { val snackbar = Snackbar.make(this, text, duration) snackbar.builder() snackbar.show() return snackbar } -fun View.snackbar(@StringRes textId: Int, duration: Int = Snackbar.LENGTH_LONG, builder: Snackbar.() -> Unit = {}) = +fun View.snackbar( + @StringRes textId: Int, duration: Int = Snackbar.LENGTH_LONG, + builder: Snackbar.() -> Unit = {} +) = snackbar(context.string(textId), duration, builder) @KauUtils @@ -108,6 +118,9 @@ fun ImageView.setIcon( ) { icon ?: return setImageDrawable(icon.toDrawable(context, sizeDp = sizeDp, color = color, builder = builder)) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + imageTintList = ColorStateList.valueOf(color) + } } @KauUtils @@ -270,11 +283,17 @@ inline val TextInputEditText.value: String get() = text.toString().trim() /** * Generates a recycler view with match parent and a linearlayoutmanager, since it's so commonly used */ -fun Context.fullLinearRecycler(rvAdapter: RecyclerView.Adapter<*>? = null, configs: RecyclerView.() -> Unit = {}) = +fun Context.fullLinearRecycler( + rvAdapter: RecyclerView.Adapter<*>? = null, + configs: RecyclerView.() -> Unit = {} +) = RecyclerView(this).apply { layoutManager = LinearLayoutManager(this@fullLinearRecycler) layoutParams = - RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.MATCH_PARENT) + RecyclerView.LayoutParams( + RecyclerView.LayoutParams.MATCH_PARENT, + RecyclerView.LayoutParams.MATCH_PARENT + ) if (rvAdapter != null) { adapter = rvAdapter } -- cgit v1.2.3