add translation, fix small bugs

This commit is contained in:
2024-10-23 17:49:23 +03:00
parent 47a09ccd2e
commit 02aabfdf4c
7 changed files with 64 additions and 16 deletions
+3 -3
View File
@@ -15,7 +15,7 @@
<TextBlock x:Name="groupName" Text="{TemplateBinding GroupName}" FontSize="15" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/> <TextBlock x:Name="groupName" Text="{TemplateBinding GroupName}" FontSize="15" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1" FontSize="10" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" LineStackingStrategy="BlockLineHeight" LineHeight="10"> <TextBlock Grid.Row="1" FontSize="10" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" LineStackingStrategy="BlockLineHeight" LineHeight="10">
<Run Text="{TemplateBinding ProgramsCount}"/> <Run Text="{TemplateBinding ProgramsCount}"/>
<Run>программ</Run> <Run Text="{DynamicResource programs}"/>
</TextBlock> </TextBlock>
</Grid> </Grid>
</Border> </Border>
@@ -101,9 +101,9 @@ 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.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Button}"> <ControlTemplate TargetType="{x:Type Button}">
<Border Background="Red" Height="50" Width="50" CornerRadius="300"> <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 Fill="#FFF4F4F5" HorizontalAlignment="Center" Height="7" Stroke="Black" Stretch="Fill" VerticalAlignment="Center" Width="30">
<Path.Data> <Path.Data>
<PathGeometry Figures="M7.225951,21.044638 L7.1408542,25.087499 43.923114,25.087499 43.984694,20.800105 z"/> <PathGeometry Figures="M7.0900176,20.854068 L7.1408542,25.087499 43.923114,25.087499 43.984694,20.800105 z"/>
</Path.Data> </Path.Data>
</Path> </Path>
</Border> </Border>
+12
View File
@@ -0,0 +1,12 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="settings">Settings</system:String>
<system:String x:Key="fullscreen">Fullscreen</system:String>
<system:String x:Key="rememberLast">Remember last seen programm</system:String>
<system:String x:Key="addNewPlaylist">Add new playlist</system:String>
<system:String x:Key="playlistURL">Playlist URL</system:String>
<system:String x:Key="playlistName">Playlist name</system:String>
<system:String x:Key="programs">programs</system:String>
</ResourceDictionary>
+3 -3
View File
@@ -103,7 +103,7 @@ namespace TV_Player
} }
} }
public static async Task<ProgramGuide> ParseEpg(string channelId) public static async Task<ProgramGuide> ParseEpg(string groupName, string channelId)
{ {
XmlReaderSettings settings = new XmlReaderSettings(); XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true; settings.IgnoreWhitespace = true;
@@ -112,9 +112,9 @@ namespace TV_Player
settings.Async = true; settings.Async = true;
ProgramGuide channel = null; ProgramGuide channel = null;
var fileName = "guide.xml"; var fileName = groupName+"_guide.xml";
string programDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); string programDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
string filePath = Path.Combine(programDataPath, "TV_Player", fileName); string filePath = Path.Combine(programDataPath, "TVPlayer", fileName);
using (XmlReader reader = XmlReader.Create(filePath, settings)) using (XmlReader reader = XmlReader.Create(filePath, settings))
{ {
+7 -5
View File
@@ -6,6 +6,7 @@
mc:Ignorable="d"> mc:Ignorable="d">
<Viewbox> <Viewbox>
<StackPanel x:Name="groupsGrid" VerticalAlignment="Center"> <StackPanel x:Name="groupsGrid" VerticalAlignment="Center">
<Label Margin="10" Foreground="White" HorizontalAlignment="Center" FontSize="25" FontWeight="Bold" FontFamily="Arial" Content="{DynamicResource settings}"></Label>
<Button HorizontalAlignment="Center" Height="70" Width="70" Style="{DynamicResource ButtonAdd}" Click="OpenAddPlayList_Click" /> <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 Height="250" ItemsSource="{Binding Playlists}" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemTemplate> <ListView.ItemTemplate>
@@ -29,15 +30,16 @@
</Style> </Style>
</ListView.ItemContainerStyle> </ListView.ItemContainerStyle>
</ListView> </ListView>
<StackPanel x:Name="AddPlayList" Visibility="Collapsed"> <StackPanel x:Name="AddPlayList" Visibility="Collapsed" Margin="0,-250,0,0" Background="Black">
<Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial">Адрес плейлиста</Label> <Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial" Content="{DynamicResource addNewPlaylist}"/>
<Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial" Content="{DynamicResource playlistURL}"/>
<TextBox Margin="10" Style="{StaticResource TextBox}" HorizontalAlignment="Stretch" Text="{Binding PlaylistURL}"></TextBox> <TextBox Margin="10" Style="{StaticResource TextBox}" HorizontalAlignment="Stretch" Text="{Binding PlaylistURL}"></TextBox>
<Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial">Название</Label> <Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial" Content="{DynamicResource playlistName}"/>
<TextBox Margin="10" Style="{StaticResource TextBox}" HorizontalAlignment="Stretch" Text="{Binding PlaylistName}"></TextBox> <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}" Click="AddPlayList_Click" Command="{Binding AddPlaylistCommand}" /> <Button Grid.Column="1" Height="70" Width="70" Margin="10,0,50,0" Style="{DynamicResource ButtonConfirm}" Click="AddPlayList_Click" Command="{Binding AddPlaylistCommand}" />
</StackPanel> </StackPanel>
<CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartFullScreen}">Откывать во весь экран</CheckBox> <CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartFullScreen}" Content="{DynamicResource fullscreen}"/>
<CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartLastScreen}">Запоминать последний выбор</CheckBox> <CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartLastScreen}" Content="{DynamicResource rememberLast}"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Grid.Column="1" Height="70" Width="70" Margin="10,0,50,0" Style="{DynamicResource ButtonBack}" Command="{Binding BackCommand}" /> <Button Grid.Column="1" Height="70" Width="70" Margin="10,0,50,0" Style="{DynamicResource ButtonBack}" Command="{Binding BackCommand}" />
<Button HorizontalAlignment="Center" Height="70" Width="70" Style="{DynamicResource ButtonConfirm}" Command="{Binding SaveCommand}" /> <Button HorizontalAlignment="Center" Height="70" Width="70" Style="{DynamicResource ButtonConfirm}" Command="{Binding SaveCommand}" />
+4 -2
View File
@@ -10,10 +10,12 @@ namespace TV_Player
private readonly ReplaySubject<Unit> programGuideSubject = new ReplaySubject<Unit>(); private readonly ReplaySubject<Unit> programGuideSubject = new ReplaySubject<Unit>();
public IObservable<List<M3UInfo>> AllPrograms => programsSubject; public IObservable<List<M3UInfo>> AllPrograms => programsSubject;
public IObservable<List<GroupInfo>> GroupsInformation => groupsSubject; public IObservable<List<GroupInfo>> GroupsInformation => groupsSubject;
public IObservable<Unit> ProgramGuideInfo => programGuideSubject; public IObservable<Unit> ProgramGuideInfo => programGuideSubject;
private readonly string _programName;
public ProgramsData(string name,string playlistURL) public ProgramsData(string name,string playlistURL)
{ {
_programName = name;
Task.Run(() => GetPrograms(name,playlistURL)); Task.Run(() => GetPrograms(name,playlistURL));
} }
@@ -34,7 +36,7 @@ namespace TV_Player
public Task<ProgramGuide> GetGuideByProgram(string channelID) public Task<ProgramGuide> GetGuideByProgram(string channelID)
{ {
return M3UParser.ParseEpg(channelID); return M3UParser.ParseEpg(_programName,channelID);
} }
private async Task GetProgramGuide(string name, string guideLink) private async Task GetProgramGuide(string name, string guideLink)
+13 -1
View File
@@ -63,7 +63,19 @@ namespace TV_Player.ViewModels
private void OnAddPlaylistCommand() private void OnAddPlaylistCommand()
{ {
Playlists.Add(new KeyValuePair<string, string>(PlaylistName, PlaylistURL)); var url = PlaylistURL?.Trim();
var name = PlaylistName?.Trim();
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(url))
return;
if (IsValidUrl(url))
Playlists.Add(new KeyValuePair<string, string>(name, url));
}
private bool IsValidUrl(string url)
{
Uri uriResult;
return Uri.TryCreate(url, UriKind.Absolute, out uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
} }
private void OnPlaylistDeleteCommand(KeyValuePair<string, string> pair) private void OnPlaylistDeleteCommand(KeyValuePair<string, string> pair)
+22 -2
View File
@@ -1,4 +1,5 @@
using System.Windows.Controls; using System.Windows;
using System.Windows.Controls;
namespace TV_Player.ViewModels namespace TV_Player.ViewModels
{ {
@@ -12,7 +13,7 @@ namespace TV_Player.ViewModels
public Action ButtonBackAction { get; set; } public Action ButtonBackAction { get; set; }
private string _currentPlaylistName; public string _currentPlaylistName;
private static TVPlayerViewModel? _instance; private static TVPlayerViewModel? _instance;
public static TVPlayerViewModel Instance public static TVPlayerViewModel Instance
@@ -44,6 +45,7 @@ namespace TV_Player.ViewModels
{ {
if (SettingsModel.Playlists!=null && SettingsModel.Playlists.Any()) if (SettingsModel.Playlists!=null && SettingsModel.Playlists.Any())
{ {
SetLanguageDictionary();
PlayListsData.Clear(); PlayListsData.Clear();
foreach (var playlist in SettingsModel.Playlists) foreach (var playlist in SettingsModel.Playlists)
{ {
@@ -64,6 +66,24 @@ namespace TV_Player.ViewModels
} }
} }
private void SetLanguageDictionary()
{
ResourceDictionary dict = new ResourceDictionary();
switch (Thread.CurrentThread.CurrentCulture.ToString())
{
case "en-US":
dict.Source = new Uri("..\\Assets\\en-US.xaml", UriKind.Relative);
break;
case "ru-RU":
dict.Source = new Uri("..\\Assets\\ru-RU.xaml", UriKind.Relative);
break;
default:
dict.Source = new Uri("..\\Assets\\en-US.xaml", UriKind.Relative);
break;
}
Application.Current.Resources.MergedDictionaries.Add(dict);
}
public void SelectScreen() public void SelectScreen()
{ {
switch (SettingsModel.LastScreen) switch (SettingsModel.LastScreen)