Commit a6ec6d80 authored by Jean Felder's avatar Jean Felder Committed by Marinus Schraal
Browse files

grltrackerplaylists: Improve smart playlists updates

The existing update method removes the songs which are not part of the
playlist anymore and adds the new songs at the end of the model.

This behavior assumes that the position of an existing song does not
change on update. This is wrong for most of the smart playlists (for
example, the MostPlayed playlist).

This issue is fixed by removing the existing songs and adding the new
ones in one go by a splice call. If a song was already part of the
playlist, its state is preserved.
parent fba2bd08
Pipeline #229040 passed with stages
in 7 minutes and 32 seconds
......@@ -797,23 +797,22 @@ class SmartPlaylist(Playlist):
current_models_ids = [coresong.props.media.get_id()
for coresong in self._model]
new_model_ids = [media.get_id() for media in new_model_medias]
idx_to_delete = []
for idx, media_id in enumerate(current_models_ids):
if media_id not in new_model_ids:
idx_to_delete.insert(0, idx)
new_songs = []
for media in new_model_medias:
coresong = CoreSong(self._application, media)
new_songs.append(coresong)
try:
idx = current_models_ids.index(media.get_id())
except ValueError:
continue
for idx in idx_to_delete:
self._model.remove(idx)
self.props.count -= 1
current_song = self._model[idx]
coresong.props.state = current_song.props.state
coresong.props.validation = current_song.props.validation
for idx, media in enumerate(new_model_medias):
if media.get_id() not in current_models_ids:
coresong = CoreSong(self._application, media)
self._bind_to_main_song(coresong)
self._model.append(coresong)
self.props.count += 1
self._model.splice(0, self._model.get_n_items(), new_songs)
self.props.count = len(new_songs)
class MostPlayed(SmartPlaylist):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment