Search history almost works

This commit is contained in:
archroid 2022-05-09 22:39:03 +04:30
parent 8149e69210
commit 34b53d0b17
No known key found for this signature in database
GPG Key ID: D8EE5C11EDF911B1
2 changed files with 6 additions and 3 deletions

View File

@ -15,6 +15,7 @@ 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
@ -189,6 +190,7 @@ class SearchFragment : Fragment() {
} }
if (splited_history.size > 10) { if (splited_history.size > 10) {
splited_history = splited_history.takeLast(10) splited_history = splited_history.takeLast(10)
} }
@ -202,7 +204,6 @@ class SearchFragment : Fragment() {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
var history = sharedPreferences.getString("search_history", "") var history = sharedPreferences.getString("search_history", "")
var splited_history = history!!.split("|") var splited_history = history!!.split("|")
return splited_history return splited_history
} }
} }

View File

@ -1,6 +1,7 @@
package com.github.libretube.adapters package com.github.libretube.adapters
import android.content.Context import android.content.Context
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -10,10 +11,11 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R 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>) : class SearchHistoryAdapter(private val context: Context, private val historyList: List<String>) :
RecyclerView.Adapter<SearchHistoryViewHolder>() { RecyclerView.Adapter<SearchHistoryViewHolder>() {
override fun getItemCount(): Int { override fun getItemCount(): Int {
return historyList.size return historyList.size -1
} }
@ -24,7 +26,7 @@ class SearchHistoryAdapter(private val context: Context, private val historyList
} }
override fun onBindViewHolder(holder: SearchHistoryViewHolder, position: Int) { override fun onBindViewHolder(holder: SearchHistoryViewHolder, position: Int) {
val history = historyList[position] val history = historyList[position+1]
holder.v.findViewById<TextView>(R.id.history_text).text = history holder.v.findViewById<TextView>(R.id.history_text).text = history