subscriptions module finished

This commit is contained in:
2024-03-09 20:15:19 +01:00
Unverified
parent 38475a96ad
commit 2d53f75be2
5 changed files with 82 additions and 13 deletions

View File

@@ -159,4 +159,7 @@
<data name="StartAtMeteredConnectionDialogTitle" xml:space="preserve">
<value>Warning</value>
</data>
<data name="SubscriptionVideoListName" xml:space="preserve">
<value>Subscriptions</value>
</data>
</root>

View File

@@ -132,6 +132,12 @@
<data name="OptionBarMessageLoading" xml:space="preserve">
<value>Loading...</value>
</data>
<data name="OptionBarMessageVideosFound" xml:space="preserve">
<value>New videos:</value>
</data>
<data name="OptionBarMessageVideosNotFound" xml:space="preserve">
<value>No new videos</value>
</data>
<data name="OptionBarPlaylistSearch.Label" xml:space="preserve">
<value>Playlist search</value>
</data>

View File

@@ -10,6 +10,7 @@ using VDownload.Core.Tasks;
using VDownload.Models;
using VDownload.Services.Data.Configuration;
using VDownload.Services.Data.Settings;
using VDownload.Services.Data.Subscriptions;
using VDownload.Services.UI.Dialogs;
using VDownload.Services.UI.StringResources;
using VDownload.Sources;
@@ -52,6 +53,7 @@ namespace VDownload.Core.ViewModels.Home
protected readonly ISettingsService _settingsService;
protected readonly IStringResourcesService _stringResourcesService;
protected readonly ISearchService _searchService;
protected readonly ISubscriptionsDataService _subscriptionsDataService;
protected readonly IDialogsService _dialogsService;
protected readonly IDownloadTaskManager _downloadTaskManager;
@@ -88,6 +90,9 @@ namespace VDownload.Core.ViewModels.Home
[ObservableProperty]
private OptionBarMessageIconType _optionBarMessageIcon;
[ObservableProperty]
private bool _optionBarLoadSubscriptionButtonChecked;
[ObservableProperty]
private bool _optionBarVideoSearchButtonChecked;
@@ -112,12 +117,13 @@ namespace VDownload.Core.ViewModels.Home
#region CONSTRUCTORS
public HomeViewModel(IConfigurationService configurationService, ISettingsService settingsService, IStringResourcesService stringResourcesService, ISearchService searchService, IDialogsService dialogsService, IDownloadTaskManager downloadTaskManager, HomeVideoViewModel videoViewModel, HomeVideoCollectionViewModel videoCollectionViewModel)
public HomeViewModel(IConfigurationService configurationService, ISettingsService settingsService, IStringResourcesService stringResourcesService, ISearchService searchService, ISubscriptionsDataService subscriptionsDataService, IDialogsService dialogsService, IDownloadTaskManager downloadTaskManager, HomeVideoViewModel videoViewModel, HomeVideoCollectionViewModel videoCollectionViewModel)
{
_configurationService = configurationService;
_settingsService = settingsService;
_stringResourcesService = stringResourcesService;
_searchService = searchService;
_subscriptionsDataService = subscriptionsDataService;
_dialogsService = dialogsService;
_downloadTaskManager = downloadTaskManager;
@@ -145,6 +151,7 @@ namespace VDownload.Core.ViewModels.Home
OptionBarContent = OptionBarContentType.None;
OptionBarMessageIcon = OptionBarMessageIconType.None;
OptionBarMessage = null;
OptionBarLoadSubscriptionButtonChecked = false;
OptionBarVideoSearchButtonChecked = false;
OptionBarPlaylistSearchButtonChecked = false;
OptionBarSearchNotPending = true;
@@ -154,16 +161,64 @@ namespace VDownload.Core.ViewModels.Home
}
[RelayCommand]
public void LoadFromSubscription()
public async Task LoadFromSubscription()
{
MainContent = _downloadsView;
OptionBarMessageIcon = OptionBarMessageIconType.None;
OptionBarMessage = null;
if (OptionBarLoadSubscriptionButtonChecked)
{
OptionBarContent = OptionBarContentType.None;
OptionBarVideoSearchButtonChecked = false;
OptionBarPlaylistSearchButtonChecked = false;
OptionBarSearchNotPending = false;
//TODO: Load videos
OptionBarSearchNotPending = false;
OptionBarMessageIcon = OptionBarMessageIconType.ProgressRing;
OptionBarMessage = _stringResourcesService.HomeViewResources.Get("OptionBarMessageLoading");
SubscriptionsVideoList subList = new SubscriptionsVideoList { Name = _stringResourcesService.CommonResources.Get("SubscriptionVideoListName") };
List<Task> tasks = new List<Task>();
foreach (Subscription sub in _subscriptionsDataService.Data.ToArray())
{
tasks.Add(Task.Run(async () =>
{
Playlist playlist;
try
{
playlist = await _searchService.SearchPlaylist(sub.Url.OriginalString, 0);
}
catch (MediaSearchException)
{
return;
}
IEnumerable<Video> newIds = playlist.Where(x => !sub.VideoIds.Contains(x.Id));
subList.AddRange(newIds);
foreach (Video video in newIds)
{
sub.VideoIds.Add(video.Id);
}
}));
}
await Task.WhenAll(tasks);
await _subscriptionsDataService.Save();
if (subList.Count > 0)
{
OptionBarMessage = $"{_stringResourcesService.HomeViewResources.Get("OptionBarMessageVideosFound")} {subList.Count}";
_videoCollectionViewModel.LoadCollection(subList);
MainContent = _videoCollectionView;
}
else
{
OptionBarMessage = _stringResourcesService.HomeViewResources.Get("OptionBarMessageVideosNotFound");
}
OptionBarSearchNotPending = true;
OptionBarMessageIcon = OptionBarMessageIconType.None;
}
}
[RelayCommand]
@@ -178,6 +233,7 @@ namespace VDownload.Core.ViewModels.Home
{
OptionBarContent = OptionBarContentType.VideoSearch;
OptionBarPlaylistSearchButtonChecked = false;
OptionBarLoadSubscriptionButtonChecked = false;
}
else
{
@@ -197,6 +253,7 @@ namespace VDownload.Core.ViewModels.Home
{
OptionBarContent = OptionBarContentType.PlaylistSearch;
OptionBarVideoSearchButtonChecked = false;
OptionBarLoadSubscriptionButtonChecked = false;
}
else
{

View File

@@ -129,9 +129,10 @@
</ctuc:UniformGrid>
<StackPanel Grid.Column="2"
Orientation="Horizontal">
<AppBarButton x:Uid="/VDownload.Core.Strings/HomeViewResources/OptionBarLoadSubscription"
<AppBarToggleButton x:Uid="/VDownload.Core.Strings/HomeViewResources/OptionBarLoadSubscription"
Icon="Favorite"
IsEnabled="{Binding OptionBarSearchNotPending}"
IsChecked="{Binding OptionBarLoadSubscriptionButtonChecked, Mode=TwoWay}"
Command="{Binding LoadFromSubscriptionCommand}"/>
<AppBarToggleButton x:Uid="/VDownload.Core.Strings/HomeViewResources/OptionBarVideoSearch"
Icon="Video"

View File

@@ -62,7 +62,8 @@
</Image>
<TextBlock Grid.Row="1"
Text="{Binding Name}"
HorizontalAlignment="Center"/>
HorizontalAlignment="Center"
TextTrimming="CharacterEllipsis"/>
<HyperlinkButton x:Uid="/VDownload.Core.Strings/SubscriptionsViewResources/RemovePlaylistButton"
Grid.Row="2"
Content="Remove"
@@ -87,7 +88,8 @@
</Grid.ColumnDefinitions>
<TextBox x:Uid="/VDownload.Core.Strings/SubscriptionsViewResources/PlaylistUrlTextBox"
Grid.Column="0"
Text="{Binding Url, Mode=TwoWay}"/>
Text="{Binding Url, Mode=TwoWay}"
IsEnabled="{Binding Loading, Converter={StaticResource BoolNegationConverter}}"/>
<ctuc:SwitchPresenter Grid.Column="1"
Value="{Binding Loading, Converter={StaticResource ObjectToStringConverter}}">
<ctuc:Case Value="True">