Allow to add/remove multiple playlists from settings window

This commit is contained in:
2024-10-23 14:37:54 +03:00
parent 6d09c2699c
commit 7cbda8a6b9
7 changed files with 127 additions and 30 deletions
+31
View File
@@ -80,6 +80,37 @@ c-0.781-0.781-0.788-2.047-0.007-2.828L51.438,14.43c1.754-1.755,1.753-4.61-0.001-
</Setter>
</Style>
<Style x:Key="ButtonAdd" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="Green" Height="50" Width="50" CornerRadius="300">
<Path Fill="#FFF4F4F5" HorizontalAlignment="Center" Height="35" Stroke="Black" Stretch="Fill" VerticalAlignment="Center" Width="30">
<Path.Data>
<PathGeometry Figures="M23.531502,6.7801739 L23.553471,20.766701 7.225951,21.044638 7.1408542,25.087499 23.177883,25.087499 23.051064,42.665812 28.15887,42.751559 28.194953,25.087499 43.923114,25.087499 43.984694,20.800105 28.242605,20.852246 28.284472,6.737454 z"/>
</Path.Data>
</Path>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonRemove" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="Red" Height="50" Width="50" CornerRadius="300">
<Path Fill="#FFF4F4F5" HorizontalAlignment="Center" Height="35" Stroke="Black" Stretch="Fill" VerticalAlignment="Center" Width="30">
<Path.Data>
<PathGeometry Figures="M7.225951,21.044638 L7.1408542,25.087499 43.923114,25.087499 43.984694,20.800105 z"/>
</Path.Data>
</Path>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonUp" TargetType="{x:Type Button}">
+6
View File
@@ -17,5 +17,11 @@ namespace TV_Player
viewModel.OnKeyDownCommand.Execute(e);
}
}
protected override void OnManipulationBoundaryFeedback(ManipulationBoundaryFeedbackEventArgs e)
{
e.Handled = true;
}
}
}
+2 -2
View File
@@ -35,13 +35,13 @@ namespace TV_Player
}
}
private void ListView_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
private void ListView_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
_isDragging = true;
_mousePosition = e.GetPosition(null);
}
private void ListView_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
private void ListView_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
+29 -5
View File
@@ -3,16 +3,39 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:tv_player="clr-namespace:TV_Player"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
mc:Ignorable="d">
<Viewbox>
<StackPanel x:Name="groupsGrid" VerticalAlignment="Center">
<!--<StackPanel x:Name="AddPlayList" Visibility="Collapsed">-->
<Button HorizontalAlignment="Center" Height="70" Width="70" Style="{DynamicResource ButtonAdd}" Click="OpenAddPlayList_Click" />
<ListView Height="250" ItemsSource="{Binding Playlists}" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" Height="80">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<TextBlock Foreground="White" VerticalAlignment="Center" FontSize="25" FontWeight="Bold" Text="{Binding Key}" />
<TextBlock Grid.Column="1" Foreground="White" VerticalAlignment="Center" FontSize="25" FontWeight="Bold" Text="{Binding Value}" />
<Button Grid.Column="2" Height="70" Width="70" Style="{DynamicResource ButtonRemove}" CommandParameter="{Binding}"
Command="{Binding DataContext.PlaylistDeleteCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
<StackPanel x:Name="AddPlayList" Visibility="Collapsed">
<Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial">Адрес плейлиста</Label>
<TextBox Margin="10" Style="{StaticResource TextBox}" HorizontalAlignment="Stretch" Text="{Binding PlaylistURL}"></TextBox>
<Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial">Название</Label>
<TextBox Margin="10" Style="{StaticResource TextBox}" HorizontalAlignment="Stretch" Text="{Binding PlaylistName}"></TextBox>
<Button Grid.Column="1" Height="70" Width="70" Margin="10,0,50,0" Style="{DynamicResource ButtonConfirm}" Command="{Binding BackCommand}" />
<!--</StackPanel>-->
<Button Grid.Column="1" Height="70" Width="70" Margin="10,0,50,0" Style="{DynamicResource ButtonConfirm}" Click="AddPlayList_Click" Command="{Binding AddPlaylistCommand}" />
</StackPanel>
<CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartFullScreen}">Откывать во весь экран</CheckBox>
<CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartLastScreen}">Запоминать последний выбор</CheckBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
@@ -20,4 +43,5 @@
<Button HorizontalAlignment="Center" Height="70" Width="70" Style="{DynamicResource ButtonConfirm}" Command="{Binding SaveCommand}" />
</StackPanel>
</StackPanel>
</Viewbox>
</UserControl>
+5
View File
@@ -1,4 +1,5 @@
using System.Windows.Controls;
using System.Windows;
namespace TV_Player
{
@@ -11,5 +12,9 @@ namespace TV_Player
{
InitializeComponent();
}
private void OpenAddPlayList_Click(object sender, System.Windows.RoutedEventArgs e) => AddPlayList.Visibility = Visibility.Visible;
private void AddPlayList_Click(object sender, RoutedEventArgs e) => AddPlayList.Visibility = Visibility.Collapsed;
}
}
+33 -3
View File
@@ -1,10 +1,18 @@
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace TV_Player.ViewModels
{
internal class SettingsViewModel : ObservableViewModelBase
{
private string _playlistName;
public string PlaylistName
{
get => _playlistName;
set => SetProperty(ref _playlistName, value);
}
private string _playlistURL;
public string PlaylistURL
{
@@ -12,6 +20,13 @@ namespace TV_Player.ViewModels
set => SetProperty(ref _playlistURL, value);
}
private ObservableCollection<KeyValuePair<string, string>> _playlists;
public ObservableCollection<KeyValuePair<string, string>> Playlists
{
get => _playlists;
set => SetProperty(ref _playlists, value);
}
private bool _startFullScreen;
public bool StartFullScreen
{
@@ -27,7 +42,9 @@ namespace TV_Player.ViewModels
}
public ICommand SaveCommand { get; }
public ICommand PlaylistDeleteCommand { get; }
public ICommand BackCommand { get; }
public ICommand AddPlaylistCommand { get; }
public SettingsViewModel()
{
@@ -35,12 +52,25 @@ namespace TV_Player.ViewModels
SaveCommand = new RelayCommand(OnSaveSettings);
BackCommand = new RelayCommand(OnBackCommand);
AddPlaylistCommand = new RelayCommand(OnAddPlaylistCommand);
PlaylistDeleteCommand = new RelayCommand<KeyValuePair<string, string>>(OnPlaylistDeleteCommand);
StartFullScreen = SettingsModel.StartFullScreen;
StartLastScreen = SettingsModel.StartFromLastScreen;
// PlaylistURL = SettingsModel.PlaylistURL;
Playlists = new ObservableCollection<KeyValuePair<string, string>>(SettingsModel.Playlists);
}
private void OnAddPlaylistCommand()
{
Playlists.Add(new KeyValuePair<string, string>(PlaylistName, PlaylistURL));
}
private void OnPlaylistDeleteCommand(KeyValuePair<string, string> pair)
{
Playlists.Remove(pair);
}
private void OnBackCommand()
{
TVPlayerViewModel.Instance.SelectScreen();
@@ -50,8 +80,8 @@ namespace TV_Player.ViewModels
{
SettingsModel.StartFullScreen = StartFullScreen;
SettingsModel.StartFromLastScreen = StartLastScreen;
//SettingsModel.PlaylistURL = PlaylistURL;
SettingsModel.Playlists.Clear();
SettingsModel.Playlists = Playlists.ToDictionary<string, string>();
SettingsModel.SaveSetttings();
TVPlayerViewModel.Instance.InitializeTVWithData();
}
@@ -44,6 +44,7 @@ namespace TV_Player.ViewModels
{
if (SettingsModel.Playlists!=null && SettingsModel.Playlists.Any())
{
PlayListsData.Clear();
foreach (var playlist in SettingsModel.Playlists)
{
PlayListsData.Add(playlist.Key, new ProgramsData(playlist.Key,playlist.Value));