From df1f578cdffb5314bde26c7ffbedc6b1a1d96692 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 27 Jul 2019 19:45:00 -0700 Subject: Us genericitem where applicable --- .../src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt | 7 ++++--- .../main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt | 7 ++++--- .../main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt | 5 +++-- fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt | 7 ++++--- 4 files changed, 15 insertions(+), 11 deletions(-) (limited to 'fastadapter/src/main/kotlin') 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 14fdc9d..59832ed 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt @@ -16,6 +16,7 @@ package ca.allanwang.kau.adapters import com.mikepenz.fastadapter.FastAdapter +import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.IAdapter import com.mikepenz.fastadapter.IAdapterExtension import com.mikepenz.fastadapter.IItem @@ -28,14 +29,14 @@ import com.mikepenz.fastadapter.select.SelectExtension /** * Add kotlin's generic syntax to better support out types */ -fun > fastAdapter(vararg adapter: IAdapter) = +fun fastAdapter(vararg adapter: IAdapter) = FastAdapter.with>(adapter.toList()) /** * Returns selection size, or -1 if selection is disabled */ -inline val > IAdapter.selectionSize: Int +inline val IAdapter.selectionSize: Int get() = fastAdapter?.getExtension>()?.selections?.size ?: -1 -inline val > IAdapter.selectedItems: Set +inline val IAdapter.selectedItems: Set get() = fastAdapter?.getExtension>()?.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 24a37c4..e3f43ca 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt @@ -23,6 +23,7 @@ import android.widget.TextView import androidx.annotation.RequiresApi import ca.allanwang.kau.ui.createSimpleRippleDrawable import ca.allanwang.kau.utils.adjustAlpha +import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.IItemAdapter import com.mikepenz.fastadapter.adapters.FastItemAdapter @@ -36,7 +37,7 @@ import com.mikepenz.fastadapter.adapters.FastItemAdapter * This adapter overrides every method where an item is added * If that item extends [ThemableIItem], then the colors will be set */ -class FastItemThemedAdapter>( +class FastItemThemedAdapter( textColor: Int? = null, backgroundColor: Int? = null, accentColor: Int? = null @@ -85,11 +86,11 @@ class FastItemThemedAdapter>( notifyAdapterDataSetChanged() } - private fun injectTheme(items: Collection?>?) { + private fun injectTheme(items: Collection?) { items?.forEach { injectTheme(it) } } - protected fun injectTheme(item: IItem<*>?) { + protected fun injectTheme(item: GenericItem?) { if (item is ThemableIItem && item.themeEnabled) { item.textColor = textColor item.backgroundColor = backgroundColor 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 99c367b..3aca18b 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt @@ -19,13 +19,14 @@ import android.view.View import androidx.annotation.IntRange import com.mikepenz.fastadapter.ClickListener import com.mikepenz.fastadapter.FastAdapter +import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.IAdapter import com.mikepenz.fastadapter.IItem /** * Created by Allan Wang on 26/12/17. */ -fun > FastAdapter.withOnRepeatedClickListener( +fun FastAdapter.withOnRepeatedClickListener( count: Int, duration: Long, event: ClickListener @@ -39,7 +40,7 @@ fun > FastAdapter.withOnRepeatedClickListener( * each within [duration] from each other. * Only then will the [event] be fired, and everything will be reset. */ -private class RepeatedClickListener>( +private class RepeatedClickListener( @IntRange(from = 1) val count: Int, @IntRange(from = 1) val duration: Long, val event: ClickListener diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt index f9f06b9..040559c 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt @@ -34,6 +34,7 @@ import ca.allanwang.kau.utils.string import ca.allanwang.kau.utils.toDrawable import ca.allanwang.kau.utils.visible import com.mikepenz.fastadapter.FastAdapter +import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.listeners.ClickEventHook import com.mikepenz.iconics.typeface.IIcon @@ -51,13 +52,13 @@ class CardIItem( ), ThemableIItem by ThemableIItemDelegate() { companion object { - fun bindClickEvents(fastAdapter: FastAdapter>) { - fastAdapter.addEventHook(object : ClickEventHook>() { + fun bindClickEvents(fastAdapter: FastAdapter) { + fastAdapter.addEventHook(object : ClickEventHook() { override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List? { return if (viewHolder is ViewHolder) listOf(viewHolder.card, viewHolder.button) else null } - override fun onClick(v: View, position: Int, fastAdapter: FastAdapter>, item: IItem<*>) { + override fun onClick(v: View, position: Int, fastAdapter: FastAdapter, item: GenericItem) { if (item !is CardIItem) return with(item.configs) { when (v.id) { -- cgit v1.2.3