subscription view finished
This commit is contained in:
@@ -117,7 +117,22 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="DuplicateError" xml:space="preserve">
|
||||
<value>Playlist has been already added</value>
|
||||
</data>
|
||||
<data name="ErrorInfoBar.Title" xml:space="preserve">
|
||||
<value>Error</value>
|
||||
</data>
|
||||
<data name="Header.Text" xml:space="preserve">
|
||||
<value>Subscriptions</value>
|
||||
</data>
|
||||
<data name="PlaylistSearchButton.Content" xml:space="preserve">
|
||||
<value>Add</value>
|
||||
</data>
|
||||
<data name="PlaylistUrlTextBox.PlaceholderText" xml:space="preserve">
|
||||
<value>Playlist URL</value>
|
||||
</data>
|
||||
<data name="RemovePlaylistButton.Content" xml:space="preserve">
|
||||
<value>Remove</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -0,0 +1,39 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Models;
|
||||
|
||||
namespace VDownload.Core.ViewModels.Subscriptions.Helpers
|
||||
{
|
||||
public partial class PlaylistViewModel : ObservableObject
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[ObservableProperty]
|
||||
protected Guid _guid;
|
||||
|
||||
[ObservableProperty]
|
||||
protected string _name;
|
||||
|
||||
[ObservableProperty]
|
||||
protected Source _source;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public PlaylistViewModel(string name, Source source, Guid guid)
|
||||
{
|
||||
_name = name;
|
||||
_source = source;
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,141 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using ABI.System;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Core.ViewModels.Subscriptions.Helpers;
|
||||
using VDownload.Models;
|
||||
using VDownload.Services.Data.Subscriptions;
|
||||
using VDownload.Services.UI.StringResources;
|
||||
using VDownload.Sources;
|
||||
using VDownload.Sources.Common;
|
||||
|
||||
namespace VDownload.Core.ViewModels.Subscriptions
|
||||
{
|
||||
public class SubscriptionsViewModel : ObservableObject
|
||||
public partial class SubscriptionsViewModel : ObservableObject
|
||||
{
|
||||
#region SERVICES
|
||||
|
||||
protected readonly ISearchService _searchService;
|
||||
protected readonly IStringResourcesService _stringResourcesService;
|
||||
protected readonly ISubscriptionsDataService _subscriptionsDataService;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PROPERTIES
|
||||
|
||||
[ObservableProperty]
|
||||
protected ObservableCollection<PlaylistViewModel> _playlists;
|
||||
|
||||
[ObservableProperty]
|
||||
protected string _url;
|
||||
|
||||
[ObservableProperty]
|
||||
protected bool _loading;
|
||||
|
||||
[ObservableProperty]
|
||||
protected string _error;
|
||||
|
||||
[ObservableProperty]
|
||||
protected bool _isErrorOpened;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public SubscriptionsViewModel(ISearchService searchService, IStringResourcesService stringResourcesService, ISubscriptionsDataService subscriptionsDataService)
|
||||
{
|
||||
_searchService = searchService;
|
||||
_stringResourcesService = stringResourcesService;
|
||||
_subscriptionsDataService = subscriptionsDataService;
|
||||
|
||||
_playlists = new ObservableCollection<PlaylistViewModel>();
|
||||
_loading = false;
|
||||
_isErrorOpened = true;
|
||||
_error = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region COMMANDS
|
||||
|
||||
[RelayCommand]
|
||||
public void Navigation()
|
||||
{
|
||||
Playlists.Clear();
|
||||
foreach (Subscription sub in _subscriptionsDataService.Data)
|
||||
{
|
||||
Playlists.Add(new PlaylistViewModel(sub.Name, sub.Source, sub.Guid));
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task RemovePlaylist(PlaylistViewModel playlist)
|
||||
{
|
||||
Playlists.Remove(playlist);
|
||||
|
||||
Subscription sub = _subscriptionsDataService.Data.FirstOrDefault(x => x.Guid == playlist.Guid);
|
||||
_subscriptionsDataService.Data.Remove(sub);
|
||||
await _subscriptionsDataService.Save();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task Add()
|
||||
{
|
||||
Loading = true;
|
||||
|
||||
Playlist playlist;
|
||||
try
|
||||
{
|
||||
playlist = await _searchService.SearchPlaylist(Url, 0);
|
||||
}
|
||||
catch (MediaSearchException ex)
|
||||
{
|
||||
Error = _stringResourcesService.SearchResources.Get(ex.StringCode);
|
||||
Loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (_subscriptionsDataService.Data.Any(x => x.Source == playlist.Source && x.Name == playlist.Name))
|
||||
{
|
||||
Error = _stringResourcesService.SubscriptionsViewResources.Get("DuplicateError");
|
||||
Loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Subscription subscription = new Subscription
|
||||
{
|
||||
Name = playlist.Name,
|
||||
Source = playlist.Source,
|
||||
Url = playlist.Url,
|
||||
};
|
||||
playlist.ForEach(x => subscription.VideoIds.Add(x.Id));
|
||||
|
||||
_subscriptionsDataService.Data.Add(subscription);
|
||||
await _subscriptionsDataService.Save();
|
||||
Playlists.Add(new PlaylistViewModel(subscription.Name, subscription.Source, subscription.Guid));
|
||||
|
||||
Loading = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void CloseError()
|
||||
{
|
||||
Error = null;
|
||||
IsErrorOpened = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,109 @@
|
||||
xmlns:local="using:VDownload.Core.Views.Subscriptions"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ctuc="using:CommunityToolkit.WinUI.UI.Controls"
|
||||
xmlns:ctc="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:ct="using:CommunityToolkit.WinUI"
|
||||
xmlns:i="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
Background="{ThemeResource ViewBackgroundColor}"
|
||||
x:Name="Root">
|
||||
<i:Interaction.Behaviors>
|
||||
<ic:EventTriggerBehavior EventName="Loaded">
|
||||
<ic:InvokeCommandAction Command="{Binding NavigationCommand}"/>
|
||||
</ic:EventTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
|
||||
<Grid>
|
||||
<TextBlock Text="AAAAAAAAAA"/>
|
||||
<Grid Padding="20"
|
||||
RowSpacing="20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock x:Uid="/VDownload.Core.Strings/SubscriptionsViewResources/Header"
|
||||
Grid.Row="0"
|
||||
FontSize="28"
|
||||
FontWeight="SemiBold"/>
|
||||
<ScrollViewer Grid.Row="1">
|
||||
<ItemsControl ItemsSource="{Binding Playlists}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<ctuc:StaggeredPanel ColumnSpacing="10"
|
||||
DesiredColumnWidth="120"
|
||||
RowSpacing="10"/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid RowSpacing="10"
|
||||
Padding="10"
|
||||
Background="{ThemeResource PanelBackgroundColor}"
|
||||
CornerRadius="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Image Grid.Row="0">
|
||||
<i:Interaction.Behaviors>
|
||||
<ic:DataTriggerBehavior Binding="{Binding Source, Converter={StaticResource ObjectToStringConverter}}"
|
||||
Value="Twitch">
|
||||
<ic:ChangePropertyAction PropertyName="Source"
|
||||
Value="{StaticResource ImageSourcesTwitch}"/>
|
||||
</ic:DataTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
</Image>
|
||||
<TextBlock Grid.Row="1"
|
||||
Text="{Binding Name}"
|
||||
HorizontalAlignment="Center"/>
|
||||
<HyperlinkButton x:Uid="/VDownload.Core.Strings/SubscriptionsViewResources/RemovePlaylistButton"
|
||||
Grid.Row="2"
|
||||
Content="Remove"
|
||||
HorizontalAlignment="Center"
|
||||
Command="{Binding DataContext.RemovePlaylistCommand, ElementName=Root}"
|
||||
CommandParameter="{Binding}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
<ctuc:SwitchPresenter Grid.Row="2"
|
||||
Value="{Binding Error, Converter={StaticResource IsNotNullConverter}}">
|
||||
<ctuc:Case Value="False">
|
||||
<Grid Background="{ThemeResource PanelBackgroundColor}"
|
||||
Padding="10"
|
||||
ColumnSpacing="10"
|
||||
CornerRadius="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox x:Uid="/VDownload.Core.Strings/SubscriptionsViewResources/PlaylistUrlTextBox"
|
||||
Grid.Column="0"
|
||||
Text="{Binding Url, Mode=TwoWay}"/>
|
||||
<ctuc:SwitchPresenter Grid.Column="1"
|
||||
Value="{Binding Loading, Converter={StaticResource ObjectToStringConverter}}">
|
||||
<ctuc:Case Value="True">
|
||||
<ProgressRing IsIndeterminate="True"
|
||||
Width="20"
|
||||
Height="20"/>
|
||||
</ctuc:Case>
|
||||
<ctuc:Case Value="False">
|
||||
<Button x:Uid="/VDownload.Core.Strings/SubscriptionsViewResources/PlaylistSearchButton"
|
||||
Command="{Binding AddCommand}"/>
|
||||
</ctuc:Case>
|
||||
</ctuc:SwitchPresenter>
|
||||
</Grid>
|
||||
</ctuc:Case>
|
||||
<ctuc:Case Value="True">
|
||||
<InfoBar x:Uid="/VDownload.Core.Strings/SubscriptionsViewResources/ErrorInfoBar"
|
||||
Severity="Error"
|
||||
IsOpen="{Binding IsErrorOpened, Mode=TwoWay}"
|
||||
Message="{Binding Error}"
|
||||
CloseButtonCommand="{Binding CloseErrorCommand}"/>
|
||||
</ctuc:Case>
|
||||
</ctuc:SwitchPresenter>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
Reference in New Issue
Block a user