aboutsummaryrefslogtreecommitdiff
path: root/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
diff options
context:
space:
mode:
Diffstat (limited to 'searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt')
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt49
1 files changed, 37 insertions, 12 deletions
diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
index 86ed83d..7d754c8 100644
--- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
+++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
@@ -1,8 +1,22 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.searchview
import android.graphics.Typeface
import android.graphics.drawable.Drawable
-import androidx.recyclerview.widget.RecyclerView
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.StyleSpan
@@ -10,8 +24,13 @@ import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
+import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.iitems.KauIItem
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.adjustAlpha
+import ca.allanwang.kau.utils.gone
+import ca.allanwang.kau.utils.setIcon
+import ca.allanwang.kau.utils.setRippleBackground
+import ca.allanwang.kau.utils.visible
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.mikepenz.iconics.typeface.IIcon
@@ -22,15 +41,16 @@ 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 description: String? = null,
- val iicon: IIcon? = GoogleMaterial.Icon.gmd_search,
- val image: Drawable? = null
+class SearchItem(
+ val key: String,
+ val content: String = key,
+ val description: String? = null,
+ val iicon: IIcon? = GoogleMaterial.Icon.gmd_search,
+ val image: Drawable? = null
) : KauIItem<SearchItem, SearchItem.ViewHolder>(
- R.layout.kau_search_iitem,
- { ViewHolder(it) },
- R.id.kau_item_search
+ R.layout.kau_search_iitem,
+ { ViewHolder(it) },
+ R.id.kau_item_search
) {
companion object {
@@ -48,7 +68,12 @@ class SearchItem(val key: String,
val index = content.indexOf(subText, ignoreCase = true)
if (index == -1) return
styledContent = SpannableStringBuilder(content)
- styledContent!!.setSpan(StyleSpan(Typeface.BOLD), index, index + subText.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
+ styledContent!!.setSpan(
+ StyleSpan(Typeface.BOLD),
+ index,
+ index + subText.length,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
+ )
}
override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
@@ -77,4 +102,4 @@ class SearchItem(val key: String,
val desc: TextView = v.findViewById(R.id.kau_search_desc)
val container: ConstraintLayout = v.findViewById(R.id.kau_search_item_frame)
}
-} \ No newline at end of file
+}