Skip to content

Commit 1b6c03e

Browse files
authored
fix: only remove track from the selected playlist (#332)
Refs: #69
1 parent 19eba26 commit 1b6c03e

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Changed
99
- Tapping notification now launches the "Now playing" screen ([#179])
1010

11+
### Fixed
12+
- Fixed an issue where removing a track from a playlist removed it from all playlists ([#69])
13+
1114
## [1.6.0] - 2025-11-09
1215
### Changed
1316
- Player now respects play/pause state when seeking ([#97])
@@ -91,6 +94,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9194
[#45]: https://github.com/FossifyOrg/Music-Player/issues/45
9295
[#47]: https://github.com/FossifyOrg/Music-Player/issues/47
9396
[#65]: https://github.com/FossifyOrg/Music-Player/issues/65
97+
[#69]: https://github.com/FossifyOrg/Music-Player/issues/69
9498
[#97]: https://github.com/FossifyOrg/Music-Player/issues/97
9599
[#179]: https://github.com/FossifyOrg/Music-Player/issues/179
96100
[#206]: https://github.com/FossifyOrg/Music-Player/issues/206

app/src/main/kotlin/org/fossify/musicplayer/adapters/TracksAdapter.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class TracksAdapter(
8787
R.id.cab_add_to_queue -> addToQueue()
8888
R.id.cab_properties -> showProperties()
8989
R.id.cab_rename -> displayEditDialog()
90-
R.id.cab_remove_from_playlist -> removeFromPlaylist()
90+
R.id.cab_remove_from_playlist -> removeFromPlaylist(playlist)
9191
R.id.cab_delete -> askConfirmDelete()
9292
R.id.cab_share -> shareFiles()
9393
R.id.cab_select_all -> selectAll()
@@ -107,7 +107,9 @@ class TracksAdapter(
107107
}
108108
}
109109

110-
private fun removeFromPlaylist() {
110+
private fun removeFromPlaylist(playlist: Playlist?) {
111+
if (playlist == null) return
112+
111113
ensureBackgroundThread {
112114
val positions = ArrayList<Int>()
113115
val selectedTracks = getSelectedTracks()
@@ -118,7 +120,8 @@ class TracksAdapter(
118120
}
119121
}
120122

121-
context.audioHelper.deleteTracks(selectedTracks)
123+
val mediaIds = selectedTracks.map { it.mediaStoreId }
124+
context.audioHelper.removeTracksFromPlaylist(playlist.id, mediaIds)
122125
// this is to make sure these tracks aren't automatically re-added to the 'All tracks' playlist on rescan
123126
val removedTrackIds = selectedTracks.filter { it.playListId == ALL_TRACKS_PLAYLIST_ID }.map { it.mediaStoreId.toString() }
124127
if (removedTrackIds.isNotEmpty()) {

app/src/main/kotlin/org/fossify/musicplayer/helpers/AudioHelper.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class AudioHelper(private val context: Context) {
7171
}
7272
}
7373

74+
fun removeTracksFromPlaylist(playlistId: Int, mediaStoreIds: List<Long>) {
75+
if (mediaStoreIds.isEmpty()) return
76+
context.tracksDAO.removeTracksFromPlaylist(playlistId, mediaStoreIds)
77+
}
78+
7479
fun insertArtists(artists: List<Artist>) {
7580
context.artistDAO.insertAll(artists)
7681
}

app/src/main/kotlin/org/fossify/musicplayer/interfaces/SongsDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ interface SongsDao {
4444
@Query("DELETE FROM tracks WHERE playlist_id = :playlistId")
4545
fun removePlaylistSongs(playlistId: Int)
4646

47+
@Query("DELETE FROM tracks WHERE playlist_id = :playlistId AND media_store_id IN (:mediaStoreIds)")
48+
fun removeTracksFromPlaylist(playlistId: Int, mediaStoreIds: List<Long>)
49+
4750
@Query("UPDATE tracks SET path = :newPath, artist = :artist, title = :title WHERE path = :oldPath")
4851
fun updateSongInfo(newPath: String, artist: String, title: String, oldPath: String)
4952

0 commit comments

Comments
 (0)