From a42a6a4f8b1a685894027037d80fa144f2531f97 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Jan 2023 22:50:32 +0100 Subject: [PATCH] implementing actual search functionality --- .../voicerecorder/fragments/PlayerFragment.kt | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt index d7c52d1..a753ba8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt @@ -41,6 +41,8 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager private var player: MediaPlayer? = null private var progressTimer = Timer() private var playedRecordingIDs = Stack() + private var itemsIgnoringSearch = ArrayList() + private var lastSearchQuery = "" private var bus: EventBus? = null private var prevSavePath = "" private var playOnPreparation = true @@ -48,7 +50,8 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager override fun onResume() { setupColors() if (prevSavePath.isNotEmpty() && context!!.config.saveRecordingsFolder != prevSavePath) { - setupAdapter() + itemsIgnoringSearch = getRecordings() + setupAdapter(itemsIgnoringSearch) } else { getRecordingsAdapter()?.updateTextColor(context.getProperTextColor()) } @@ -71,7 +74,8 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager bus = EventBus.getDefault() bus!!.register(this) setupColors() - setupAdapter() + itemsIgnoringSearch = getRecordings() + setupAdapter(itemsIgnoringSearch) initMediaPlayer() setupViews() storePrevPath() @@ -132,18 +136,26 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager } override fun refreshRecordings() { - setupAdapter() + itemsIgnoringSearch = getRecordings() + setupAdapter(itemsIgnoringSearch) } - private fun setupAdapter() { + private fun setupAdapter(recordings: ArrayList) { ensureBackgroundThread { - val recordings = getRecordings() - Handler(Looper.getMainLooper()).post { recordings_fastscroller.beVisibleIf(recordings.isNotEmpty()) recordings_placeholder.beVisibleIf(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) resetProgress(null) player?.stop() @@ -391,7 +403,9 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager } fun onSearchTextChanged(text: String) { - + lastSearchQuery = text + val filtered = itemsIgnoringSearch.filter { it.title.contains(text, true) }.toMutableList() as ArrayList + setupAdapter(filtered) } private fun togglePlayPause() {