Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Screenbox.Core/Common/ServiceHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public static void PopulateCoreServices(ServiceCollection services)
// Factories
services.AddSingleton<MediaViewModelFactory>();
services.AddSingleton<StorageItemViewModelFactory>();
services.AddTransient<ArtistViewModelFactory>();
services.AddTransient<AlbumViewModelFactory>();
services.AddSingleton<IMediaListFactory, MediaListFactory>();

// Contexts
Expand Down
37 changes: 7 additions & 30 deletions Screenbox.Core/Contexts/LibraryContext.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#nullable enable

using System.Collections.Generic;
using System.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Screenbox.Core.Messages;
using Screenbox.Core.ViewModels;
using Screenbox.Core.Models;
using Windows.Storage;
using Windows.Storage.Search;

Expand All @@ -17,10 +14,10 @@ namespace Screenbox.Core.Contexts;
public sealed partial class LibraryContext : ObservableRecipient
{
[ObservableProperty]
private StorageLibrary? _musicLibrary;
private StorageLibrary? _storageMusicLibrary;

[ObservableProperty]
private StorageLibrary? _videosLibrary;
private StorageLibrary? _storageVideosLibrary;

[ObservableProperty]
private bool _isLoadingVideos;
Expand All @@ -29,35 +26,15 @@ public sealed partial class LibraryContext : ObservableRecipient
private bool _isLoadingMusic;

[ObservableProperty]
private Dictionary<string, AlbumViewModel> _albums = new();
[NotifyPropertyChangedRecipients]
private MusicLibrary _musicLibrary = new();

[ObservableProperty]
private Dictionary<string, ArtistViewModel> _artists = new();

[ObservableProperty]
private AlbumViewModel _unknownAlbum = new();

[ObservableProperty]
private ArtistViewModel _unknownArtist = new();

[ObservableProperty]
private List<MediaViewModel> _songs = new();

[ObservableProperty]
private List<MediaViewModel> _videos = new();
[NotifyPropertyChangedRecipients]
private VideosLibrary _videosLibrary = new();

public StorageFileQueryResult? MusicLibraryQueryResult { get; set; }
public StorageFileQueryResult? VideosLibraryQueryResult { get; set; }
public CancellationTokenSource? MusicFetchCts { get; set; }
public CancellationTokenSource? VideosFetchCts { get; set; }

public void RaiseMusicLibraryContentChanged()
{
Messenger.Send(new LibraryContentChangedMessage(KnownLibraryId.Music));
}

public void RaiseVideosLibraryContentChanged()
{
Messenger.Send(new LibraryContentChangedMessage(KnownLibraryId.Videos));
}
}
8 changes: 4 additions & 4 deletions Screenbox.Core/Controllers/LibraryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ private void StopWatching()

private async Task EnsureWatchingMusicAsync()
{
if (_context.MusicLibrary is null)
if (_context.StorageMusicLibrary is null)
{
_context.MusicLibrary = await _libraryService.InitializeMusicLibraryAsync();
_context.StorageMusicLibrary = await _libraryService.InitializeMusicLibraryAsync();
}

if (_musicQuery is not null && ShouldUpdateQuery(_musicQuery, UseIndexer))
Expand All @@ -136,9 +136,9 @@ private async Task EnsureWatchingMusicAsync()

private async Task EnsureWatchingVideosAsync()
{
if (_context.VideosLibrary is null)
if (_context.StorageVideosLibrary is null)
{
_context.VideosLibrary = await _libraryService.InitializeVideosLibraryAsync();
_context.StorageVideosLibrary = await _libraryService.InitializeVideosLibraryAsync();
}

if (_videosQuery is not null && ShouldUpdateQuery(_videosQuery, UseIndexer))
Expand Down
16 changes: 0 additions & 16 deletions Screenbox.Core/Messages/LibraryContentChangedMessage.cs

This file was deleted.

41 changes: 41 additions & 0 deletions Screenbox.Core/Models/MusicLibrary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using Screenbox.Core.ViewModels;

namespace Screenbox.Core.Models;

public class MusicLibrary
{
public List<MediaViewModel> Songs { get; }

public Dictionary<string, AlbumViewModel> Albums { get; }

public Dictionary<string, ArtistViewModel> Artists { get; }

public AlbumViewModel UnknownAlbum { get; }

public ArtistViewModel UnknownArtist { get; }

public MusicLibrary() : this(
new List<MediaViewModel>(),
new Dictionary<string, AlbumViewModel>(),
new Dictionary<string, ArtistViewModel>(),
new AlbumViewModel(),
new ArtistViewModel()
)
{ }

public MusicLibrary(
List<MediaViewModel> songs,
Dictionary<string, AlbumViewModel> albums,
Dictionary<string, ArtistViewModel> artists,
AlbumViewModel unknownAlbum,
ArtistViewModel unknownArtist
)
{
Songs = songs;
Albums = albums;
Artists = artists;
UnknownAlbum = unknownAlbum;
UnknownArtist = unknownArtist;
}
}
16 changes: 16 additions & 0 deletions Screenbox.Core/Models/VideosLibrary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using Screenbox.Core.ViewModels;

namespace Screenbox.Core.Models;

public class VideosLibrary
{
public List<MediaViewModel> Videos { get; }

public VideosLibrary() : this(new List<MediaViewModel>()) { }

public VideosLibrary(List<MediaViewModel> videos)
{
Videos = videos;
}
}
5 changes: 3 additions & 2 deletions Screenbox.Core/Screenbox.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
<Compile Include="Messages\FailedToLoadSubtitleNotificationMessage.cs" />
<Compile Include="Messages\FailedToOpenFilesNotificationMessage.cs" />
<Compile Include="Messages\FailedToSaveFrameNotificationMessage.cs" />
<Compile Include="Messages\LibraryContentChangedMessage.cs" />
<Compile Include="Messages\MediaLoadFailedNotificationMessage.cs" />
<Compile Include="Messages\NavigationViewDisplayModeRequestMessage.cs" />
<Compile Include="Messages\OverrideControlsHideDelayMessage.cs" />
Expand Down Expand Up @@ -205,6 +204,7 @@
<Compile Include="Models\MediaInfo.cs" />
<Compile Include="Models\MediaLastPosition.cs" />
<Compile Include="Models\MusicInfo.cs" />
<Compile Include="Models\MusicLibrary.cs" />
<Compile Include="Models\PersistentPlaylist.cs" />
<Compile Include="Models\PersistentStorageLibrary.cs" />
<Compile Include="Models\PlaybackNavigationResult.cs" />
Expand All @@ -217,6 +217,7 @@
<Compile Include="Models\SearchSuggestionItem.cs" />
<Compile Include="Models\ShuffleBackup.cs" />
<Compile Include="Models\VideoInfo.cs" />
<Compile Include="Models\VideosLibrary.cs" />
<Compile Include="Playback\AudioTrack.cs" />
<Compile Include="Helpers\DisplayRequestTracker.cs" />
<Compile Include="Playback\IMediaPlayer.cs" />
Expand Down Expand Up @@ -352,4 +353,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
6 changes: 4 additions & 2 deletions Screenbox.Core/Services/ILibraryService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Screenbox.Core.Contexts;
using Windows.Storage;
Expand All @@ -26,12 +28,12 @@ public interface ILibraryService
/// <summary>
/// Fetch music from the library
/// </summary>
Task FetchMusicAsync(LibraryContext context, bool useCache = true);
Task FetchMusicAsync(LibraryContext context, bool useCache = true, IProgress<List<MediaViewModel>>? progress = default);

/// <summary>
/// Fetch videos from the library
/// </summary>
Task FetchVideosAsync(LibraryContext context, bool useCache = true);
Task FetchVideosAsync(LibraryContext context, bool useCache = true, IProgress<List<MediaViewModel>>? progress = default);

/// <summary>
/// Remove media from the library
Expand Down
Loading