aboutsummaryrefslogtreecommitdiff
path: root/adapter
diff options
context:
space:
mode:
Diffstat (limited to 'adapter')
-rw-r--r--adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt17
-rw-r--r--adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt13
-rw-r--r--adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt3
-rw-r--r--adapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt2
4 files changed, 26 insertions, 9 deletions
diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
index 2f25d8c..b754cb4 100644
--- a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
+++ b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
@@ -1,9 +1,10 @@
package ca.allanwang.kau.adapters
-import android.view.View
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.IAdapter
+import com.mikepenz.fastadapter.IAdapterExtension
import com.mikepenz.fastadapter.IItem
+import com.mikepenz.fastadapter.select.SelectExtension
/**
* Created by Allan Wang on 2017-11-08.
@@ -13,4 +14,16 @@ import com.mikepenz.fastadapter.IItem
* Add kotlin's generic syntax to better support out types
*/
fun <Item : IItem<*, *>> fastAdapter(vararg adapter: IAdapter<out Item>) =
- FastAdapter.with<Item, IAdapter<out Item>>(adapter.toList())!! \ No newline at end of file
+ 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
+
+inline val <Item : IItem<*, *>> IAdapter<Item>.selectedItems: Set<Item>
+ get() = fastAdapter.getExtension<SelectExtension<Item>, Item>()?.selectedItems ?: emptySet()
diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
index 6ce81a3..9fd5512 100644
--- a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
+++ b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
@@ -56,17 +56,17 @@ class CardIItem(
class Config {
var title: String? = null
- var titleRes: Int = -1
+ var titleRes: Int = INVALID_ID
var desc: String? = null
- var descRes: Int = -1
+ var descRes: Int = INVALID_ID
var button: String? = null
- var buttonRes: Int = -1
+ var buttonRes: Int = INVALID_ID
var buttonClick: (() -> Unit)? = null
var cardClick: (() -> Unit)? = null
var image: Drawable? = null
var imageIIcon: IIcon? = null
var imageIIconColor: Int = Color.WHITE
- var imageRes: Int = -1
+ var imageRes: Int = INVALID_ID
}
override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
@@ -81,8 +81,9 @@ class CardIItem(
holder.bottomRow.visible()
holder.button.text = buttonText
}
- val icon = if (imageRes > 0) drawable(imageRes)
- else imageIIcon?.toDrawable(this@context, sizeDp = 24, color = imageIIconColor) ?: image
+ val icon = drawable(imageRes) {
+ imageIIcon?.toDrawable(this@context, sizeDp = 24, color = imageIIconColor) ?: image
+ }
if (icon != null) holder.icon.visible().setImageDrawable(icon)
}
with(holder) {
diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt
index 8367e7c..67e7d30 100644
--- a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt
+++ b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt
@@ -7,6 +7,7 @@ import android.widget.TextView
import ca.allanwang.kau.adapter.R
import ca.allanwang.kau.adapters.ThemableIItem
import ca.allanwang.kau.adapters.ThemableIItemDelegate
+import ca.allanwang.kau.utils.INVALID_ID
import ca.allanwang.kau.utils.bindView
import ca.allanwang.kau.utils.string
@@ -17,7 +18,7 @@ import ca.allanwang.kau.utils.string
* Contains only one text view
*/
class HeaderIItem(
- text: String? = null, var textRes: Int = -1
+ text: String? = null, var textRes: Int = INVALID_ID
) : KauIItem<HeaderIItem, HeaderIItem.ViewHolder>(
R.layout.kau_iitem_header, { ViewHolder(it) }, R.id.kau_item_header_big_margin_top
), ThemableIItem by ThemableIItemDelegate() {
diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt
index c01dea4..196959c 100644
--- a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt
+++ b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt
@@ -1,5 +1,6 @@
package ca.allanwang.kau.iitems
+import android.annotation.SuppressLint
import android.support.annotation.LayoutRes
import android.support.v7.widget.RecyclerView
import android.view.View
@@ -18,6 +19,7 @@ open class KauIItem<Item, VH : RecyclerView.ViewHolder>(
private val viewHolder: (v: View) -> VH,
private val type: Int = layoutRes
) : AbstractItem<Item, VH>() where Item : IItem<*, *>, Item : IClickable<*> {
+ @SuppressLint("ResourceType")
final override fun getType(): Int = type
final override fun getViewHolder(v: View): VH = viewHolder(v)
final override fun getLayoutRes(): Int = layoutRes