2022-06-10 14:28:33 +05:30
|
|
|
package com.github.libretube.adapters
|
|
|
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.EditText
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2022-07-01 15:39:54 +05:30
|
|
|
import com.github.libretube.databinding.SearchsuggestionRowBinding
|
2022-06-10 17:52:32 +05:30
|
|
|
import com.github.libretube.fragments.SearchFragment
|
2022-06-10 14:28:33 +05:30
|
|
|
|
|
|
|
class SearchSuggestionsAdapter(
|
|
|
|
private var suggestionsList: List<String>,
|
2022-06-10 17:52:32 +05:30
|
|
|
private var editText: EditText,
|
|
|
|
private val searchFragment: SearchFragment
|
2022-06-10 14:28:33 +05:30
|
|
|
) :
|
|
|
|
RecyclerView.Adapter<SearchSuggestionsViewHolder>() {
|
|
|
|
|
2022-07-01 15:39:54 +05:30
|
|
|
private val TAG = "SearchSuggestionsAdapter"
|
|
|
|
private lateinit var binding: SearchsuggestionRowBinding
|
|
|
|
|
2022-06-10 14:28:33 +05:30
|
|
|
override fun getItemCount(): Int {
|
|
|
|
return suggestionsList.size
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchSuggestionsViewHolder {
|
|
|
|
val layoutInflater = LayoutInflater.from(parent.context)
|
2022-07-01 15:39:54 +05:30
|
|
|
binding = SearchsuggestionRowBinding.inflate(layoutInflater, parent, false)
|
|
|
|
return SearchSuggestionsViewHolder(binding.root)
|
2022-06-10 14:28:33 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: SearchSuggestionsViewHolder, position: Int) {
|
|
|
|
val suggestion = suggestionsList[position]
|
2022-07-01 15:39:54 +05:30
|
|
|
binding.apply {
|
|
|
|
suggestionText.text = suggestion
|
|
|
|
root.setOnClickListener {
|
|
|
|
editText.setText(suggestion)
|
|
|
|
searchFragment.fetchSearch(editText.text.toString())
|
|
|
|
}
|
2022-06-10 14:28:33 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SearchSuggestionsViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
|
|
|
init {
|
|
|
|
}
|
|
|
|
}
|