aboutsummaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
Diffstat (limited to 'library')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt42
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt6
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt13
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)