Refactor code structure for improved readability and maintainability

This commit is contained in:
Vladimir
2026-03-22 13:19:49 +02:00
parent 689450393b
commit 36c2970709
9 changed files with 238 additions and 199 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

+21 -23
View File
@@ -4,35 +4,33 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="TV_Player.AvaloniaApp.MainWindow"
mc:Ignorable="d"
Width="1400"
Height="860"
MinWidth="980"
MinHeight="640"
Title="TV Player"
Width="800"
Height="450"
MinWidth="800"
MinHeight="450"
Title="TV"
WindowState="{Binding CurrentWindowState}"
Background="#0B1220">
SystemDecorations="None">
<Grid RowDefinitions="Auto,*">
<Border IsVisible="{Binding IsTopPanelVisible}"
Background="#AA111827"
BorderBrush="#33FFFFFF"
BorderThickness="0,0,0,1"
Padding="20,14">
<Grid ColumnDefinitions="Auto,Auto,*,Auto,Auto">
<Button Content="Settings" Command="{Binding SettingsCommand}" MinWidth="92" Margin="0,0,12,0" />
<Button Grid.Column="1" Content="Back" Command="{Binding BackCommand}" MinWidth="92" Margin="0,0,12,0" />
<Grid.Background>
<ImageBrush Source="/Assets/bkground.jpg" Stretch="UniformToFill" />
</Grid.Background>
<Grid IsVisible="{Binding IsTopPanelVisible}" Height="80">
<Grid ColumnDefinitions="80,80,*,80,80">
<Button Width="70" Height="70" Margin="10,0,0,0" Content="S" Command="{Binding SettingsCommand}" />
<Button Grid.Column="1" Width="70" Height="70" Margin="10,0,0,0" Content="B" Command="{Binding BackCommand}" />
<TextBlock Grid.Column="2"
Text="{Binding TopPanelTitle}"
FontSize="26"
FontWeight="SemiBold"
FontSize="30"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
<Button Grid.Column="3" Content="Fullscreen" Command="{Binding FullscreenCommand}" MinWidth="110" Margin="0,0,12,0" />
<Button Grid.Column="4" Content="Close" Command="{Binding CloseAppCommand}" MinWidth="92" />
HorizontalAlignment="Center"
Foreground="White" />
<Button Grid.Column="3" Width="70" Height="70" Margin="10,0,0,0" Content="F" Command="{Binding FullscreenCommand}" />
<Button Grid.Column="4" Width="70" Height="70" Margin="10,0,0,0" Content="X" Command="{Binding CloseAppCommand}" />
</Grid>
</Grid>
</Border>
<Border Grid.Row="1" Padding="20">
<ContentControl Content="{Binding CurrentViewModel}" />
</Border>
<ContentControl Grid.Row="1" Content="{Binding CurrentViewModel}" />
</Grid>
</Window>
@@ -25,4 +25,8 @@
<ItemGroup>
<ProjectReference Include="..\TV Player Core\TV Player Core.csproj" />
</ItemGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**\*" />
</ItemGroup>
</Project>
+73 -53
View File
@@ -2,71 +2,91 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vlc="clr-namespace:LibVLCSharp.Avalonia;assembly=LibVLCSharp.Avalonia"
x:Class="TV_Player.AvaloniaApp.Views.PlayerView">
<Grid RowDefinitions="*,Auto" ColumnDefinitions="280,*">
<Border Grid.RowSpan="2"
Background="#AA111827"
Padding="16"
CornerRadius="16"
<Grid>
<vlc:VideoView x:Name="VideoView" />
<Grid Background="#01000000">
<Grid.RowDefinitions>
<RowDefinition Height="80" />
<RowDefinition Height="*" />
<RowDefinition Height="80" />
</Grid.RowDefinitions>
<Grid Background="#70000000">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
</Grid.ColumnDefinitions>
<Button Width="70" Height="50" Margin="10,0,0,0" Content="B" Command="{Binding BackCommand}" />
<TextBlock Grid.Column="1" FontSize="20" Foreground="White" Text="{Binding TopPanelTitle}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Button Grid.Column="2" Width="50" Height="70" Margin="10,0,0,0" Content="F" Command="{Binding FullscreenCommand}" />
<Button Grid.Column="3" Width="70" Height="70" Margin="10,0,0,0" Content="X" Command="{Binding CloseAppCommand}" />
</Grid>
<Border Grid.Row="1"
Width="400"
HorizontalAlignment="Left"
Background="#B0000000"
IsVisible="{Binding ProgramGuideVisible}">
<StackPanel Spacing="10">
<TextBlock Text="Upcoming" FontSize="22" FontWeight="SemiBold" />
<ItemsControl ItemsSource="{Binding Programs}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Padding="8" Background="#1F2937" CornerRadius="10" Margin="0,0,0,8">
<StackPanel Spacing="4">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" />
<StackPanel Orientation="Horizontal" Spacing="8">
<TextBlock Text="{Binding StartTime, StringFormat='{}{0:HH:mm}'}" />
<TextBlock Text="-" />
<TextBlock Text="{Binding EndTime, StringFormat='{}{0:HH:mm}'}" />
<StackPanel Orientation="Vertical" Margin="6,2">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" FontSize="15" Foreground="White" TextAlignment="Left" Margin="1,0,1,2" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding StartTime, StringFormat='{}{0:HH:mm}'}" FontSize="12" Foreground="White" Margin="1,0,1,2" />
<TextBlock Text="{Binding EndTime, StringFormat='{}{0:HH:mm}'}" FontSize="12" Foreground="White" Margin="10,0,1,2" />
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Border>
<Border Grid.Column="1" Background="#0F172A" CornerRadius="20" Padding="20" Margin="16,0,0,16">
<Grid RowDefinitions="Auto,*,Auto">
<TextBlock Text="{Binding TopPanelTitle}" FontSize="30" FontWeight="Bold" TextAlignment="Center" Margin="0,0,0,16" />
<Grid Grid.Row="1">
<vlc:VideoView x:Name="VideoView" />
<Border Background="#66000000" Padding="14" CornerRadius="12"
HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="20"
<Grid Grid.Row="2" Background="#B0000000">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="180" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<Button Width="50" Height="70" Margin="10,0,10,0" Content="-" Command="{Binding PreviousCommand}" />
<TextBlock FontSize="15" Foreground="White" Text="Ch" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Button Width="50" Height="70" Margin="10,0,10,0" Content="+" Command="{Binding NextCommand}" />
</StackPanel>
<Button Grid.Column="1"
Background="#0F000000"
BorderThickness="0"
IsVisible="{Binding IsProgramInfoVisible}"
Command="{Binding ShowProgramListCommand}">
<StackPanel>
<TextBlock FontSize="20" Foreground="White" Text="{Binding ProgramGuideText}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock FontSize="15" Foreground="White" Text="{Binding StartProgram}" />
<ProgressBar Height="10" Foreground="Yellow" Value="{Binding DurationValue}" Maximum="100" Width="400" VerticalAlignment="Center" />
<TextBlock FontSize="15" Foreground="White" Text="{Binding EndProgram}" />
</StackPanel>
</StackPanel>
</Button>
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Width="70" Height="50" Margin="8,0,0,0" Content="G" Command="{Binding ShowProgramListCommand}" />
<Button Width="70" Height="50" Margin="8,0,0,0" Content="Open" Command="{Binding OpenStreamCommand}" />
</StackPanel>
</Grid>
</Grid>
<Border Background="#66000000"
Padding="10"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="10"
IsVisible="{Binding HasPlaybackStatus}">
<StackPanel Spacing="8" MaxWidth="720">
<TextBlock Text="{Binding PlaybackStatus}" TextWrapping="Wrap" TextAlignment="Center" />
<SelectableTextBlock Text="{Binding StreamUrl}" TextWrapping="Wrap" IsVisible="False" />
</StackPanel>
</Border>
</Grid>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Spacing="12">
<Button Content="Previous" Command="{Binding PreviousCommand}" />
<Button Content="Open Externally" Command="{Binding OpenStreamCommand}" />
<Button Content="Next" Command="{Binding NextCommand}" />
</StackPanel>
</Grid>
</Border>
<Border Grid.Row="1" Grid.Column="1" Background="#AA111827" Padding="16" CornerRadius="16">
<Grid ColumnDefinitions="Auto,*,Auto,Auto,Auto,Auto" VerticalAlignment="Center">
<Button Content="Back" Command="{Binding BackCommand}" Margin="0,0,12,0" />
<StackPanel Grid.Column="1" IsVisible="{Binding IsProgramInfoVisible}" Spacing="6">
<TextBlock Text="{Binding ProgramGuideText}" FontSize="18" FontWeight="SemiBold" />
<StackPanel Orientation="Horizontal" Spacing="8">
<TextBlock Text="{Binding StartProgram}" />
<ProgressBar Width="260" Maximum="100" Value="{Binding DurationValue}" />
<TextBlock Text="{Binding EndProgram}" />
</StackPanel>
</StackPanel>
<Button Grid.Column="2" Content="Guide" Command="{Binding ShowProgramListCommand}" Margin="0,0,12,0" />
<Button Grid.Column="3" Content="Fullscreen" Command="{Binding FullscreenCommand}" Margin="0,0,12,0" />
<Button Grid.Column="4" Content="Open" Command="{Binding OpenStreamCommand}" Margin="0,0,12,0" />
<Button Grid.Column="5" Content="Close" Command="{Binding CloseAppCommand}" />
</Grid>
<TextBlock Text="{Binding PlaybackStatus}" Foreground="White" TextWrapping="Wrap" MaxWidth="420" />
</Border>
</Grid>
</UserControl>
@@ -2,32 +2,38 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="TV_Player.AvaloniaApp.Views.PlaylistsGroupView"
x:Name="Root">
<ScrollViewer>
<ItemsControl ItemsSource="{Binding Programs}">
<ItemsControl.ItemsPanel>
<Grid VerticalAlignment="Center">
<ListBox ItemsSource="{Binding Programs}"
Background="Transparent"
BorderThickness="0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
<UniformGrid Columns="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Button Width="260"
Height="120"
Margin="10"
Padding="18"
CornerRadius="16"
Background="#AA111827"
BorderBrush="#EAB308"
<Button Width="170"
Height="130"
Margin="8"
Background="#B0000000"
BorderBrush="Yellow"
BorderThickness="2"
Command="{Binding DataContext.SelectPlaylistCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
CommandParameter="{Binding}">
<StackPanel Spacing="8">
<TextBlock Text="{Binding Name}" FontSize="24" FontWeight="Bold" TextWrapping="Wrap" />
<TextBlock Text="Open playlist" Foreground="#D1D5DB" />
</StackPanel>
<TextBlock Text="{Binding Name}"
Foreground="White"
FontSize="20"
FontWeight="Bold"
TextWrapping="Wrap"
HorizontalAlignment="Center"
VerticalAlignment="Center"
TextAlignment="Center" />
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</UserControl>
@@ -1,43 +1,43 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="TV_Player.AvaloniaApp.Views.ProgramsGroupView">
<Grid RowDefinitions="Auto,*">
<!-- Debug Info Header -->
<Border Grid.Row="0" Background="#1a1a2e" Padding="16" Margin="0,0,0,4">
<TextBlock Text="{Binding Programs.Count, StringFormat='Groups Loaded: {0}'}"
Foreground="#EAB308"
FontSize="14"
FontWeight="Bold" />
</Border>
<!-- Groups List -->
<ScrollViewer Grid.Row="1">
<ItemsControl ItemsSource="{Binding Programs}">
<ItemsControl.ItemsPanel>
<Grid VerticalAlignment="Center">
<ListBox ItemsSource="{Binding Programs}"
Background="Transparent"
BorderThickness="0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
<UniformGrid Columns="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Button Width="260"
Height="140"
Margin="10"
Padding="18"
CornerRadius="16"
Background="#AA111827"
BorderBrush="#EAB308"
<Button Width="170"
Height="130"
Margin="8"
Background="#B0000000"
BorderBrush="Yellow"
BorderThickness="2"
Command="{Binding DataContext.SelectGroupCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
CommandParameter="{Binding}">
<StackPanel Spacing="8">
<TextBlock Text="{Binding Name}" FontSize="24" FontWeight="Bold" TextWrapping="Wrap" />
<TextBlock Text="{Binding Count, StringFormat='Channels: {0}'}" Foreground="#D1D5DB" />
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Spacing="6">
<TextBlock Text="{Binding Name}"
Foreground="White"
FontSize="20"
FontWeight="Bold"
TextWrapping="Wrap"
HorizontalAlignment="Center"
TextAlignment="Center" />
<TextBlock Text="{Binding Count}"
Foreground="White"
FontSize="16"
HorizontalAlignment="Center" />
</StackPanel>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</UserControl>
+31 -22
View File
@@ -1,34 +1,43 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="TV_Player.AvaloniaApp.Views.ProgramsListView">
<ScrollViewer>
<ItemsControl ItemsSource="{Binding Programs}">
<ItemsControl.ItemsPanel>
<Grid>
<ListBox ItemsSource="{Binding Programs}"
Background="Transparent"
VerticalAlignment="Top"
Margin="0,50,0,0"
BorderThickness="0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
<UniformGrid Columns="12" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Button Width="160"
Height="170"
Margin="8"
Padding="10"
CornerRadius="14"
Background="#AA111827"
BorderBrush="#EAB308"
<Button Width="106"
Height="145"
Margin="3"
Background="#B0000000"
BorderBrush="Yellow"
BorderThickness="2"
Command="{Binding DataContext.SelectProgramCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
CommandParameter="{Binding}">
<StackPanel Spacing="10">
<Border Height="90" Background="#1F2937" CornerRadius="10">
<Image Source="{Binding Logo}" Stretch="Uniform" />
</Border>
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" TextAlignment="Center" />
</StackPanel>
<Grid Margin="1" Background="#B0000000" RowDefinitions="*,Auto">
<Image Source="{Binding Logo}" MaxWidth="100" Margin="0,0,0,10" Stretch="Uniform" />
<TextBlock Grid.Row="1"
Text="{Binding Name}"
FontSize="15"
Foreground="White"
TextWrapping="Wrap"
TextAlignment="Center"
Margin="1,0,1,2"
HorizontalAlignment="Center" />
</Grid>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</UserControl>
+36 -32
View File
@@ -1,47 +1,51 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="TV_Player.AvaloniaApp.Views.SettingsView">
<ScrollViewer>
<StackPanel Width="900" HorizontalAlignment="Center" Spacing="18">
<TextBlock Text="Settings" FontSize="30" FontWeight="Bold" HorizontalAlignment="Center" />
<Viewbox>
<StackPanel VerticalAlignment="Center" Width="900">
<TextBlock Margin="10"
Foreground="White"
HorizontalAlignment="Center"
FontSize="25"
FontWeight="Bold"
Text="Settings" />
<Border Background="#AA111827" Padding="18" CornerRadius="16">
<StackPanel Spacing="12">
<TextBlock Text="Playlist URL" />
<TextBox Text="{Binding PlaylistURL}" Watermark="https://example.com/playlist.m3u" />
<TextBlock Text="Playlist name" />
<TextBox Text="{Binding PlaylistName}" Watermark="My IPTV" />
<Button Content="Add playlist" Command="{Binding AddPlaylistCommand}" HorizontalAlignment="Left" />
<StackPanel Margin="10" Spacing="8">
<TextBlock Foreground="White" FontSize="22" FontWeight="Bold" Text="Playlist URL" />
<TextBox Text="{Binding PlaylistURL}" />
<TextBlock Foreground="White" FontSize="22" FontWeight="Bold" Text="Playlist Name" />
<TextBox Text="{Binding PlaylistName}" />
<Button Content="Add" Width="70" Height="70" HorizontalAlignment="Center" Command="{Binding AddPlaylistCommand}" />
</StackPanel>
</Border>
<Border Background="#AA111827" Padding="18" CornerRadius="16">
<StackPanel Spacing="12">
<TextBlock Text="Playlists" FontSize="22" FontWeight="SemiBold" />
<ItemsControl ItemsSource="{Binding Playlists}">
<ItemsControl.ItemTemplate>
<ListBox Height="250"
ItemsSource="{Binding Playlists}"
Background="Transparent"
BorderThickness="0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ColumnDefinitions="220,*,Auto" Margin="0,4">
<TextBlock Text="{Binding Key}" VerticalAlignment="Center" Margin="0,0,12,0" />
<TextBlock Grid.Column="1" Text="{Binding Value}" VerticalAlignment="Center" TextWrapping="Wrap" Margin="0,0,12,0" />
<Grid HorizontalAlignment="Stretch" Height="80" ColumnDefinitions="200,*,100">
<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"
Content="Remove"
Command="{Binding DataContext.PlaylistDeleteCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
CommandParameter="{Binding}" />
Width="70"
Height="70"
Content="-"
CommandParameter="{Binding}"
Command="{Binding DataContext.PlaylistDeleteCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Border>
</ListBox.ItemTemplate>
</ListBox>
<CheckBox IsChecked="{Binding StartFullScreen}" Content="Start in fullscreen" />
<CheckBox IsChecked="{Binding StartLastScreen}" Content="Remember last screen" />
<CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartFullScreen}" Content="Fullscreen" />
<CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartLastScreen}" Content="Remember last" />
<StackPanel Orientation="Horizontal" Spacing="12" HorizontalAlignment="Center">
<Button Content="Back" Command="{Binding BackCommand}" MinWidth="120" />
<Button Content="Save" Command="{Binding SaveCommand}" MinWidth="120" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Width="70" Height="70" Margin="10,0,50,0" Content="B" Command="{Binding BackCommand}" />
<Button Width="70" Height="70" Content="OK" Command="{Binding SaveCommand}" />
</StackPanel>
</StackPanel>
</ScrollViewer>
</Viewbox>
</UserControl>
+2 -4
View File
@@ -221,9 +221,8 @@ namespace TV_Player
{
try
{
using (var client = new HttpClient())
using (var request = new HttpRequestMessage())
{
using var client = new HttpClient();
using var request = new HttpRequestMessage();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/text"));
request.Method = HttpMethod.Get;
request.RequestUri = new Uri(url);
@@ -231,7 +230,6 @@ namespace TV_Player
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
}
catch (HttpRequestException ex)
{
System.Diagnostics.Debug.WriteLine($"Network error reading file from {url}: {ex.Message}");