Skip to content

Commit

Permalink
Fixed the way we apply the title to selections, and also made sure ba…
Browse files Browse the repository at this point in the history
…cking up in search still filters for Droidcon-Boston#153.
  • Loading branch information
AdamMc331 committed Mar 2, 2019
1 parent d6551ea commit e497771
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class Schedule {
|| this.talkDescription.contains(keyword, ignoreCase = true)
|| this.speakerNames.any { it.contains(keyword, ignoreCase = true) }
}

override fun toString(): String {
return talkTitle
}
}

data class ScheduleDetail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ScheduleSearchAdapter(
private val layoutRes: Int,
private val scheduleRows: List<Schedule.ScheduleRow>
): ArrayAdapter<Schedule.ScheduleRow>(context, layoutRes, scheduleRows) {
private val suggestions: MutableList<Schedule.ScheduleRow> = mutableListOf()
private val tempItems: MutableList<Schedule.ScheduleRow> = scheduleRows.toMutableList()

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view = convertView ?: LayoutInflater.from(context).inflate(layoutRes, parent, false)
Expand All @@ -36,8 +38,14 @@ class ScheduleSearchAdapter(
override fun getFilter(): Filter {
return object : Filter() {
override fun performFiltering(constraint: CharSequence?): FilterResults {
val suggestions = scheduleRows.filter {
it.containsKeyword(constraint?.toString().orEmpty())
val keyword = constraint ?: return FilterResults()

suggestions.clear()

tempItems.forEach {
if (it.containsKeyword(keyword.toString())) {
suggestions.add(it)
}
}

return FilterResults().apply {
Expand All @@ -47,16 +55,19 @@ class ScheduleSearchAdapter(
}

override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
val tempValues = (results?.values as? List<*>)
?.filterIsInstance(Schedule.ScheduleRow::class.java)

clear()

(results?.values as? List<*>)
?.filterIsInstance(Schedule.ScheduleRow::class.java)
?.forEach {
add(it)
}
tempValues?.forEach(this@ScheduleSearchAdapter::add)

notifyDataSetChanged()
}

override fun convertResultToString(resultValue: Any?): CharSequence {
return (resultValue as? Schedule.ScheduleRow)?.talkTitle.toString()
}
}
}
}

0 comments on commit e497771

Please sign in to comment.