mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Search history works fine without any bugs
This commit is contained in:
parent
580e99329d
commit
8121e8534b
@ -15,7 +15,6 @@ import android.widget.ArrayAdapter
|
|||||||
import android.widget.AutoCompleteTextView
|
import android.widget.AutoCompleteTextView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.TextView.*
|
import android.widget.TextView.*
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
@ -66,7 +65,12 @@ class SearchFragment : Fragment() {
|
|||||||
history_tv.visibility = VISIBLE
|
history_tv.visibility = VISIBLE
|
||||||
|
|
||||||
historyRecycler.layoutManager = LinearLayoutManager(view.context)
|
historyRecycler.layoutManager = LinearLayoutManager(view.context)
|
||||||
historyRecycler.adapter = SearchHistoryAdapter(requireContext(),getHistory(),autoTextView)
|
|
||||||
|
var historylist = getHistory()
|
||||||
|
if (historylist.size != 0) {
|
||||||
|
historyRecycler.adapter =
|
||||||
|
SearchHistoryAdapter(requireContext(), historylist, autoTextView)
|
||||||
|
}
|
||||||
|
|
||||||
recyclerView.layoutManager = GridLayoutManager(view.context, 1)
|
recyclerView.layoutManager = GridLayoutManager(view.context, 1)
|
||||||
autoTextView.requestFocus()
|
autoTextView.requestFocus()
|
||||||
@ -106,7 +110,11 @@ class SearchFragment : Fragment() {
|
|||||||
recyclerView.visibility = GONE
|
recyclerView.visibility = GONE
|
||||||
historyRecycler.visibility = VISIBLE
|
historyRecycler.visibility = VISIBLE
|
||||||
history_tv.visibility = VISIBLE
|
history_tv.visibility = VISIBLE
|
||||||
historyRecycler.adapter = SearchHistoryAdapter(requireContext(),getHistory(),autoTextView)
|
var historylist = getHistory()
|
||||||
|
if (historylist.size != 0) {
|
||||||
|
historyRecycler.adapter =
|
||||||
|
SearchHistoryAdapter(requireContext(), historylist, autoTextView)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,9 +214,7 @@ class SearchFragment : Fragment() {
|
|||||||
|
|
||||||
private fun getHistory(): List<String> {
|
private fun getHistory(): List<String> {
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
|
|
||||||
val set: Set<String> = sharedPreferences.getStringSet("search_history", null)!!
|
val set: Set<String> = sharedPreferences.getStringSet("search_history", null)!!
|
||||||
|
|
||||||
return set.toList()
|
return set.toList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,10 @@ import com.github.libretube.R
|
|||||||
import com.google.android.material.imageview.ShapeableImageView
|
import com.google.android.material.imageview.ShapeableImageView
|
||||||
|
|
||||||
|
|
||||||
class SearchHistoryAdapter(private val context: Context, private val historyList: List<String> , private val editText : AutoCompleteTextView) :
|
class SearchHistoryAdapter(private val context: Context, private var historyList: List<String> , private val editText : AutoCompleteTextView) :
|
||||||
RecyclerView.Adapter<SearchHistoryViewHolder>() {
|
RecyclerView.Adapter<SearchHistoryViewHolder>() {
|
||||||
|
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
return historyList.size
|
return historyList.size
|
||||||
}
|
}
|
||||||
@ -33,15 +35,19 @@ class SearchHistoryAdapter(private val context: Context, private val historyList
|
|||||||
|
|
||||||
holder.v.findViewById<ShapeableImageView>(R.id.delete_history).setOnClickListener {
|
holder.v.findViewById<ShapeableImageView>(R.id.delete_history).setOnClickListener {
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
var splited_history = sharedPreferences.getString("search_history", "")!!.split("|")
|
// var historyList = sharedPreferences.getStringSet("search_history", null)!!.toList()
|
||||||
|
|
||||||
splited_history = splited_history - history
|
historyList = historyList - history
|
||||||
|
|
||||||
sharedPreferences.edit().putString("search_history", splited_history.joinToString("|"))
|
sharedPreferences.edit().putStringSet("search_history", HashSet(historyList))
|
||||||
.apply()
|
.apply()
|
||||||
|
|
||||||
|
Log.d("TAG", "onBindViewHolder: " + historyList.size)
|
||||||
|
|
||||||
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
holder.v.setOnClickListener {
|
holder.v.setOnClickListener {
|
||||||
editText.setText(history)
|
editText.setText(history)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user