Skip to content

Commit

Permalink
新增 在线插件详细
Browse files Browse the repository at this point in the history
  • Loading branch information
MakesYT committed Aug 21, 2024
1 parent c630c7f commit 148321e
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 22 deletions.
82 changes: 82 additions & 0 deletions Core/AvaloniaControl/MarketPage/PluginDetail.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pluginCore="clr-namespace:PluginCore;assembly=Core"
xmlns:mdxaml="https://github.com/whistyun/Markdown.Avalonia.Tight"
xmlns:pluginManagerPage1="clr-namespace:Core.AvaloniaControl.MarketPage"
xmlns:pages="clr-namespace:Core.ViewModel.Pages"
xmlns:pluginManagerPage111="clr-namespace:KitopiaAvalonia.Converter.PluginManagerPage"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:DataType="pages:OnlinePluginInfo"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
x:Class="Core.AvaloniaControl.MarketPage.PluginDetail">
<UserControl.Resources>
<pluginManagerPage111:IconCtr x:Key="IconCtr" />
</UserControl.Resources>
<Border BorderBrush="{DynamicResource SemiColorBorder}" BorderThickness="1"
CornerRadius="{DynamicResource RadiusCardCornerRadius}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" x:DataType="pages:OnlinePluginInfo">
<Panel>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
ColumnDefinitions="80,*" x:DataType="pages:OnlinePluginInfo"

RowDefinitions="*,48">
<Image Grid.Column="0" HorizontalAlignment="Center" Margin="0,15,0,0"
VerticalAlignment="Top" Focusable="False" Width="64" x:DataType="pages:OnlinePluginInfo"
Source="{Binding Icon,Converter={StaticResource IconCtr},ConverterParameter={Binding .}}"
Height="64" />
<StackPanel Grid.Column="1" Margin="0,15,0,5" VerticalAlignment="Top" Spacing="5"
HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal" x:DataType="pages:OnlinePluginInfo" Spacing="5">
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Left"
x:DataType="pages:OnlinePluginInfo"
Text="{Binding Name}"
FontWeight="Normal" FontSize="18"
Foreground="{DynamicResource DefaultForeground}">
</TextBlock>
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Left"
x:DataType="pages:OnlinePluginInfo"
Text="{Binding LastVersion}"
FontWeight="Normal" FontSize="18"
Foreground="{DynamicResource DefaultForeground}">
</TextBlock>
</StackPanel>

<TextBlock VerticalAlignment="Center"
MaxWidth="{Binding $parent.Bounds.Width}"
TextWrapping="Wrap"
x:DataType="pages:OnlinePluginInfo"
Text="{Binding DescriptionShort}" />
<Label Theme="{DynamicResource TitleLabel}" Classes="H3" Content="详细"></Label>
<Line EndPoint="5000,0" HorizontalAlignment="Stretch" Stroke="{DynamicResource SemiColorBorder}"/>
<ScrollViewer IsHitTestVisible="False"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
HorizontalScrollBarVisibility="Hidden">

<mdxaml:MarkdownScrollViewer x:DataType="pages:OnlinePluginInfo"
Markdown="{Binding $parent[pluginManagerPage1:PluginDetail].Markdown}" ></mdxaml:MarkdownScrollViewer>
</ScrollViewer>
<ContentPresenter HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Content="{Binding $parent[pluginManagerPage1:PluginDetail].Content}">
</ContentPresenter>

</StackPanel>

</Grid>


</Panel>

</Border>
</UserControl>
60 changes: 60 additions & 0 deletions Core/AvaloniaControl/MarketPage/PluginDetail.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Threading;
using Core.SDKs.Services.Plugin;
using Core.ViewModel.Pages;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PluginCore;

namespace Core.AvaloniaControl.MarketPage;

public partial class PluginDetail : UserControl
{
public static AvaloniaProperty<Control> ContentProperty = AvaloniaProperty.Register<PluginDetail, Control>(nameof(Content));
public Control Content
{
get => (Control)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

public static AvaloniaProperty<string> MarkdownProperty = AvaloniaProperty.Register<PluginDetail, string>(nameof(Markdown));
public string Markdown
{
get => (string)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}
public PluginDetail()
{
InitializeComponent();
}

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
if (DataContext is not OnlinePluginInfo pluginInfo)
{
return;
}

Task.Run(async () =>
{
var request = new HttpRequestMessage()
{
RequestUri = new Uri($"https://www.ncserver.top:5111/api/plugin/{pluginInfo.Id}"),
Method = HttpMethod.Get,
};
request.Headers.Add("AllBeforeThisVersion", true.ToString());
var sendAsync = await PluginManager._httpClient.SendAsync(request);
var stringAsync = await sendAsync.Content.ReadAsStringAsync();
var deserializeObject = (JObject)JsonConvert.DeserializeObject(stringAsync);
var list = deserializeObject["data"]["description"].ToString();
await Dispatcher.UIThread.InvokeAsync(() =>
{
SetValue(MarkdownProperty, list);
});
});

}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pluginCore="clr-namespace:PluginCore;assembly=Core"
xmlns:pluginManagerPage="clr-namespace:KitopiaAvalonia.Converter.PluginManagerPage"
xmlns:pluginManagerPage1="clr-namespace:KitopiaAvalonia.Controls.PluginManagerPage"
xmlns:mdxaml="https://github.com/whistyun/Markdown.Avalonia.Tight"
xmlns:pluginManagerPage1="clr-namespace:Core.AvaloniaControl.PluginManagerPage"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:DataType="pluginCore:PluginInfo"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
x:Class="KitopiaAvalonia.Controls.PluginManagerPage.PluginDetail">
x:Class="Core.AvaloniaControl.PluginManagerPage.PluginDetail">
<UserControl.Resources>
<pluginManagerPage:IconCtr x:Key="IconCtr" />
</UserControl.Resources>
Expand Down Expand Up @@ -61,11 +61,14 @@
</TextBlock.Foreground>
</TextBlock>
</StackPanel>

<TextBlock VerticalAlignment="Center"
MaxWidth="{Binding $parent.Bounds.Width}"
TextWrapping="Wrap"
x:DataType="pluginCore:PluginInfo"
Text="{Binding Description}" />
<Label Theme="{DynamicResource TitleLabel}" Classes="H3" Content="详细"></Label>
<Line EndPoint="5000,0" HorizontalAlignment="Stretch" Stroke="{DynamicResource SemiColorBorder}"/>
<ScrollViewer IsHitTestVisible="False"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using Core.SDKs.Services.Plugin;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PluginCore;

namespace KitopiaAvalonia.Controls.PluginManagerPage;
namespace Core.AvaloniaControl.PluginManagerPage;

public partial class PluginDetail : UserControl
{
Expand All @@ -27,7 +26,6 @@ public string Markdown
public PluginDetail()
{
InitializeComponent();

}

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
Expand Down
5 changes: 4 additions & 1 deletion Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@


<ItemGroup>
<AdditionalFiles Include="PluginManagerPage\PluginDetail.axaml" />
<Compile Update="AvaloniaControl\MarketPage\PluginDetail.axaml.cs">
<DependentUpon>PluginDetail.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>

</Project>
82 changes: 81 additions & 1 deletion Core/ViewModel/Pages/MarketPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Shapes;
using Avalonia.Media;
using Avalonia.Styling;
using AvaloniaEdit.Utils;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Core.AvaloniaControl.PluginManagerPage;
using Core.SDKs;
using Core.SDKs.Services;
using Core.SDKs.Services.Plugin;
using KitopiaAvalonia.Tools;
using Markdown.Avalonia.Full;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PluginCore;
using SixLabors.ImageSharp;
using Bitmap = Avalonia.Media.Imaging.Bitmap;
using Image = SixLabors.ImageSharp.Image;
using JsonSerializer = System.Text.Json.JsonSerializer;
using Point = Avalonia.Point;

namespace Core.ViewModel.Pages;
public class ApiResponse
Expand Down Expand Up @@ -114,5 +127,72 @@ private async Task DownloadPlugin(OnlinePluginInfo plugin)
await PluginManager.DownloadPluginOnline(plugin);
}


[RelayCommand]
private async Task ShowPluginDetail(Control control)
{
if (control.DataContext is OnlinePluginInfo pluginInfo)
{
StackPanel stackPanel = new StackPanel();
stackPanel.Spacing = 4;

var request = new HttpRequestMessage()
{
RequestUri = new Uri($"https://www.ncserver.top:5111/api/plugin/detail/{pluginInfo.Id}/{pluginInfo.LastVersionId}"),
Method = HttpMethod.Get,
};
request.Headers.Add("AllBeforeThisVersion",true.ToString());
var sendAsync =await PluginManager._httpClient.SendAsync(request);
var stringAsync =await sendAsync.Content.ReadAsStringAsync();
var deserializeObject = (JObject)JsonConvert.DeserializeObject(stringAsync);
var list = deserializeObject["data"].ToObject<List<JObject>>();

Application.Current.Styles.TryGetResource("TitleLabel",null,out var h1);
Application.Current.Styles.TryGetResource("SemiColorBorder",null,out var semiColorBorder);
var semiColorBorder2 = semiColorBorder as SolidColorBrush;
var controlTheme = h1 as ControlTheme;
var childOfType = control.GetParentOfType<Window>().GetChildOfType<ContentPresenter>("DialogOvercover");
stackPanel.Children.Add( new Label()
{
Classes = { "H2" },
Theme =controlTheme,
Content = "版本说明"
});
stackPanel.Children.Add(new Line()
{
Stroke = semiColorBorder2,
EndPoint = new Point( childOfType.Bounds.Width,0)
});
for (var i = 0; i < list.Count; i++)
{
stackPanel.Children.Add( new Label()
{
Classes = { "H3" },
Theme =controlTheme,
Content = list[i]["version"]
});
stackPanel.Children.Add(new Line()
{
Stroke = semiColorBorder2,
EndPoint = new Point( childOfType.Bounds.Width,0)
});
stackPanel.Children.Add( new MarkdownScrollViewer()
{
Markdown = list[i]["detail"].ToString()
});
}
var pluginDetail = new AvaloniaControl.MarketPage.PluginDetail();
pluginDetail.DataContext= pluginInfo;
pluginDetail.Content = stackPanel;
var dialog = new DialogContent()
{
Content =pluginDetail,
Title = "插件详细信息",
};


ServiceManager.Services!.GetService<IContentDialog>()!.ShowDialogAsync(childOfType,
dialog,true);
}

}
}
13 changes: 12 additions & 1 deletion Core/ViewModel/Pages/plugin/PluginManagerPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Core.AvaloniaControl.PluginManagerPage;
using Core.SDKs;
using Core.SDKs.CustomScenario;
using Core.SDKs.Services;
using Core.SDKs.Services.Config;
using Core.SDKs.Services.Plugin;
using KitopiaAvalonia.Controls.PluginManagerPage;
using KitopiaAvalonia.Tools;
using log4net;
using Markdown.Avalonia.Full;
Expand Down Expand Up @@ -207,6 +207,17 @@ private async Task ShowPluginDetail(Control control)
var semiColorBorder2 = semiColorBorder as SolidColorBrush;
var controlTheme = h1 as ControlTheme;
var childOfType = control.GetParentOfType<Window>().GetChildOfType<ContentPresenter>("DialogOvercover");
stackPanel.Children.Add( new Label()
{
Classes = { "H2" },
Theme =controlTheme,
Content = "版本说明"
});
stackPanel.Children.Add(new Line()
{
Stroke = semiColorBorder2,
EndPoint = new Point( childOfType.Bounds.Width,0)
});
for (var i = 0; i < list.Count; i++)
{
stackPanel.Children.Add( new Label()
Expand Down
9 changes: 4 additions & 5 deletions KitopiaAvalonia/Controls/DialogOvercover.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@
if we put ClipToBounds=True on BackgroundElement above, it clips the shadow -->
<Border ClipToBounds="True" HorizontalAlignment="Center" Name="BackgroundElement"
BorderBrush="{DynamicResource SemiColorBorder}"
BorderThickness="1"
BorderThickness="1"
VerticalAlignment="Center" Margin="5,5,5,0"
PointerMoved="InputElement_OnPointerMoved" PointerPressed="InputElement_OnPointerPressed"
PointerMoved="InputElement_OnPointerMoved" PointerPressed="InputElement_OnPointerPressed"
PointerReleased="InputElement_OnPointerReleased">
<Border.Background>
<SolidColorBrush Opacity="0.5" Color="{DynamicResource SemiBackground0Color}"></SolidColorBrush>
</Border.Background>
<Panel>
<Grid Name="DialogSpace" ClipToBounds="True"
RowDefinitions="Auto,*,Auto">
<Panel Background="{DynamicResource ContentDialogTopOverlay}"
>
<Panel Background="{DynamicResource ContentDialogTopOverlay}">
<TextPresenter Name="Title"
Margin="5"
FontSize="20"
Expand All @@ -44,7 +43,7 @@
</Panel>
<ScrollViewer Grid.Row="1" Name="ContentScrollViewer"
HorizontalScrollBarVisibility="Disabled"
MinHeight="100"
MinHeight="200"
VerticalScrollBarVisibility="Auto">
<Border Background="{DynamicResource ContentDialogTopOverlay}"
Padding="5,0,5,0"
Expand Down
4 changes: 2 additions & 2 deletions KitopiaAvalonia/Controls/DialogOvercover.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void InputElement_OnPointerReleased(object? sender, PointerReleasedEvent
private void Visual_OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
{
var visualParent = this.GetVisualParent();
BackgroundElement.Width = visualParent.Bounds.Width / 3;
BackgroundElement.Height = visualParent.Bounds.Height / 3;
BackgroundElement.Width = visualParent.Bounds.Width / 2.5;
BackgroundElement.Height = visualParent.Bounds.Height /2;
}
}
Loading

0 comments on commit 148321e

Please sign in to comment.