Skip to content

refactor: simplify Playlist and NextMediaList construction - #909

Open
huynhsontung wants to merge 2 commits into
mainfrom
safer-playlist-and-media-list
Open

refactor: simplify Playlist and NextMediaList construction#909
huynhsontung wants to merge 2 commits into
mainfrom
safer-playlist-and-media-list

Conversation

@huynhsontung

Copy link
Copy Markdown
Owner

No description provided.

@huynhsontung
huynhsontung requested a review from Copilot May 25, 2026 10:00
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors playlist construction to be index-based (instead of item-based) and simplifies NextMediaList creation by inferring NextItem from the first list entry.

Changes:

  • Replaced new Playlist(currentItem, items) usage with new Playlist(currentIndex, items) across view models and services.
  • Added NextMediaList(List<MediaViewModel> items) constructor and updated factories to use it.
  • Removed the Playlist(MediaViewModel currentItem, ...) constructor.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Screenbox.Core/ViewModels/PlaylistDetailsPageViewModel.cs Constructs playlists using the selected item’s index.
Screenbox.Core/ViewModels/MediaListViewModel.cs Uses index-based playlist creation during parse-and-play flows.
Screenbox.Core/Services/PlaylistService.cs Switches to index-based playlist creation when merging neighboring files / restoring from shuffle.
Screenbox.Core/Services/PlaybackControlService.cs Creates playlists for previous/next navigation using an explicit index.
Screenbox.Core/Models/Playlist.cs Removes item-based constructor and keeps index-based constructor.
Screenbox.Core/Models/NextMediaList.cs Adds constructor that infers NextItem from items[0].
Screenbox.Core/Helpers/MessengerExtensions.cs Manually finds the media index before constructing a playlist.
Screenbox.Core/Factories/MediaListFactory.cs Returns NextMediaList via list-only constructor to reduce repetition.
Comments suppressed due to low confidence (1)

Screenbox.Core/Models/Playlist.cs:1

  • Removing the public Playlist(MediaViewModel currentItem, ...) constructor is a breaking API change for any external callers. If this assembly is consumed outside this project, consider keeping the old overload as a wrapper (possibly marked [Obsolete]) that forwards to the index-based constructor, so consumers can migrate without immediate breakage.
#nullable enable
}
}

var playlist = new Playlist(index, queue);
{
var result = await _mediaListFactory.ParseMediaListAsync(nextFile);
var newPlaylist = new Playlist(result.NextItem, result.Items, playlist);
var newPlaylist = new Playlist(0, result.Items, playlist);
{
var result = await _mediaListFactory.ParseMediaListAsync(previousFile);
var newPlaylist = new Playlist(result.NextItem, result.Items, playlist);
var newPlaylist = new Playlist(0, result.Items, playlist);
Items = items;
}

public NextMediaList(List<MediaViewModel> items) : this(items[0], items) { }
// same object reference. Calling ParseMediaListAsync(file) would create a second VM
// via GetOrCreate, making result.NextItem a different instance from fileMedia.
// That mismatch would cause LoadFromPlaylist to restart playback unnecessarily.
result = await _mediaListFactory.ParseMediaListAsync(fileMedia);
Base automatically changed from copilot/fix-add-files-queue-issue to main May 25, 2026 16:21
@huynhsontung
huynhsontung force-pushed the safer-playlist-and-media-list branch from 556d281 to fc332ce Compare May 26, 2026 05:26
@huynhsontung
huynhsontung force-pushed the safer-playlist-and-media-list branch from fc332ce to 378a4e9 Compare May 26, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

2 participants