diff options
author | Allan Wang <me@allanwang.ca> | 2017-07-03 20:21:30 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-07-03 20:21:30 -0700 |
commit | c7e1a0ccbc5ab366b8d14720b0b5b0e7ab34c126 (patch) | |
tree | d4da56474163f4c2585fed024b3ebad36492942d /library | |
parent | 139f2dd8207d3a9cd67157a3e3754a9982c7f69d (diff) | |
download | kau-c7e1a0ccbc5ab366b8d14720b0b5b0e7ab34c126.tar.gz kau-c7e1a0ccbc5ab366b8d14720b0b5b0e7ab34c126.tar.bz2 kau-c7e1a0ccbc5ab366b8d14720b0b5b0e7ab34c126.zip |
Make themable null safe
Diffstat (limited to 'library')
3 files changed, 32 insertions, 29 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/library/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt index 83b8726..0fc590d 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt @@ -135,13 +135,13 @@ class ThemableIItemColorsDelegate : ThemableIItemColors { */ interface ThemableIItem : ThemableIItemColors { var themeEnabled: Boolean - fun bindTextColor(vararg views: TextView) - fun bindTextColorSecondary(vararg views: TextView) - fun bindDividerColor(vararg views: View) - fun bindAccentColor(vararg views: TextView) - fun bindBackgroundColor(vararg views: View) - fun bindBackgroundRipple(vararg views: View) - fun bindIconColor(vararg views: ImageView) + fun bindTextColor(vararg views: TextView?) + fun bindTextColorSecondary(vararg views: TextView?) + fun bindDividerColor(vararg views: View?) + fun bindAccentColor(vararg views: TextView?) + fun bindBackgroundColor(vararg views: View?) + fun bindBackgroundRipple(vararg views: View?) + fun bindIconColor(vararg views: ImageView?) } /** @@ -150,40 +150,40 @@ interface ThemableIItem : ThemableIItemColors { class ThemableIItemDelegate : ThemableIItem, ThemableIItemColors by ThemableIItemColorsDelegate() { override var themeEnabled: Boolean = true - override fun bindTextColor(vararg views: TextView) { + override fun bindTextColor(vararg views: TextView?) { val color = textColor ?: return - views.forEach { it.setTextColor(color) } + views.forEach { it?.setTextColor(color) } } - override fun bindTextColorSecondary(vararg views: TextView) { + override fun bindTextColorSecondary(vararg views: TextView?) { val color = textColor?.adjustAlpha(0.8f) ?: return - views.forEach { it.setTextColor(color) } + views.forEach { it?.setTextColor(color) } } - override fun bindAccentColor(vararg views: TextView) { + override fun bindAccentColor(vararg views: TextView?) { val color = accentColor ?: textColor ?: return - views.forEach { it.setTextColor(color) } + views.forEach { it?.setTextColor(color) } } - override fun bindDividerColor(vararg views: View) { + override fun bindDividerColor(vararg views: View?) { val color = (textColor ?: accentColor)?.adjustAlpha(0.1f) ?: return - views.forEach { it.setBackgroundColor(color) } + views.forEach { it?.setBackgroundColor(color) } } - override fun bindBackgroundColor(vararg views: View) { + override fun bindBackgroundColor(vararg views: View?) { val color = backgroundColor ?: return - views.forEach { it.setBackgroundColor(color) } + views.forEach { it?.setBackgroundColor(color) } } - override fun bindBackgroundRipple(vararg views: View) { + override fun bindBackgroundRipple(vararg views: View?) { val foreground = accentColor ?: textColor ?: return val background = backgroundColor ?: return val ripple = createSimpleRippleDrawable(foreground, background) - views.forEach { it.background = ripple } + views.forEach { it?.background = ripple } } - override fun bindIconColor(vararg views: ImageView) { + override fun bindIconColor(vararg views: ImageView?) { val color = accentColor ?: textColor ?: return - views.forEach { it.drawable.setTintList(ColorStateList.valueOf(color)) } + views.forEach { it?.drawable.setTintList(ColorStateList.valueOf(color)) } } }
\ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt index 7d0f9f7..3c4a052 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt @@ -12,6 +12,8 @@ import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView import ca.allanwang.kau.R +import ca.allanwang.kau.adapters.ThemableIItem +import ca.allanwang.kau.adapters.ThemableIItemDelegate import ca.allanwang.kau.kpref.GlobalOptions import ca.allanwang.kau.kpref.KPrefMarker import ca.allanwang.kau.utils.* @@ -24,7 +26,8 @@ import com.mikepenz.iconics.typeface.IIcon * Core class containing nothing but the view items */ -abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCore, KPrefItemCore.ViewHolder>() { +abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCore, KPrefItemCore.ViewHolder>(), + ThemableIItem by ThemableIItemDelegate() { override final fun getViewHolder(v: View) = ViewHolder(v) @@ -50,6 +53,7 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCor if (accentColor != null) { icon?.drawable?.setTint(accentColor) } + bindTextColor(title, desc) onPostBindView(this, textColor, accentColor) } } diff --git a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt index 8c5ad0a..95a38da 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt @@ -11,6 +11,7 @@ import android.view.View import android.widget.ImageView import android.widget.TextView import ca.allanwang.kau.R +import ca.allanwang.kau.iitems.KotlinIItem import ca.allanwang.kau.utils.* import com.mikepenz.fastadapter.items.AbstractItem import com.mikepenz.google_material_typeface_library.GoogleMaterial @@ -28,7 +29,11 @@ class SearchItem(val key: String, val description: String? = null, val iicon: IIcon? = GoogleMaterial.Icon.gmd_search, val image: Drawable? = null -) : AbstractItem<SearchItem, SearchItem.ViewHolder>() { +) : KotlinIItem<SearchItem, SearchItem.ViewHolder>( + R.id.kau_item_search, + R.layout.kau_search_iitem, + {ViewHolder(it)} +) { companion object { @JvmStatic var foregroundColor: Int = 0xdd000000.toInt() @@ -47,12 +52,6 @@ class SearchItem(val key: String, styledContent!!.setSpan(StyleSpan(Typeface.BOLD), index, index + subText.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) } - override fun getLayoutRes(): Int = R.layout.kau_search_iitem - - override fun getType(): Int = R.id.kau_item_search - - override fun getViewHolder(v: View): ViewHolder = ViewHolder(v) - override fun bindView(holder: ViewHolder, payloads: MutableList<Any>?) { super.bindView(holder, payloads) holder.title.setTextColor(foregroundColor) |