From 650d25aa1266000376b53b1ffa40731a27c50df5 Mon Sep 17 00:00:00 2001 From: MiMoHo <37556964+MiMoHo@users.noreply.github.com> Date: Fri, 3 Jul 2026 20:56:28 +0200 Subject: [PATCH] fix: preserve search filter after deleting a track while searching Deleting a selected track posts Events.RefreshFragments(), which makes MainActivity call refreshAllFragments() -> TracksFragment.setupFragment(). setupFragment reloads the full library asynchronously and calls updateItems() with the complete, unfiltered list, without re-applying the still-active search query. The search bar stays open but the list resets to the whole library. Track the active query in lastSearchQuery and re-apply it via onSearchQueryChanged() after the async reload finishes, so the filtered view (minus the deleted track) is preserved. Clear it in onSearchClosed(). Closes #85 --- CHANGELOG.md | 3 +++ .../org/fossify/musicplayer/fragments/TracksFragment.kt | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a95b2901..37cd4b8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fixed search results resetting to the full song list after deleting a track while searching ([#85]) ## [1.8.1] - 2026-02-14 ### Changed @@ -115,6 +117,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#47]: https://github.com/FossifyOrg/Music-Player/issues/47 [#65]: https://github.com/FossifyOrg/Music-Player/issues/65 [#69]: https://github.com/FossifyOrg/Music-Player/issues/69 +[#85]: https://github.com/FossifyOrg/Music-Player/issues/85 [#97]: https://github.com/FossifyOrg/Music-Player/issues/97 [#179]: https://github.com/FossifyOrg/Music-Player/issues/179 [#206]: https://github.com/FossifyOrg/Music-Player/issues/206 diff --git a/app/src/main/kotlin/org/fossify/musicplayer/fragments/TracksFragment.kt b/app/src/main/kotlin/org/fossify/musicplayer/fragments/TracksFragment.kt index 1b0a8c75..bc748dad 100644 --- a/app/src/main/kotlin/org/fossify/musicplayer/fragments/TracksFragment.kt +++ b/app/src/main/kotlin/org/fossify/musicplayer/fragments/TracksFragment.kt @@ -23,6 +23,7 @@ import org.fossify.musicplayer.models.sortSafely // Artists -> Albums -> Tracks class TracksFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) { private var tracks = ArrayList() + private var lastSearchQuery = "" private val binding by viewBinding(FragmentTracksBinding::bind) override fun setupFragment(activity: BaseSimpleActivity) { @@ -70,6 +71,12 @@ class TracksFragment(context: Context, attributeSet: AttributeSet) : MyViewPager } else { (adapter as TracksAdapter).updateItems(tracks) } + + // re-apply the active search filter so it isn't lost after a refresh + // (e.g. when deleting a track while searching) + if (lastSearchQuery.isNotEmpty()) { + onSearchQueryChanged(lastSearchQuery) + } } } } @@ -79,6 +86,7 @@ class TracksFragment(context: Context, attributeSet: AttributeSet) : MyViewPager } override fun onSearchQueryChanged(text: String) { + lastSearchQuery = text val normalizedText = text.normalizeString() val filtered = ArrayList( tracks.filter { track -> @@ -93,6 +101,7 @@ class TracksFragment(context: Context, attributeSet: AttributeSet) : MyViewPager } override fun onSearchClosed() { + lastSearchQuery = "" getAdapter()?.updateItems(tracks) binding.tracksPlaceholder.beGoneIf(tracks.isNotEmpty()) }