mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
commit
17b6d36b3a
@ -1,35 +1,38 @@
|
||||
package com.github.libretube.ui.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.SearchhistoryRowBinding
|
||||
import com.github.libretube.databinding.SuggestionRowBinding
|
||||
import com.github.libretube.db.DatabaseHolder.Database
|
||||
import com.github.libretube.db.obj.SearchHistoryItem
|
||||
import com.github.libretube.extensions.query
|
||||
import com.github.libretube.ui.viewholders.SearchHistoryViewHolder
|
||||
import com.github.libretube.ui.viewholders.SuggestionsViewHolder
|
||||
|
||||
class SearchHistoryAdapter(
|
||||
private var historyList: List<String>,
|
||||
private val searchView: SearchView
|
||||
) :
|
||||
RecyclerView.Adapter<SearchHistoryViewHolder>() {
|
||||
RecyclerView.Adapter<SuggestionsViewHolder>() {
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return historyList.size
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchHistoryViewHolder {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SuggestionsViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val binding = SearchhistoryRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SearchHistoryViewHolder(binding)
|
||||
val binding = SuggestionRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SuggestionsViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SearchHistoryViewHolder, position: Int) {
|
||||
override fun onBindViewHolder(holder: SuggestionsViewHolder, position: Int) {
|
||||
val historyQuery = historyList[position]
|
||||
holder.binding.apply {
|
||||
historyText.text = historyQuery
|
||||
suggestionText.text = historyQuery
|
||||
|
||||
deleteHistory.visibility = View.VISIBLE
|
||||
|
||||
deleteHistory.setOnClickListener {
|
||||
historyList -= historyQuery
|
||||
@ -45,6 +48,9 @@ class SearchHistoryAdapter(
|
||||
root.setOnClickListener {
|
||||
searchView.setQuery(historyQuery, true)
|
||||
}
|
||||
arrow.setOnClickListener {
|
||||
searchView.setQuery(historyQuery, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,26 +4,26 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.SearchsuggestionRowBinding
|
||||
import com.github.libretube.ui.viewholders.SearchSuggestionsViewHolder
|
||||
import com.github.libretube.databinding.SuggestionRowBinding
|
||||
import com.github.libretube.ui.viewholders.SuggestionsViewHolder
|
||||
|
||||
class SearchSuggestionsAdapter(
|
||||
private var suggestionsList: List<String>,
|
||||
private val searchView: SearchView
|
||||
) :
|
||||
RecyclerView.Adapter<SearchSuggestionsViewHolder>() {
|
||||
RecyclerView.Adapter<SuggestionsViewHolder>() {
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return suggestionsList.size
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchSuggestionsViewHolder {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SuggestionsViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val binding = SearchsuggestionRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SearchSuggestionsViewHolder(binding)
|
||||
val binding = SuggestionRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SuggestionsViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SearchSuggestionsViewHolder, position: Int) {
|
||||
override fun onBindViewHolder(holder: SuggestionsViewHolder, position: Int) {
|
||||
val suggestion = suggestionsList[position]
|
||||
holder.binding.apply {
|
||||
suggestionText.text = suggestion
|
||||
|
@ -1,8 +0,0 @@
|
||||
package com.github.libretube.ui.viewholders
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.SearchsuggestionRowBinding
|
||||
|
||||
class SearchSuggestionsViewHolder(
|
||||
val binding: SearchsuggestionRowBinding
|
||||
) : RecyclerView.ViewHolder(binding.root)
|
@ -1,8 +1,8 @@
|
||||
package com.github.libretube.ui.viewholders
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.SearchhistoryRowBinding
|
||||
import com.github.libretube.databinding.SuggestionRowBinding
|
||||
|
||||
class SearchHistoryViewHolder(
|
||||
val binding: SearchhistoryRowBinding
|
||||
class SuggestionsViewHolder(
|
||||
val binding: SuggestionRowBinding
|
||||
) : RecyclerView.ViewHolder(binding.root)
|
@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingVertical="8dp"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.github.libretube.ui.views.DrawableTextView
|
||||
android:id="@+id/history_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="viewStart"
|
||||
android:drawablePadding="15dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
app:drawableStartCompat="@drawable/ic_history"
|
||||
tools:text="Suggestion item" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/delete_history"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/ic_close"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:shapeAppearanceOverlay="@style/roundedImageViewRounded" />
|
||||
</LinearLayout>
|
@ -3,24 +3,37 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingVertical="8dp"
|
||||
android:layout_height="wrap_content">
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="8dp">
|
||||
|
||||
<com.github.libretube.ui.views.DrawableTextView
|
||||
android:id="@+id/suggestion_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="viewStart"
|
||||
android:drawablePadding="15dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_weight="1"
|
||||
android:drawablePadding="15dp"
|
||||
android:textAlignment="viewStart"
|
||||
app:drawableStartCompat="@drawable/ic_search"
|
||||
tools:text="Suggestion item" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/delete_history"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/ic_close"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:shapeAppearanceOverlay="@style/roundedImageViewRounded" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/arrow"
|
||||
android:layout_width="wrap_content"
|
Loading…
Reference in New Issue
Block a user