aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
diff options
context:
space:
mode:
Diffstat (limited to 'library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt30
1 files changed, 20 insertions, 10 deletions
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 f8b6ab6..6fea9b0 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
@@ -1,14 +1,13 @@
package ca.allanwang.kau.searchview
+import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import ca.allanwang.kau.R
-import ca.allanwang.kau.utils.bindView
-import ca.allanwang.kau.utils.setIcon
-import ca.allanwang.kau.views.SimpleRippleDrawable
+import ca.allanwang.kau.utils.*
import com.mikepenz.fastadapter.items.AbstractItem
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.mikepenz.iconics.typeface.IIcon
@@ -20,7 +19,11 @@ import com.mikepenz.iconics.typeface.IIcon
* Contains a [key] which acts as a unique identifier (eg url)
* and a [content] which is displayed in the item
*/
-class SearchItem(val key: String, val content: String = key, val iicon: IIcon? = GoogleMaterial.Icon.gmd_search
+class SearchItem(val key: String,
+ val content: String = key,
+ val description: String? = null,
+ val iicon: IIcon? = GoogleMaterial.Icon.gmd_search,
+ val image: Drawable? = null
) : AbstractItem<SearchItem, SearchItem.ViewHolder>() {
companion object {
@@ -36,21 +39,28 @@ class SearchItem(val key: String, val content: String = key, val iicon: IIcon? =
override fun bindView(holder: ViewHolder, payloads: MutableList<Any>?) {
super.bindView(holder, payloads)
- holder.text.setTextColor(foregroundColor)
- holder.icon.setIcon(iicon, sizeDp = 18, color = foregroundColor)
- holder.container.background = SimpleRippleDrawable(foregroundColor, backgroundColor)
- holder.text.text = content
+ holder.title.setTextColor(foregroundColor)
+ holder.desc.setTextColor(foregroundColor.adjustAlpha(0.6f))
+
+ if (image != null) holder.icon.setImageDrawable(image)
+ else holder.icon.setIcon(iicon, sizeDp = 18, color = foregroundColor)
+
+ holder.container.setRippleBackground(foregroundColor, backgroundColor)
+ holder.title.text = content
+ if (description?.isNotBlank() ?: false) holder.desc.visible().text = description
}
override fun unbindView(holder: ViewHolder) {
super.unbindView(holder)
- holder.text.text = null
+ holder.title.text = null
+ holder.desc.gone().text = null
holder.icon.setImageDrawable(null)
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
val icon: ImageView by bindView(R.id.search_icon)
- val text: TextView by bindView(R.id.search_text)
+ val title: TextView by bindView(R.id.search_title)
+ val desc: TextView by bindView(R.id.search_desc)
val container: LinearLayout by bindView(R.id.search_item_frame)
}
} \ No newline at end of file