mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-27 03:41:47 +02:00
fix(playlists): keep imported playlist track order (#482)
Playlist tracks were read newest-first (added_at DESC, rowid DESC), so a batch import - inserted in playlist order with one timestamp - came back reversed, and the in-memory prepend matched that. Playlists now use insertion order: snapshot reads ASC, single adds append, and batch adds append in order. Existing rows were already stored in playlist order, so old libraries display correctly without migration. The preview-cover query follows the first visible track.
This commit is contained in:
@@ -803,7 +803,7 @@ class LibraryCollectionsNotifier extends Notifier<LibraryCollectionsState> {
|
|||||||
final changed = _replacePlaylistById(playlistId, (playlist) {
|
final changed = _replacePlaylistById(playlistId, (playlist) {
|
||||||
if (playlist.containsTrackKey(key)) return playlist;
|
if (playlist.containsTrackKey(key)) return playlist;
|
||||||
return playlist.copyWith(
|
return playlist.copyWith(
|
||||||
tracks: [entry, ...playlist.tracks],
|
tracks: [...playlist.tracks, entry],
|
||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -864,7 +864,8 @@ class LibraryCollectionsNotifier extends Notifier<LibraryCollectionsState> {
|
|||||||
);
|
);
|
||||||
final changed = _replacePlaylistById(playlistId, (current) {
|
final changed = _replacePlaylistById(playlistId, (current) {
|
||||||
return current.copyWith(
|
return current.copyWith(
|
||||||
tracks: [...entriesToAdd.reversed, ...current.tracks],
|
// Append in playlist order, matching the ASC snapshot ordering.
|
||||||
|
tracks: [...current.tracks, ...entriesToAdd],
|
||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -269,7 +269,10 @@ class LibraryCollectionsDatabase {
|
|||||||
);
|
);
|
||||||
final playlistTrackRows = await db.query(
|
final playlistTrackRows = await db.query(
|
||||||
_tablePlaylistTracks,
|
_tablePlaylistTracks,
|
||||||
orderBy: 'playlist_id ASC, added_at DESC, rowid DESC',
|
// Playlists keep playlist order: batch imports insert rows in playlist
|
||||||
|
// order and later additions append, so insertion order IS the order
|
||||||
|
// (unlike wishlist/loved, which show newest first).
|
||||||
|
orderBy: 'playlist_id ASC, added_at ASC, rowid ASC',
|
||||||
);
|
);
|
||||||
final favoriteArtistRows = await db.query(
|
final favoriteArtistRows = await db.query(
|
||||||
_tableFavoriteArtists,
|
_tableFavoriteArtists,
|
||||||
@@ -348,7 +351,7 @@ class LibraryCollectionsDatabase {
|
|||||||
SELECT inner_tracks.rowid
|
SELECT inner_tracks.rowid
|
||||||
FROM $_tablePlaylistTracks inner_tracks
|
FROM $_tablePlaylistTracks inner_tracks
|
||||||
WHERE inner_tracks.playlist_id = outer_tracks.playlist_id
|
WHERE inner_tracks.playlist_id = outer_tracks.playlist_id
|
||||||
ORDER BY inner_tracks.added_at DESC, inner_tracks.rowid DESC
|
ORDER BY inner_tracks.added_at ASC, inner_tracks.rowid ASC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
)
|
)
|
||||||
''', playlistIdsNeedingPreview);
|
''', playlistIdsNeedingPreview);
|
||||||
|
|||||||
Reference in New Issue
Block a user