Quellcode durchsuchen

News ui somewhat finished

Krzysztof Krysiński vor 2 Jahren
Ursprung
Commit
61395fd4fd

+ 1 - 0
src/PixiEditor.Extensions/Common/UserPreferences/PreferencesConstants.cs

@@ -7,4 +7,5 @@ public static class PreferencesConstants
 
     public const string MaxOpenedRecently = "MaxOpenedRecently";
     public const int MaxOpenedRecentlyDefault = 8;
+    public const string HideNewsPanel = "HideNewsPanel";
 }

+ 2 - 1
src/PixiEditor/Data/Localization/Languages/en.json

@@ -572,5 +572,6 @@
 
   "BUY_NOW": "Buy Now",
   "BUY_SUPPORTER_PACK": "Buy Supporter Pack",
-  "PALETTE_BROWSER_BUY_TEXT": "Buy Supporter Pack and get 21 beautiful palettes!"
+  "PALETTE_BROWSER_BUY_TEXT": "Buy Supporter Pack and get 21 beautiful palettes!",
+  "HIDE_NEWS_PANEL": "Hide News panel in startup window"
 }

BIN
src/PixiEditor/Images/News/Article.png


BIN
src/PixiEditor/Images/News/Misc.png


BIN
src/PixiEditor/Images/News/NewVersion.png


BIN
src/PixiEditor/Images/News/OfficialAnnouncement.png


BIN
src/PixiEditor/Images/News/YouTube.png


+ 13 - 1
src/PixiEditor/Models/Services/NewsFeed/News.cs

@@ -1,11 +1,19 @@
-namespace PixiEditor.Models.Services.NewsFeed;
+using System.ComponentModel;
+using Newtonsoft.Json;
+
+namespace PixiEditor.Models.Services.NewsFeed;
 
 internal enum NewsType
 {
+    [Description("NewVersion.png")]
     NewVersion,
+    [Description("YouTube.png")]
     YtVideo,
+    [Description("Article.png")]
     BlogPost,
+    [Description("OfficialAnnouncement.png")]
     OfficialAnnouncement,
+    [Description("Misc.png")]
     Misc
 }
 
@@ -13,8 +21,12 @@ internal record News
 {
     public string Title { get; set; }
     public string ShortDescription { get; set; }
+
     public NewsType NewsType { get; set; }
     public string Url { get; set; }
     public DateTime Date { get; set; }
     public string CustomIconUrl { get; set; }
+
+    [JsonIgnore]
+    public string ResolvedIconUrl => CustomIconUrl ?? $"/Images/News/{NewsType.GetDescription()}";
 }

+ 69 - 11
src/PixiEditor/Models/Services/NewsFeed/NewsProvider.cs

@@ -1,32 +1,90 @@
 using System.Net;
 using System.Net.Http;
 using Newtonsoft.Json;
+using PixiEditor.Platform;
 using PixiEditor.UpdateModule;
 
 namespace PixiEditor.Models.Services.NewsFeed;
 
 internal class NewsProvider
 {
-    private const int ProtocolVersion = 1;
     private const string FeedUrl = "https://raw.githubusercontent.com/PixiEditor/news-feed/main/";
     public async Task<List<News>?> FetchNewsAsync()
+    {
+        List<News> allNews = new List<News>();
+        await FetchFrom(allNews, "shared.json");
+        await FetchFrom(allNews, $"{IPlatform.Current.Id}.json");
+
+        var test = new News()
+        {
+            Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
+                    "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
+            Date = DateTime.Now,
+            ShortDescription =
+                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
+            NewsType = NewsType.BlogPost
+        };
+
+        allNews.Add(test);
+        var test1 = new News()
+        {
+            Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
+                    "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
+            Date = DateTime.Now,
+            ShortDescription =
+                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
+            NewsType = NewsType.Misc
+        };
+
+        allNews.Add(test1);
+        var test2 = new News()
+        {
+            Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
+                    "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
+            Date = DateTime.Now,
+            ShortDescription =
+                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
+            NewsType = NewsType.YtVideo
+        };
+        allNews.Add(test2);
+
+        var test3 = new News()
+        {
+            Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
+                    "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
+            Date = DateTime.Now,
+            ShortDescription =
+                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
+            NewsType = NewsType.OfficialAnnouncement
+        };
+        allNews.Add(test3);
+        var test4 = new News()
+        {
+            Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
+                    "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
+            Date = DateTime.Now,
+            ShortDescription =
+                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
+            NewsType = NewsType.NewVersion
+        };
+
+        allNews.Add(test4);
+
+        return allNews.OrderByDescending(x => x.Date).Take(20).ToList();
+    }
+
+    private static async Task FetchFrom(List<News> output, string fileName)
     {
         using HttpClient client = new HttpClient();
         client.DefaultRequestHeaders.Add("User-Agent", "PixiEditor");
-        HttpResponseMessage response = await client.GetAsync(FeedUrl + "shared.json");
+        HttpResponseMessage response = await client.GetAsync($"{FeedUrl}{fileName}");
         if (response.StatusCode == HttpStatusCode.OK)
         {
             string content = await response.Content.ReadAsStringAsync();
             var list = JsonConvert.DeserializeObject<List<News>>(content);
-            list.Add(new News(){ Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
-                                         "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec", Date = DateTime.Now,
-                ShortDescription = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec" ,
-                CustomIconUrl = "https://raw.githubusercontent.com/PixiEditor/PixiEditor/master/src/PixiEditor/Images/SocialMedia/WebsiteIcon.png"
-            });
-
-            return list;
+            {
+                output.AddRange(list);
+            }
         }
-
-        return null;
     }
 }

+ 9 - 0
src/PixiEditor/PixiEditor.csproj

@@ -278,6 +278,7 @@
 		<Resource Include="Images\Layer-add.png" />
 		<Resource Include="Images\Lock-alpha.png" />
 		<Resource Include="Images\Merge-downwards.png" />
+		<Resource Include="Images\News\Article.png" />
 		<Resource Include="Images\penMode.png" />
 		<Resource Include="Images\PixiBotLogo.png" />
 		<Resource Include="Images\PixiEditorLogo.png" />
@@ -438,6 +439,14 @@
 		<None Remove="Images\LanguageFlags\pt-br.png" />
 		<Resource Include="Images\LanguageFlags\pt-br.png" />
 		<None Remove="OfficialExtensions\supporter-pack.snk" />
+		<None Remove="Images\News\YouTube.png" />
+		<Resource Include="Images\News\YouTube.png" />
+		<None Remove="Images\News\Misc.png" />
+		<Resource Include="Images\News\Misc.png" />
+		<None Remove="Images\News\NewVersion.png" />
+		<Resource Include="Images\News\NewVersion.png" />
+		<None Remove="Images\News\OfficialAnnouncement.png" />
+		<Resource Include="Images\News\OfficialAnnouncement.png" />
 	</ItemGroup>
 	<ItemGroup>
 		<None Include="..\LICENSE">

+ 14 - 0
src/PixiEditor/Styles/LabelStyles.xaml

@@ -27,6 +27,20 @@
         </Style.Triggers>
     </Style>
 
+    <Style x:Key="LinkTextBlock" TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
+        <Setter Property="Foreground" Value="LightGray"/>
+        <Setter Property="FontSize" Value="14"/>
+        <Style.Triggers>
+            <Trigger Property="IsMouseOver" Value="True">
+                <Setter Property="Foreground" Value="White"/>
+                <Setter Property="TextDecorations" Value="Underline"/>
+            </Trigger>
+            <Trigger Property="IsMouseOver" Value="False">
+                <Setter Property="TextDecorations" Value="None"/>
+            </Trigger>
+        </Style.Triggers>
+    </Style>
+
     <Style x:Key="SettingsText" TargetType="Label" BasedOn="{StaticResource BaseLabel}">
         <Setter Property="FontSize" Value="12"/>
         <Setter Property="Padding" Value="0"/>

+ 8 - 0
src/PixiEditor/ViewModels/SubViewModels/UserPreferences/Settings/FileSettings.cs

@@ -46,4 +46,12 @@ internal class FileSettings : SettingsGroup
         get => maxOpenedRecently;
         set => RaiseAndUpdatePreference(ref maxOpenedRecently, value);
     }
+
+    private bool hideNewsPanel = GetPreference(PreferencesConstants.HideNewsPanel, false);
+
+    public bool HideNewsPanel
+    {
+        get => hideNewsPanel;
+        set => RaiseAndUpdatePreference(ref hideNewsPanel, value);
+    }
 }

+ 1 - 1
src/PixiEditor/Views/Dialogs/HelloTherePopup.xaml

@@ -44,7 +44,7 @@
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="*"/>
-            <ColumnDefinition Width="300"/>
+            <ColumnDefinition Width="300" x:Name="newsColumn"/>
         </Grid.ColumnDefinitions>
 
         <DockPanel Grid.Row="0" Grid.ColumnSpan="2" Background="{StaticResource MainColor}">

+ 29 - 7
src/PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs

@@ -3,6 +3,7 @@ using System.Diagnostics;
 using System.IO;
 using System.Windows;
 using System.Windows.Input;
+using PixiEditor.Extensions.Common.UserPreferences;
 using PixiEditor.Helpers;
 using PixiEditor.Models.Commands;
 using PixiEditor.Models.DataHolders;
@@ -52,6 +53,8 @@ internal partial class HelloTherePopup : Window
         true;
 #endif
 
+    private bool _newsHidden = false;
+
     public HelloTherePopup(FileViewModel fileViewModel)
     {
         DataContext = this;
@@ -66,25 +69,35 @@ internal partial class HelloTherePopup : Window
         RecentlyOpenedEmpty = RecentlyOpened.Count == 0;
         RecentlyOpened.CollectionChanged += RecentlyOpened_CollectionChanged;
 
+        _newsHidden = IPreferences.Current.GetPreference<bool>(PreferencesConstants.HideNewsPanel);
+
         NewsProvider = new NewsProvider();
 
         Closing += (_, _) => { IsClosing = true; };
 
         InitializeComponent();
 
+        int newsWidth = 200;
+
+        if (_newsHidden)
+        {
+            newsColumn.Width = new GridLength(0);
+            newsWidth = 0;
+        }
+
         if (RecentlyOpenedEmpty)
         {
-            Width = 700;
+            Width = 500 + newsWidth;
             Height = 500;
         }
         else if (RecentlyOpened.Count < 4)
         {
-            Width = 745;
+            Width = 545 + newsWidth;
             Height = 500;
         }
         else if (RecentlyOpened.Count < 7)
         {
-            Width = 775;
+            Width = 575 + newsWidth;
             Height = 670;
         }
     }
@@ -135,11 +148,20 @@ internal partial class HelloTherePopup : Window
 
     private async void HelloTherePopup_OnLoaded(object sender, RoutedEventArgs e)
     {
-        var news = await NewsProvider.FetchNewsAsync();
-        if (news is not null)
+        if(_newsHidden) return;
+
+        try
+        {
+            var news = await NewsProvider.FetchNewsAsync();
+            if (news is not null)
+            {
+                News.Clear();
+                News.AddRange(news);
+            }
+        }
+        catch
         {
-            News.Clear();
-            News.AddRange(news);
+            // TODO: Display error message
         }
     }
 }

+ 5 - 1
src/PixiEditor/Views/Dialogs/SettingsWindow.xaml

@@ -115,10 +115,14 @@
                           IsChecked="{Binding SettingsSubViewModel.File.ShowStartupWindow}"/>
 
                 <CheckBox Margin="27 10"
+                          VerticalAlignment="Center" ui:Translator.Key="HIDE_NEWS_PANEL" d:Content="Hide news in startup window"
+                          IsChecked="{Binding SettingsSubViewModel.File.HideNewsPanel}"/>
+
+                <CheckBox Margin="27 0"
                           VerticalAlignment="Center" d:Content="Show image preview in taskbar" ui:Translator.Key="SHOW_IMAGE_PREVIEW_TASKBAR"
                           IsChecked="{Binding SettingsSubViewModel.General.ImagePreviewInTaskbar}"/>
 
-                <StackPanel Margin="27 0" Orientation="Horizontal">
+                <StackPanel Margin="27 10 27 0" Orientation="Horizontal">
                 <Label Style="{StaticResource SettingsText}"
                        ui:Translator.Key="RECENT_FILE_LENGTH"
                        ui:Translator.TooltipKey="RECENT_FILE_LENGTH_TOOLTIP"/>

+ 13 - 4
src/PixiEditor/Views/UserControls/NewsFeed/NewsItem.xaml

@@ -6,23 +6,32 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:local="clr-namespace:PixiEditor.Views.UserControls.NewsFeed"
              xmlns:xaml="clr-namespace:PixiEditor.Models.Commands.XAML"
+             xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
              mc:Ignorable="d" Name="newsItem"
              d:DesignHeight="300" d:DesignWidth="300">
-    <Border Background="{StaticResource MainColor}" Padding="5" CornerRadius="5">
+    <Border Background="{StaticResource MainColor}" Padding="8" CornerRadius="5">
         <StackPanel Orientation="Vertical">
             <StackPanel Orientation="Horizontal">
-                <Image Margin="0 0 5 0" Width="25" Source="{Binding ElementName=newsItem, Path=News.CustomIconUrl}"/>
+                <Image Margin="0 0 5 0" Width="25"
+                       Source="{Binding ElementName=newsItem, Path=News.ResolvedIconUrl}"/>
                 <Label VerticalAlignment="Center" Foreground="White" FontSize="14" HorizontalAlignment="Center">
                     <Hyperlink
                                Command="{xaml:Command PixiEditor.Links.OpenHyperlink, UseProvided=True}"
                                CommandParameter="{Binding ElementName=newsItem, Path=News.Url}"
                                Style="{StaticResource SettingsLink}">
-                        <Run Text="{Binding ElementName=newsItem, Path=News.Title}"/>
+                        <TextBlock Width="200" TextTrimming="CharacterEllipsis" MaxHeight="50"
+                                   ToolTip="{Binding ElementName=newsItem, Path=News.Title}"
+                                   Style="{StaticResource LinkTextBlock}" TextWrapping="Wrap"
+                                   Text="{Binding ElementName=newsItem, Path=News.Title}"/>
                         <Run Text="" FontFamily="{StaticResource Feather}"/>
                     </Hyperlink>
                 </Label>
             </StackPanel>
-            <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Foreground="White" FontSize="12" Text="{Binding ElementName=newsItem, Path=News.ShortDescription}"/>
+            <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Foreground="White" FontSize="12"
+                       Text="{Binding ElementName=newsItem, Path=News.ShortDescription}"
+                       MaxHeight="50" TextTrimming="CharacterEllipsis"/>
+            <TextBlock Margin="0 2.5" HorizontalAlignment="Right" FontSize="12" Foreground="LightGray"
+                       Text="{Binding ElementName=newsItem, Path=News.Date, StringFormat=d}"/>
         </StackPanel>
     </Border>
 </UserControl>