diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index d3de13e..23e1bc4 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -21,6 +21,13 @@
android:name=".SongListActivity"
android:label="@string/title_song_list"
android:theme="@style/AppTheme.NoActionBar">
+
+
+
+
+
() {
+ RecyclerView.Adapter(), Filterable {
+ private var listFilter: ListFilter? = null
private val onClickListener: View.OnClickListener
private val values: MutableList = ArrayList()
+ private var filteredItemList: MutableList = values
init {
onClickListener = View.OnClickListener { v ->
@@ -138,8 +170,8 @@ class SongListActivity : AppCompatActivity() {
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
- val item = values[position]
- holder.idView.text = item.name.replace("\\n", " ")
+ val item = filteredItemList[position]
+ holder.idView.text = """${item.name}(${item.id})""".replace("\\n", " ")
holder.contentView.text = item.composer
holder.backgroundLayout.setBackgroundColor(makeRGB(getColor(item.circleType)))
with(holder.itemView) {
@@ -149,7 +181,7 @@ class SongListActivity : AppCompatActivity() {
}
- override fun getItemCount() = values.size
+ override fun getItemCount() = filteredItemList.size
fun addItem(item: MusicInfo) {
values.add(item)
@@ -161,5 +193,51 @@ class SongListActivity : AppCompatActivity() {
val contentView: TextView = view.content
val backgroundLayout: LinearLayout = view.listitem_background
}
+
+ override fun getFilter(): Filter? {
+ if (listFilter == null) {
+ listFilter = ListFilter()
+ }
+ return listFilter
+ }
+
+ inner class ListFilter : Filter() {
+ val TAG="ListFilter"
+ override fun performFiltering(constraint: CharSequence?): FilterResults {
+ val TAG = "ListFilter"
+ Log.d(TAG, "Filter called$constraint")
+ val results = FilterResults()
+ if (constraint == null || constraint.isEmpty()) {
+ results.values = values
+ results.count = values.size
+ } else {
+ val itemList: ArrayList = ArrayList()
+ for (item in values) {
+ val name = """${item.name}(${item.id})"""
+ if (name.toUpperCase().contains(constraint.toString().toUpperCase())) {
+ itemList.add(item)
+ }
+ }
+ results.values = itemList
+ results.count = itemList.size
+ }
+ return results
+ }
+
+ override fun publishResults(
+ constraint: CharSequence,
+ results: FilterResults
+ ) { // update listview by filtered data list.
+ filteredItemList = results.values as ArrayList
+ Log.d(TAG, """filtered:${filteredItemList.size}, original:${values.size}""")
+
+ // notify
+ if (results.count > 0) {
+ notifyDataSetChanged()
+ } else {
+ notifyDataSetChanged()
+ }
+ }
+ }
}
}
diff --git a/app/src/main/java/com/kyhsgeekcode/dereinfo/model/MusicInfo.kt b/app/src/main/java/com/kyhsgeekcode/dereinfo/model/MusicInfo.kt
index 8e439d4..e229879 100644
--- a/app/src/main/java/com/kyhsgeekcode/dereinfo/model/MusicInfo.kt
+++ b/app/src/main/java/com/kyhsgeekcode/dereinfo/model/MusicInfo.kt
@@ -12,10 +12,12 @@ class MusicInfo(
) {
override fun toString(): String {
val lineSeparator = System.lineSeparator()
- return StringBuilder("name:").append(name).append(lineSeparator)
+ return StringBuilder("id:").append(id).append(lineSeparator)
+ .append("name:").append(name).append(lineSeparator)
.append("bpm:").append(bpm).append(lineSeparator)
.append("composer:").append(composer).append(lineSeparator)
.append("lyricist:").append(lyricist).append(lineSeparator)
+ .append("offset:").append(soundOffset).append(lineSeparator)
.append("duration:").append(soundLength).append(lineSeparator)
.append("type:").append(CircleType.getDesc(circleType)).toString()
}
diff --git a/app/src/main/res/drawable/ic_search_black_24dp.xml b/app/src/main/res/drawable/ic_search_black_24dp.xml
new file mode 100644
index 0000000..8fea044
--- /dev/null
+++ b/app/src/main/res/drawable/ic_search_black_24dp.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml
new file mode 100644
index 0000000..2acfea9
--- /dev/null
+++ b/app/src/main/res/menu/main_menu.xml
@@ -0,0 +1,13 @@
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6a0ac0d..b5c16d7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -4,4 +4,5 @@
Tab 2
Songs
Song Detail
+ Search hint
diff --git a/app/src/main/res/xml/searchable.xml b/app/src/main/res/xml/searchable.xml
new file mode 100644
index 0000000..fe61267
--- /dev/null
+++ b/app/src/main/res/xml/searchable.xml
@@ -0,0 +1,3 @@
+
\ No newline at end of file