aboutsummaryrefslogtreecommitdiff
path: root/fastadapter/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <allanwang@google.com>2019-07-27 18:59:14 -0700
committerAllan Wang <allanwang@google.com>2019-07-27 18:59:14 -0700
commit63f6b70cc81ec9dc6e92b6521dfd78fa72fe70a5 (patch)
treea7fdc9cd1ec78a6bd43c80fec33896a3d427d2b6 /fastadapter/src/main/kotlin
parent99f1e76a4d8d35d4d3ca1aadf68bbc227a70ba01 (diff)
downloadkau-63f6b70cc81ec9dc6e92b6521dfd78fa72fe70a5.tar.gz
kau-63f6b70cc81ec9dc6e92b6521dfd78fa72fe70a5.tar.bz2
kau-63f6b70cc81ec9dc6e92b6521dfd78fa72fe70a5.zip
Fix compile errors
Diffstat (limited to 'fastadapter/src/main/kotlin')
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt7
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt34
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt18
3 files changed, 29 insertions, 30 deletions
diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
index 42fe1a2..14fdc9d 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
@@ -31,14 +31,11 @@ import com.mikepenz.fastadapter.select.SelectExtension
fun <Item : IItem<*>> fastAdapter(vararg adapter: IAdapter<out Item>) =
FastAdapter.with<Item, IAdapter<out Item>>(adapter.toList())
-inline fun <reified T : IAdapterExtension<Item>, Item : IItem<*>> FastAdapter<Item>.getExtension(): T? =
- getExtension(T::class.java)
-
/**
* Returns selection size, or -1 if selection is disabled
*/
inline val <Item : IItem<*>> IAdapter<Item>.selectionSize: Int
- get() = fastAdapter?.getExtension<SelectExtension<Item>, Item>()?.selections?.size ?: -1
+ get() = fastAdapter?.getExtension<SelectExtension<Item>>()?.selections?.size ?: -1
inline val <Item : IItem<*>> IAdapter<Item>.selectedItems: Set<Item>
- get() = fastAdapter?.getExtension<SelectExtension<Item>, Item>()?.selectedItems ?: emptySet()
+ get() = fastAdapter?.getExtension<SelectExtension<Item>>()?.selectedItems ?: emptySet()
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 01ac0e5..e6d4b24 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
@@ -24,6 +24,7 @@ import androidx.annotation.RequiresApi
import ca.allanwang.kau.ui.createSimpleRippleDrawable
import ca.allanwang.kau.utils.adjustAlpha
import com.mikepenz.fastadapter.IItem
+import com.mikepenz.fastadapter.IItemAdapter
import com.mikepenz.fastadapter.adapters.FastItemAdapter
/**
@@ -40,7 +41,11 @@ class FastItemThemedAdapter<Item : IItem<*>>(
backgroundColor: Int? = null,
accentColor: Int? = null
) : FastItemAdapter<Item>() {
- constructor(colors: ThemableIItemColors) : this(colors.textColor, colors.backgroundColor, colors.accentColor)
+ constructor(colors: ThemableIItemColors) : this(
+ colors.textColor,
+ colors.backgroundColor,
+ colors.accentColor
+ )
var textColor: Int? = textColor
set(value) {
@@ -73,46 +78,41 @@ class FastItemThemedAdapter<Item : IItem<*>>(
notifyAdapterDataSetChanged()
}
- override fun add(position: Int, items: List<Item>): FastItemAdapter<Item> {
+ override fun add(position: Int, items: List<Item>): IItemAdapter<Item, Item> {
injectTheme(items)
return super.add(position, items)
}
- override fun add(position: Int, item: Item): FastItemAdapter<Item> {
- injectTheme(item)
- return super.add(position, item)
+ override fun add(position: Int, vararg items: Item): IItemAdapter<Item, Item> {
+ injectTheme(items.toList())
+ return super.add(position, *items)
}
- override fun add(item: Item): FastItemAdapter<Item> {
- injectTheme(item)
- return super.add(item)
+ override fun add(vararg items: Item): IItemAdapter<Item, Item> {
+ injectTheme(items.toList())
+ return super.add(*items)
}
- override fun add(items: List<Item>?): FastItemAdapter<Item> {
+ override fun add(items: List<Item>): IItemAdapter<Item, Item> {
injectTheme(items)
return super.add(items)
}
- override fun set(items: List<Item>?): FastItemAdapter<Item> {
+ override fun set(items: List<Item>): IItemAdapter<Item, Item> {
injectTheme(items)
return super.set(items)
}
- override fun set(position: Int, item: Item): FastItemAdapter<Item> {
+ 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): FastItemAdapter<Item> {
+ override fun setNewList(items: List<Item>, retainFilter: Boolean): IItemAdapter<Item, Item> {
injectTheme(items)
return super.setNewList(items, retainFilter)
}
- override fun setNewList(items: List<Item>?): FastItemAdapter<Item> {
- injectTheme(items)
- return super.setNewList(items)
- }
-
private fun injectTheme(items: Collection<IItem<*>?>?) {
items?.forEach { injectTheme(it) }
}
diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt
index 3e7d707..99c367b 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt
@@ -17,10 +17,10 @@ package ca.allanwang.kau.adapters
import android.view.View
import androidx.annotation.IntRange
+import com.mikepenz.fastadapter.ClickListener
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.IAdapter
import com.mikepenz.fastadapter.IItem
-import com.mikepenz.fastadapter.listeners.OnClickListener
/**
* Created by Allan Wang on 26/12/17.
@@ -28,9 +28,11 @@ import com.mikepenz.fastadapter.listeners.OnClickListener
fun <Item : IItem<*>> FastAdapter<Item>.withOnRepeatedClickListener(
count: Int,
duration: Long,
- event: OnClickListener<Item>
-) =
- withOnClickListener(RepeatedClickListener(count, duration, event))
+ event: ClickListener<Item>
+): FastAdapter<Item> {
+ onClickListener = RepeatedClickListener(count, duration, event)
+ return this
+}
/**
* Registers and skips each click until the designated [count] clicks are triggered,
@@ -40,8 +42,8 @@ fun <Item : IItem<*>> FastAdapter<Item>.withOnRepeatedClickListener(
private class RepeatedClickListener<Item : IItem<*>>(
@IntRange(from = 1) val count: Int,
@IntRange(from = 1) val duration: Long,
- val event: OnClickListener<Item>
-) : OnClickListener<Item> {
+ val event: ClickListener<Item>
+) : ClickListener<Item> {
init {
if (count <= 0)
@@ -53,7 +55,7 @@ private class RepeatedClickListener<Item : IItem<*>>(
private var chain = 0
private var time = -1L
- override fun onClick(v: View?, adapter: IAdapter<Item>, item: Item, position: Int): Boolean {
+ override fun invoke(v: View?, adapter: IAdapter<Item>, item: Item, position: Int): Boolean {
val now = System.currentTimeMillis()
if (time - now < duration)
chain++
@@ -62,7 +64,7 @@ private class RepeatedClickListener<Item : IItem<*>>(
time = now
if (chain == count) {
chain = 0
- event.onClick(v, adapter, item, position)
+ event(v, adapter, item, position)
return true
}
return false