Skip to content

Commit a42a6a4

Browse files
committed
implementing actual search functionality
1 parent 4f98921 commit a42a6a4

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Diff for: app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt

+22-8
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
4141
private var player: MediaPlayer? = null
4242
private var progressTimer = Timer()
4343
private var playedRecordingIDs = Stack<Int>()
44+
private var itemsIgnoringSearch = ArrayList<Recording>()
45+
private var lastSearchQuery = ""
4446
private var bus: EventBus? = null
4547
private var prevSavePath = ""
4648
private var playOnPreparation = true
4749

4850
override fun onResume() {
4951
setupColors()
5052
if (prevSavePath.isNotEmpty() && context!!.config.saveRecordingsFolder != prevSavePath) {
51-
setupAdapter()
53+
itemsIgnoringSearch = getRecordings()
54+
setupAdapter(itemsIgnoringSearch)
5255
} else {
5356
getRecordingsAdapter()?.updateTextColor(context.getProperTextColor())
5457
}
@@ -71,7 +74,8 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
7174
bus = EventBus.getDefault()
7275
bus!!.register(this)
7376
setupColors()
74-
setupAdapter()
77+
itemsIgnoringSearch = getRecordings()
78+
setupAdapter(itemsIgnoringSearch)
7579
initMediaPlayer()
7680
setupViews()
7781
storePrevPath()
@@ -132,18 +136,26 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
132136
}
133137

134138
override fun refreshRecordings() {
135-
setupAdapter()
139+
itemsIgnoringSearch = getRecordings()
140+
setupAdapter(itemsIgnoringSearch)
136141
}
137142

138-
private fun setupAdapter() {
143+
private fun setupAdapter(recordings: ArrayList<Recording>) {
139144
ensureBackgroundThread {
140-
val recordings = getRecordings()
141-
142145
Handler(Looper.getMainLooper()).post {
143146
recordings_fastscroller.beVisibleIf(recordings.isNotEmpty())
144147
recordings_placeholder.beVisibleIf(recordings.isEmpty())
145148
if (recordings.isEmpty()) {
146-
val stringId = if (isQPlus()) R.string.no_recordings_found else R.string.no_recordings_in_folder_found
149+
val stringId = if (lastSearchQuery.isEmpty()) {
150+
if (isQPlus()) {
151+
R.string.no_recordings_found
152+
} else {
153+
R.string.no_recordings_in_folder_found
154+
}
155+
} else {
156+
R.string.no_items_found
157+
}
158+
147159
recordings_placeholder.text = context.getString(stringId)
148160
resetProgress(null)
149161
player?.stop()
@@ -391,7 +403,9 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
391403
}
392404

393405
fun onSearchTextChanged(text: String) {
394-
406+
lastSearchQuery = text
407+
val filtered = itemsIgnoringSearch.filter { it.title.contains(text, true) }.toMutableList() as ArrayList<Recording>
408+
setupAdapter(filtered)
395409
}
396410

397411
private fun togglePlayPause() {

0 commit comments

Comments
 (0)