aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <allanwang@google.com>2019-07-27 19:16:00 -0700
committerAllan Wang <allanwang@google.com>2019-07-27 19:16:00 -0700
commit6a599e553a467f15be7ed60c554f43aeac5936ca (patch)
tree897a5a31564a79833befb4468b294a2f5a01a4b7
parent63f6b70cc81ec9dc6e92b6521dfd78fa72fe70a5 (diff)
downloadkau-6a599e553a467f15be7ed60c554f43aeac5936ca.tar.gz
kau-6a599e553a467f15be7ed60c554f43aeac5936ca.tar.bz2
kau-6a599e553a467f15be7ed60c554f43aeac5936ca.zip
Fix theme injection
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt27
-rw-r--r--docs/Changelog.md3
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt42
-rw-r--r--sample/src/main/res/xml/kau_changelog.xml5
4 files changed, 31 insertions, 46 deletions
diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt
index 4873f6e..96b9884 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt
@@ -37,7 +37,7 @@ import com.mikepenz.fastadapter.select.getSelectExtension
/**
* Created by Allan Wang on 2017-08-02.
*/
-class FaqIItem(val content: FaqItem) : KauIItem< FaqIItem.ViewHolder>(
+class FaqIItem(val content: FaqItem) : KauIItem<FaqIItem.ViewHolder>(
R.layout.kau_iitem_faq, ::ViewHolder, R.id.kau_item_faq
), ThemableIItem by ThemableIItemDelegate() {
@@ -46,16 +46,21 @@ class FaqIItem(val content: FaqItem) : KauIItem< FaqIItem.ViewHolder>(
fastAdapter.getSelectExtension().isSelectable = true
fastAdapter.addEventHook(object : ClickEventHook<IItem<*>>() {
- override fun onBind(viewHolder: RecyclerView.ViewHolder): View? =
- (viewHolder as? ViewHolder)?.questionContainer
+ override fun onBind(viewHolder: RecyclerView.ViewHolder): View? =
+ (viewHolder as? ViewHolder)?.questionContainer
- override fun onClick(v: View, position: Int, fastAdapter: FastAdapter<IItem<*>>, item: IItem<*>) {
- if (item !is FaqIItem) return
- item.isExpanded = !item.isExpanded
- v.parentViewGroup.findViewById<CollapsibleTextView>(R.id.faq_item_answer)
- .setExpanded(item.isExpanded)
- }
- })
+ override fun onClick(
+ v: View,
+ position: Int,
+ fastAdapter: FastAdapter<IItem<*>>,
+ item: IItem<*>
+ ) {
+ if (item !is FaqIItem) return
+ item.isExpanded = !item.isExpanded
+ v.parentViewGroup.findViewById<CollapsibleTextView>(R.id.faq_item_answer)
+ .setExpanded(item.isExpanded)
+ }
+ })
}
}
@@ -70,7 +75,7 @@ class FaqIItem(val content: FaqItem) : KauIItem< FaqIItem.ViewHolder>(
answer.setExpanded(isExpanded, false)
if (accentColor != null) answer.setLinkTextColor(accentColor!!)
answer.text = content.answer
- answer.post { answer.setPaddingLeft(16.dpToPx + number.width) }
+ answer.post { answer.setPaddingLeft(16.dpToPx + number.width) } // TODO not performant at all; and doesn't align across all items
bindTextColor(number, question)
bindTextColorSecondary(answer)
val bg2 = backgroundColor?.colorToForeground(0.1f)
diff --git a/docs/Changelog.md b/docs/Changelog.md
index f8287ca..0078430 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -1,5 +1,8 @@
# Changelog
+## v5.2.0
+* :fastadapter: Migrate fastadapter to v4.x.x
+
## v5.1.0
* :adapter: Moved fastadapter elements to new module, :fastadapter:. To migrate, simply rename the dependency. If you don't use fast adapter, no changes are necessary
* :adapter: Make NoAnimatorChange an object; previously a class
diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
index e6d4b24..24a37c4 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
@@ -47,6 +47,13 @@ class FastItemThemedAdapter<Item : IItem<*>>(
colors.accentColor
)
+ init {
+ itemAdapter.interceptor = {
+ injectTheme(it)
+ it
+ }
+ }
+
var textColor: Int? = textColor
set(value) {
if (field == value) return
@@ -78,41 +85,6 @@ class FastItemThemedAdapter<Item : IItem<*>>(
notifyAdapterDataSetChanged()
}
- override fun add(position: Int, items: List<Item>): IItemAdapter<Item, Item> {
- injectTheme(items)
- return super.add(position, items)
- }
-
- override fun add(position: Int, vararg items: Item): IItemAdapter<Item, Item> {
- injectTheme(items.toList())
- return super.add(position, *items)
- }
-
- override fun add(vararg items: Item): IItemAdapter<Item, Item> {
- injectTheme(items.toList())
- return super.add(*items)
- }
-
- override fun add(items: List<Item>): IItemAdapter<Item, Item> {
- injectTheme(items)
- return super.add(items)
- }
-
- override fun set(items: List<Item>): IItemAdapter<Item, Item> {
- injectTheme(items)
- return super.set(items)
- }
-
- override fun set(position: Int, item: Item): IItemAdapter<Item, Item> {
- injectTheme(item)
- return super.set(position, item)
- }
-
- override fun setNewList(items: List<Item>, retainFilter: Boolean): IItemAdapter<Item, Item> {
- injectTheme(items)
- return super.setNewList(items, retainFilter)
- }
-
private fun injectTheme(items: Collection<IItem<*>?>?) {
items?.forEach { injectTheme(it) }
}
diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml
index 62614ed..de73b41 100644
--- a/sample/src/main/res/xml/kau_changelog.xml
+++ b/sample/src/main/res/xml/kau_changelog.xml
@@ -6,6 +6,11 @@
<item text="" />
-->
+ <version title="v5.2.0" />
+ <item text=":fastadapter: Migrate fastadapter to v4.x.x" />
+ <item text="" />
+ <item text="" />
+
<version title="v5.1.0" />
<item text=":adapter: Moved fastadapter elements to new module, :fastadapter:. To migrate, simply rename the dependency. If you don't use fast adapter, no changes are necessary" />
<item text=":adapter: Make NoAnimatorChange an object; previously a class" />