implementing actual search functionality

This commit is contained in:
tibbi 2023-01-14 22:50:32 +01:00
parent 4f98921aab
commit a42a6a4f8b
1 changed files with 22 additions and 8 deletions

View File

@ -41,6 +41,8 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
private var player: MediaPlayer? = null private var player: MediaPlayer? = null
private var progressTimer = Timer() private var progressTimer = Timer()
private var playedRecordingIDs = Stack<Int>() private var playedRecordingIDs = Stack<Int>()
private var itemsIgnoringSearch = ArrayList<Recording>()
private var lastSearchQuery = ""
private var bus: EventBus? = null private var bus: EventBus? = null
private var prevSavePath = "" private var prevSavePath = ""
private var playOnPreparation = true private var playOnPreparation = true
@ -48,7 +50,8 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
override fun onResume() { override fun onResume() {
setupColors() setupColors()
if (prevSavePath.isNotEmpty() && context!!.config.saveRecordingsFolder != prevSavePath) { if (prevSavePath.isNotEmpty() && context!!.config.saveRecordingsFolder != prevSavePath) {
setupAdapter() itemsIgnoringSearch = getRecordings()
setupAdapter(itemsIgnoringSearch)
} else { } else {
getRecordingsAdapter()?.updateTextColor(context.getProperTextColor()) getRecordingsAdapter()?.updateTextColor(context.getProperTextColor())
} }
@ -71,7 +74,8 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
bus = EventBus.getDefault() bus = EventBus.getDefault()
bus!!.register(this) bus!!.register(this)
setupColors() setupColors()
setupAdapter() itemsIgnoringSearch = getRecordings()
setupAdapter(itemsIgnoringSearch)
initMediaPlayer() initMediaPlayer()
setupViews() setupViews()
storePrevPath() storePrevPath()
@ -132,18 +136,26 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
} }
override fun refreshRecordings() { override fun refreshRecordings() {
setupAdapter() itemsIgnoringSearch = getRecordings()
setupAdapter(itemsIgnoringSearch)
} }
private fun setupAdapter() { private fun setupAdapter(recordings: ArrayList<Recording>) {
ensureBackgroundThread { ensureBackgroundThread {
val recordings = getRecordings()
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
recordings_fastscroller.beVisibleIf(recordings.isNotEmpty()) recordings_fastscroller.beVisibleIf(recordings.isNotEmpty())
recordings_placeholder.beVisibleIf(recordings.isEmpty()) recordings_placeholder.beVisibleIf(recordings.isEmpty())
if (recordings.isEmpty()) { if (recordings.isEmpty()) {
val stringId = if (isQPlus()) R.string.no_recordings_found else R.string.no_recordings_in_folder_found val stringId = if (lastSearchQuery.isEmpty()) {
if (isQPlus()) {
R.string.no_recordings_found
} else {
R.string.no_recordings_in_folder_found
}
} else {
R.string.no_items_found
}
recordings_placeholder.text = context.getString(stringId) recordings_placeholder.text = context.getString(stringId)
resetProgress(null) resetProgress(null)
player?.stop() player?.stop()
@ -391,7 +403,9 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
} }
fun onSearchTextChanged(text: String) { fun onSearchTextChanged(text: String) {
lastSearchQuery = text
val filtered = itemsIgnoringSearch.filter { it.title.contains(text, true) }.toMutableList() as ArrayList<Recording>
setupAdapter(filtered)
} }
private fun togglePlayPause() { private fun togglePlayPause() {