mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
About tab - Fixed my icon being smoll, lmao
About tab - Use async image loader instead of manual bitmaps Workshop - Use async image loader for entry icons
This commit is contained in:
parent
2a34381926
commit
e21edd0ed6
@ -18,6 +18,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AsyncImageLoader.Avalonia" Version="3.2.0" />
|
||||||
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
|
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
|
||||||
<PackageReference Include="Avalonia.Controls.PanAndZoom" Version="11.0.0" />
|
<PackageReference Include="Avalonia.Controls.PanAndZoom" Version="11.0.0" />
|
||||||
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
|
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
|
||||||
|
|||||||
21
src/Artemis.UI/Converters/EntryIconUriConverter.cs
Normal file
21
src/Artemis.UI/Converters/EntryIconUriConverter.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Artemis.WebClient.Workshop;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Converters;
|
||||||
|
|
||||||
|
public class EntryIconUriConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is Guid guid)
|
||||||
|
return $"{WorkshopConstants.WORKSHOP_URL}/entries/{guid}/icon";
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@
|
|||||||
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||||
xmlns:vm="clr-namespace:Artemis.UI.Screens.Settings;assembly=Artemis.UI"
|
xmlns:vm="clr-namespace:Artemis.UI.Screens.Settings;assembly=Artemis.UI"
|
||||||
|
xmlns:il="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
|
||||||
x:DataType="vm:AboutTabViewModel"
|
x:DataType="vm:AboutTabViewModel"
|
||||||
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1400"
|
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1400"
|
||||||
x:Class="Artemis.UI.Screens.Settings.AboutTabView">
|
x:Class="Artemis.UI.Screens.Settings.AboutTabView">
|
||||||
@ -18,7 +19,7 @@
|
|||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Source="/Assets/Images/Logo/bow.png"
|
Source="/Assets/Images/Logo/bow.png"
|
||||||
Margin="0 0 20 0"
|
Margin="0 0 20 0"
|
||||||
RenderOptions.BitmapInterpolationMode="HighQuality"/>
|
RenderOptions.BitmapInterpolationMode="HighQuality" />
|
||||||
<TextBlock Grid.Row="0" Grid.Column="1" FontSize="36" VerticalAlignment="Bottom">
|
<TextBlock Grid.Row="0" Grid.Column="1" FontSize="36" VerticalAlignment="Bottom">
|
||||||
Artemis 2
|
Artemis 2
|
||||||
</TextBlock>
|
</TextBlock>
|
||||||
@ -52,17 +53,9 @@
|
|||||||
<Border Classes="card" Margin="0 20 0 10">
|
<Border Classes="card" Margin="0 20 0 10">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<Grid RowDefinitions="*,*,*" ColumnDefinitions="Auto,*">
|
<Grid RowDefinitions="*,*,*" ColumnDefinitions="Auto,*">
|
||||||
<Ellipse Grid.Row="0"
|
<Ellipse Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" VerticalAlignment="Top" Height="75" Width="75" Margin="0 0 15 0">
|
||||||
Grid.Column="0"
|
|
||||||
Grid.RowSpan="3"
|
|
||||||
VerticalAlignment="Top"
|
|
||||||
Height="40"
|
|
||||||
Width="40"
|
|
||||||
Margin="0 0 15 0"
|
|
||||||
IsVisible="{CompiledBinding RobertProfileImage, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
|
||||||
RenderOptions.BitmapInterpolationMode="HighQuality">
|
|
||||||
<Ellipse.Fill>
|
<Ellipse.Fill>
|
||||||
<ImageBrush Source="{CompiledBinding RobertProfileImage}" />
|
<ImageBrush il:ImageBrushLoader.Source="https://avatars.githubusercontent.com/u/8858506" />
|
||||||
</Ellipse.Fill>
|
</Ellipse.Fill>
|
||||||
</Ellipse>
|
</Ellipse>
|
||||||
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0">
|
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0">
|
||||||
@ -81,17 +74,9 @@
|
|||||||
<Border Classes="card-separator" />
|
<Border Classes="card-separator" />
|
||||||
|
|
||||||
<Grid RowDefinitions="*,*,*" ColumnDefinitions="Auto,*">
|
<Grid RowDefinitions="*,*,*" ColumnDefinitions="Auto,*">
|
||||||
<Ellipse Grid.Row="0"
|
<Ellipse Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" VerticalAlignment="Top" Height="75" Width="75" Margin="0 0 15 0">
|
||||||
Grid.Column="0"
|
|
||||||
Grid.RowSpan="3"
|
|
||||||
VerticalAlignment="Top"
|
|
||||||
Height="75"
|
|
||||||
Width="75"
|
|
||||||
Margin="0 0 15 0"
|
|
||||||
IsVisible="{CompiledBinding DarthAffeProfileImage, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
|
||||||
RenderOptions.BitmapInterpolationMode="HighQuality">
|
|
||||||
<Ellipse.Fill>
|
<Ellipse.Fill>
|
||||||
<ImageBrush Source="{CompiledBinding DarthAffeProfileImage}" />
|
<ImageBrush il:ImageBrushLoader.Source="https://avatars.githubusercontent.com/u/1094841" />
|
||||||
</Ellipse.Fill>
|
</Ellipse.Fill>
|
||||||
</Ellipse>
|
</Ellipse>
|
||||||
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0">
|
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0">
|
||||||
@ -110,17 +95,9 @@
|
|||||||
<Border Classes="card-separator" />
|
<Border Classes="card-separator" />
|
||||||
|
|
||||||
<Grid RowDefinitions="*,*,*" ColumnDefinitions="Auto,*">
|
<Grid RowDefinitions="*,*,*" ColumnDefinitions="Auto,*">
|
||||||
<Ellipse Grid.Row="0"
|
<Ellipse Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" VerticalAlignment="Top" Height="75" Width="75" Margin="0 0 15 0">
|
||||||
Grid.Column="0"
|
|
||||||
Grid.RowSpan="3"
|
|
||||||
VerticalAlignment="Top"
|
|
||||||
Height="75"
|
|
||||||
Width="75"
|
|
||||||
Margin="0 0 15 0"
|
|
||||||
IsVisible="{CompiledBinding DrMeteorProfileImage, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
|
||||||
RenderOptions.BitmapInterpolationMode="HighQuality">
|
|
||||||
<Ellipse.Fill>
|
<Ellipse.Fill>
|
||||||
<ImageBrush Source="{CompiledBinding DrMeteorProfileImage}" />
|
<ImageBrush il:ImageBrushLoader.Source="https://avatars.githubusercontent.com/u/29486064" />
|
||||||
</Ellipse.Fill>
|
</Ellipse.Fill>
|
||||||
</Ellipse>
|
</Ellipse>
|
||||||
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0">
|
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0">
|
||||||
@ -139,17 +116,9 @@
|
|||||||
<Border Classes="card-separator" />
|
<Border Classes="card-separator" />
|
||||||
|
|
||||||
<Grid RowDefinitions="*,*,*" ColumnDefinitions="Auto,*">
|
<Grid RowDefinitions="*,*,*" ColumnDefinitions="Auto,*">
|
||||||
<Ellipse Grid.Row="0"
|
<Ellipse Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" VerticalAlignment="Top" Height="75" Width="75" Margin="0 0 15 0">
|
||||||
Grid.Column="0"
|
|
||||||
Grid.RowSpan="3"
|
|
||||||
VerticalAlignment="Top"
|
|
||||||
Height="75"
|
|
||||||
Width="75"
|
|
||||||
Margin="0 0 15 0"
|
|
||||||
IsVisible="{CompiledBinding KaiProfileImage, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
|
||||||
RenderOptions.BitmapInterpolationMode="HighQuality">
|
|
||||||
<Ellipse.Fill>
|
<Ellipse.Fill>
|
||||||
<ImageBrush Source="{CompiledBinding KaiProfileImage}" />
|
<ImageBrush il:ImageBrushLoader.Source="https://i.imgur.com/8mPWY1j.png" />
|
||||||
</Ellipse.Fill>
|
</Ellipse.Fill>
|
||||||
</Ellipse>
|
</Ellipse>
|
||||||
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0">
|
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0">
|
||||||
|
|||||||
@ -1,75 +1,15 @@
|
|||||||
using System;
|
using Artemis.Core;
|
||||||
using System.Reactive.Disposables;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Artemis.Core;
|
|
||||||
using Artemis.UI.Shared;
|
using Artemis.UI.Shared;
|
||||||
using Avalonia.Media.Imaging;
|
|
||||||
using Flurl.Http;
|
|
||||||
using ReactiveUI;
|
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Settings;
|
namespace Artemis.UI.Screens.Settings;
|
||||||
|
|
||||||
public class AboutTabViewModel : ActivatableViewModelBase
|
public class AboutTabViewModel : ActivatableViewModelBase
|
||||||
{
|
{
|
||||||
private Bitmap? _darthAffeProfileImage;
|
|
||||||
private Bitmap? _drMeteorProfileImage;
|
|
||||||
private Bitmap? _kaiProfileImage;
|
|
||||||
private Bitmap? _robertProfileImage;
|
|
||||||
private string? _version;
|
|
||||||
|
|
||||||
public AboutTabViewModel()
|
public AboutTabViewModel()
|
||||||
{
|
{
|
||||||
DisplayName = "About";
|
DisplayName = "About";
|
||||||
this.WhenActivated((CompositeDisposable _) => Task.Run(Activate));
|
|
||||||
}
|
|
||||||
|
|
||||||
public string? Version
|
|
||||||
{
|
|
||||||
get => _version;
|
|
||||||
set => RaiseAndSetIfChanged(ref _version, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bitmap? RobertProfileImage
|
|
||||||
{
|
|
||||||
get => _robertProfileImage;
|
|
||||||
set => RaiseAndSetIfChanged(ref _robertProfileImage, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bitmap? DarthAffeProfileImage
|
|
||||||
{
|
|
||||||
get => _darthAffeProfileImage;
|
|
||||||
set => RaiseAndSetIfChanged(ref _darthAffeProfileImage, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bitmap? DrMeteorProfileImage
|
|
||||||
{
|
|
||||||
get => _drMeteorProfileImage;
|
|
||||||
set => RaiseAndSetIfChanged(ref _drMeteorProfileImage, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bitmap? KaiProfileImage
|
|
||||||
{
|
|
||||||
get => _kaiProfileImage;
|
|
||||||
set => RaiseAndSetIfChanged(ref _kaiProfileImage, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task Activate()
|
|
||||||
{
|
|
||||||
AssemblyInformationalVersionAttribute? versionAttribute = typeof(AboutTabViewModel).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
|
||||||
Version = $"Version {Constants.CurrentVersion}";
|
Version = $"Version {Constants.CurrentVersion}";
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
RobertProfileImage = new Bitmap(await "https://avatars.githubusercontent.com/u/8858506".GetStreamAsync());
|
|
||||||
RobertProfileImage = new Bitmap(await "https://avatars.githubusercontent.com/u/8858506".GetStreamAsync());
|
|
||||||
DarthAffeProfileImage = new Bitmap(await "https://avatars.githubusercontent.com/u/1094841".GetStreamAsync());
|
|
||||||
DrMeteorProfileImage = new Bitmap(await "https://avatars.githubusercontent.com/u/29486064".GetStreamAsync());
|
|
||||||
KaiProfileImage = new Bitmap(await "https://i.imgur.com/8mPWY1j.png".GetStreamAsync());
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
// ignored, unluckyyyy
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Version { get; }
|
||||||
}
|
}
|
||||||
@ -3,11 +3,15 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||||
xmlns:entries="clr-namespace:Artemis.UI.Screens.Workshop.Profile"
|
|
||||||
xmlns:entries1="clr-namespace:Artemis.UI.Screens.Workshop.Entries"
|
xmlns:entries1="clr-namespace:Artemis.UI.Screens.Workshop.Entries"
|
||||||
|
xmlns:il="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
|
||||||
|
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="110"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="110"
|
||||||
x:Class="Artemis.UI.Screens.Workshop.Entries.EntryListView"
|
x:Class="Artemis.UI.Screens.Workshop.Entries.EntryListView"
|
||||||
x:DataType="entries1:EntryListViewModel">
|
x:DataType="entries1:EntryListViewModel">
|
||||||
|
<UserControl.Resources>
|
||||||
|
<converters:EntryIconUriConverter x:Key="EntryIconUriConverter" />
|
||||||
|
</UserControl.Resources>
|
||||||
<Button MinHeight="110"
|
<Button MinHeight="110"
|
||||||
MaxHeight="140"
|
MaxHeight="140"
|
||||||
Padding="16"
|
Padding="16"
|
||||||
@ -26,15 +30,12 @@
|
|||||||
Width="80"
|
Width="80"
|
||||||
Height="80"
|
Height="80"
|
||||||
ClipToBounds="True">
|
ClipToBounds="True">
|
||||||
<Image Source="{CompiledBinding EntryIcon}"
|
<Image Stretch="UniformToFill" il:ImageLoader.Source="{CompiledBinding Entry.Id, Converter={StaticResource EntryIconUriConverter}, Mode=OneWay}" />
|
||||||
Stretch="UniformToFill"
|
|
||||||
Classes="fade-in"
|
|
||||||
Classes.faded-in="{CompiledBinding EntryIcon, Converter={x:Static ObjectConverters.IsNotNull}}" />
|
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<!-- Body -->
|
<!-- Body -->
|
||||||
<Grid Grid.Column="1" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
|
<Grid Grid.Column="1" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
|
||||||
<TextBlock Grid.Row="0" Margin="0 0 0 5" TextTrimming="CharacterEllipsis" >
|
<TextBlock Grid.Row="0" Margin="0 0 0 5" TextTrimming="CharacterEllipsis">
|
||||||
<Run Classes="h5" Text="{CompiledBinding Entry.Name, FallbackValue=Title}" />
|
<Run Classes="h5" Text="{CompiledBinding Entry.Name, FallbackValue=Title}" />
|
||||||
<Run Classes="subtitle">by</Run>
|
<Run Classes="subtitle">by</Run>
|
||||||
<Run Classes="subtitle" Text="{CompiledBinding Entry.Author, FallbackValue=Author}" />
|
<Run Classes="subtitle" Text="{CompiledBinding Entry.Author, FallbackValue=Author}" />
|
||||||
@ -43,7 +44,8 @@
|
|||||||
Classes="subtitle"
|
Classes="subtitle"
|
||||||
TextWrapping="Wrap"
|
TextWrapping="Wrap"
|
||||||
TextTrimming="CharacterEllipsis"
|
TextTrimming="CharacterEllipsis"
|
||||||
Text="{CompiledBinding Entry.Summary, FallbackValue=Summary}"></TextBlock>
|
Text="{CompiledBinding Entry.Summary, FallbackValue=Summary}">
|
||||||
|
</TextBlock>
|
||||||
|
|
||||||
<ItemsControl Grid.Row="2" ItemsSource="{CompiledBinding Entry.Categories}">
|
<ItemsControl Grid.Row="2" ItemsSource="{CompiledBinding Entry.Categories}">
|
||||||
<ItemsControl.ItemsPanel>
|
<ItemsControl.ItemsPanel>
|
||||||
|
|||||||
@ -16,26 +16,16 @@ namespace Artemis.UI.Screens.Workshop.Entries;
|
|||||||
public class EntryListViewModel : ActivatableViewModelBase
|
public class EntryListViewModel : ActivatableViewModelBase
|
||||||
{
|
{
|
||||||
private readonly IRouter _router;
|
private readonly IRouter _router;
|
||||||
private readonly IWorkshopService _workshopService;
|
|
||||||
private ObservableAsPropertyHelper<Bitmap?>? _entryIcon;
|
|
||||||
|
|
||||||
public EntryListViewModel(IGetEntries_Entries_Items entry, IRouter router, IWorkshopService workshopService)
|
public EntryListViewModel(IGetEntries_Entries_Items entry, IRouter router)
|
||||||
{
|
{
|
||||||
_router = router;
|
_router = router;
|
||||||
_workshopService = workshopService;
|
|
||||||
|
|
||||||
Entry = entry;
|
Entry = entry;
|
||||||
NavigateToEntry = ReactiveCommand.CreateFromTask(ExecuteNavigateToEntry);
|
NavigateToEntry = ReactiveCommand.CreateFromTask(ExecuteNavigateToEntry);
|
||||||
|
|
||||||
this.WhenActivated(d =>
|
|
||||||
{
|
|
||||||
_entryIcon = Observable.FromAsync(GetIcon).ToProperty(this, vm => vm.EntryIcon);
|
|
||||||
_entryIcon.DisposeWith(d);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGetEntries_Entries_Items Entry { get; }
|
public IGetEntries_Entries_Items Entry { get; }
|
||||||
public Bitmap? EntryIcon => _entryIcon?.Value;
|
|
||||||
public ReactiveCommand<Unit, Unit> NavigateToEntry { get; }
|
public ReactiveCommand<Unit, Unit> NavigateToEntry { get; }
|
||||||
|
|
||||||
private async Task ExecuteNavigateToEntry()
|
private async Task ExecuteNavigateToEntry()
|
||||||
@ -54,12 +44,4 @@ public class EntryListViewModel : ActivatableViewModelBase
|
|||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Bitmap?> GetIcon(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
// Take at least 100ms to allow the UI to load and make the whole thing smooth
|
|
||||||
Task<Bitmap?> iconTask = _workshopService.GetEntryIcon(Entry.Id, cancellationToken);
|
|
||||||
await Task.Delay(100, cancellationToken);
|
|
||||||
return await iconTask;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -4,9 +4,14 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:profile="clr-namespace:Artemis.UI.Screens.Workshop.Profile"
|
xmlns:profile="clr-namespace:Artemis.UI.Screens.Workshop.Profile"
|
||||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||||
|
xmlns:il="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
|
||||||
|
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Artemis.UI.Screens.Workshop.Profile.ProfileDetailsView"
|
x:Class="Artemis.UI.Screens.Workshop.Profile.ProfileDetailsView"
|
||||||
x:DataType="profile:ProfileDetailsViewModel">
|
x:DataType="profile:ProfileDetailsViewModel">
|
||||||
|
<UserControl.Resources>
|
||||||
|
<converters:EntryIconUriConverter x:Key="EntryIconUriConverter" />
|
||||||
|
</UserControl.Resources>
|
||||||
<Border Classes="router-container">
|
<Border Classes="router-container">
|
||||||
<Grid ColumnDefinitions="300,*" RowDefinitions="Auto,*" Margin="10">
|
<Grid ColumnDefinitions="300,*" RowDefinitions="Auto,*" Margin="10">
|
||||||
<Border Classes="card" Grid.Row="1" Grid.Column="0" Margin="0 0 10 0">
|
<Border Classes="card" Grid.Row="1" Grid.Column="0" Margin="0 0 10 0">
|
||||||
@ -18,10 +23,7 @@
|
|||||||
Width="80"
|
Width="80"
|
||||||
Height="80"
|
Height="80"
|
||||||
ClipToBounds="True">
|
ClipToBounds="True">
|
||||||
<Image Source="{CompiledBinding EntryIcon}"
|
<Image Stretch="UniformToFill" il:ImageLoader.Source="{CompiledBinding Entry.Id, Converter={StaticResource EntryIconUriConverter}, Mode=OneWay}" />
|
||||||
Stretch="UniformToFill"
|
|
||||||
Classes="fade-in"
|
|
||||||
Classes.faded-in="{CompiledBinding EntryIcon, Converter={x:Static ObjectConverters.IsNotNull}}" />
|
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<TextBlock Theme="{StaticResource TitleTextBlockStyle}"
|
<TextBlock Theme="{StaticResource TitleTextBlockStyle}"
|
||||||
|
|||||||
@ -5,7 +5,6 @@ using Artemis.UI.Screens.Workshop.Parameters;
|
|||||||
using Artemis.UI.Shared;
|
using Artemis.UI.Shared;
|
||||||
using Artemis.UI.Shared.Routing;
|
using Artemis.UI.Shared.Routing;
|
||||||
using Artemis.WebClient.Workshop;
|
using Artemis.WebClient.Workshop;
|
||||||
using Artemis.WebClient.Workshop.Services;
|
|
||||||
using Avalonia.Media.Imaging;
|
using Avalonia.Media.Imaging;
|
||||||
using StrawberryShake;
|
using StrawberryShake;
|
||||||
|
|
||||||
@ -14,14 +13,12 @@ namespace Artemis.UI.Screens.Workshop.Profile;
|
|||||||
public class ProfileDetailsViewModel : RoutableScreen<ActivatableViewModelBase, WorkshopDetailParameters>, IWorkshopViewModel
|
public class ProfileDetailsViewModel : RoutableScreen<ActivatableViewModelBase, WorkshopDetailParameters>, IWorkshopViewModel
|
||||||
{
|
{
|
||||||
private readonly IWorkshopClient _client;
|
private readonly IWorkshopClient _client;
|
||||||
private readonly IWorkshopService _workshopService;
|
|
||||||
private IGetEntryById_Entry? _entry;
|
private IGetEntryById_Entry? _entry;
|
||||||
private Bitmap? _entryIcon;
|
private Bitmap? _entryIcon;
|
||||||
|
|
||||||
public ProfileDetailsViewModel(IWorkshopClient client, IWorkshopService workshopService)
|
public ProfileDetailsViewModel(IWorkshopClient client)
|
||||||
{
|
{
|
||||||
_client = client;
|
_client = client;
|
||||||
_workshopService = workshopService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntryType? EntryType => null;
|
public EntryType? EntryType => null;
|
||||||
@ -29,13 +26,7 @@ public class ProfileDetailsViewModel : RoutableScreen<ActivatableViewModelBase,
|
|||||||
public IGetEntryById_Entry? Entry
|
public IGetEntryById_Entry? Entry
|
||||||
{
|
{
|
||||||
get => _entry;
|
get => _entry;
|
||||||
set => RaiseAndSetIfChanged(ref _entry, value);
|
private set => RaiseAndSetIfChanged(ref _entry, value);
|
||||||
}
|
|
||||||
|
|
||||||
public Bitmap? EntryIcon
|
|
||||||
{
|
|
||||||
get => _entryIcon;
|
|
||||||
set => RaiseAndSetIfChanged(ref _entryIcon, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnNavigating(WorkshopDetailParameters parameters, NavigationArguments args, CancellationToken cancellationToken)
|
public override async Task OnNavigating(WorkshopDetailParameters parameters, NavigationArguments args, CancellationToken cancellationToken)
|
||||||
@ -49,10 +40,6 @@ public class ProfileDetailsViewModel : RoutableScreen<ActivatableViewModelBase,
|
|||||||
if (result.IsErrorResult())
|
if (result.IsErrorResult())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Bitmap? oldEntryIcon = EntryIcon;
|
|
||||||
Entry = result.Data?.Entry;
|
Entry = result.Data?.Entry;
|
||||||
EntryIcon = await _workshopService.GetEntryIcon(entryId, cancellationToken);
|
|
||||||
|
|
||||||
oldEntryIcon?.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,9 +3,14 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:search="clr-namespace:Artemis.UI.Screens.Workshop.Search"
|
xmlns:search="clr-namespace:Artemis.UI.Screens.Workshop.Search"
|
||||||
|
xmlns:il="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
|
||||||
|
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="80"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="80"
|
||||||
x:Class="Artemis.UI.Screens.Workshop.Search.SearchResultView"
|
x:Class="Artemis.UI.Screens.Workshop.Search.SearchResultView"
|
||||||
x:DataType="search:SearchResultViewModel">
|
x:DataType="search:SearchResultViewModel">
|
||||||
|
<UserControl.Resources>
|
||||||
|
<converters:EntryIconUriConverter x:Key="EntryIconUriConverter" />
|
||||||
|
</UserControl.Resources>
|
||||||
<Grid ColumnDefinitions="Auto,*,Auto" Margin="0 5">
|
<Grid ColumnDefinitions="Auto,*,Auto" Margin="0 5">
|
||||||
<!-- Icon -->
|
<!-- Icon -->
|
||||||
<Border Grid.Column="0"
|
<Border Grid.Column="0"
|
||||||
@ -16,16 +21,13 @@
|
|||||||
Width="50"
|
Width="50"
|
||||||
Height="50"
|
Height="50"
|
||||||
ClipToBounds="True">
|
ClipToBounds="True">
|
||||||
<Image Source="{CompiledBinding EntryIcon}"
|
<Image Stretch="UniformToFill" il:ImageLoader.Source="{CompiledBinding Entry.Id, Converter={StaticResource EntryIconUriConverter}, Mode=OneWay}" />
|
||||||
Stretch="UniformToFill"
|
|
||||||
Classes="fade-in"
|
|
||||||
Classes.faded-in="{CompiledBinding EntryIcon, Converter={x:Static ObjectConverters.IsNotNull}}" />
|
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<!-- Body -->
|
<!-- Body -->
|
||||||
<Grid Grid.Column="1" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
|
<Grid Grid.Column="1" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
|
||||||
<TextBlock Grid.Row="0" TextTrimming="CharacterEllipsis">
|
<TextBlock Grid.Row="0" TextTrimming="CharacterEllipsis">
|
||||||
<Run Text="{CompiledBinding Entry.Name, FallbackValue=Title}" />
|
<Run Text="{CompiledBinding Entry.Name, FallbackValue=Title}" />
|
||||||
<Run Classes="subtitle" FontSize="12">by</Run>
|
<Run Classes="subtitle" FontSize="12">by</Run>
|
||||||
<Run Classes="subtitle" FontSize="12" Text="{CompiledBinding Entry.Author, FallbackValue=Author}" />
|
<Run Classes="subtitle" FontSize="12" Text="{CompiledBinding Entry.Author, FallbackValue=Author}" />
|
||||||
</TextBlock>
|
</TextBlock>
|
||||||
|
|||||||
@ -1,32 +1,14 @@
|
|||||||
using System.Reactive.Disposables;
|
|
||||||
using System.Reactive.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Artemis.UI.Shared;
|
using Artemis.UI.Shared;
|
||||||
using Artemis.WebClient.Workshop;
|
using Artemis.WebClient.Workshop;
|
||||||
using Artemis.WebClient.Workshop.Services;
|
|
||||||
using Avalonia.Media.Imaging;
|
|
||||||
using ReactiveUI;
|
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Workshop.Search;
|
namespace Artemis.UI.Screens.Workshop.Search;
|
||||||
|
|
||||||
public class SearchResultViewModel : ActivatableViewModelBase
|
public class SearchResultViewModel : ActivatableViewModelBase
|
||||||
{
|
{
|
||||||
private readonly IWorkshopService _workshopService;
|
public SearchResultViewModel(ISearchEntries_SearchEntries entry)
|
||||||
private ObservableAsPropertyHelper<Bitmap?>? _entryIcon;
|
|
||||||
|
|
||||||
public SearchResultViewModel(ISearchEntries_SearchEntries entry, IWorkshopService workshopService)
|
|
||||||
{
|
{
|
||||||
_workshopService = workshopService;
|
|
||||||
|
|
||||||
Entry = entry;
|
Entry = entry;
|
||||||
this.WhenActivated(d =>
|
|
||||||
{
|
|
||||||
_entryIcon = Observable.FromAsync(c => _workshopService.GetEntryIcon(Entry.Id, c)).ToProperty(this, vm => vm.EntryIcon);
|
|
||||||
_entryIcon.DisposeWith(d);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISearchEntries_SearchEntries Entry { get; }
|
public ISearchEntries_SearchEntries Entry { get; }
|
||||||
public Bitmap? EntryIcon => _entryIcon?.Value;
|
|
||||||
}
|
}
|
||||||
@ -19,16 +19,14 @@ public class SearchViewModel : ViewModelBase
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IRouter _router;
|
private readonly IRouter _router;
|
||||||
private readonly IWorkshopClient _workshopClient;
|
private readonly IWorkshopClient _workshopClient;
|
||||||
private readonly IWorkshopService _workshopService;
|
|
||||||
private EntryType? _entryType;
|
private EntryType? _entryType;
|
||||||
private bool _isLoading;
|
private bool _isLoading;
|
||||||
private SearchResultViewModel? _selectedEntry;
|
private SearchResultViewModel? _selectedEntry;
|
||||||
|
|
||||||
public SearchViewModel(ILogger logger, IWorkshopClient workshopClient, IWorkshopService workshopService, IRouter router, CurrentUserViewModel currentUserViewModel)
|
public SearchViewModel(ILogger logger, IWorkshopClient workshopClient, IRouter router, CurrentUserViewModel currentUserViewModel)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_workshopClient = workshopClient;
|
_workshopClient = workshopClient;
|
||||||
_workshopService = workshopService;
|
|
||||||
_router = router;
|
_router = router;
|
||||||
CurrentUserViewModel = currentUserViewModel;
|
CurrentUserViewModel = currentUserViewModel;
|
||||||
SearchAsync = ExecuteSearchAsync;
|
SearchAsync = ExecuteSearchAsync;
|
||||||
@ -79,7 +77,7 @@ public class SearchViewModel : ViewModelBase
|
|||||||
|
|
||||||
IsLoading = true;
|
IsLoading = true;
|
||||||
IOperationResult<ISearchEntriesResult> results = await _workshopClient.SearchEntries.ExecuteAsync(input, EntryType, cancellationToken);
|
IOperationResult<ISearchEntriesResult> results = await _workshopClient.SearchEntries.ExecuteAsync(input, EntryType, cancellationToken);
|
||||||
return results.Data?.SearchEntries.Select(e => new SearchResultViewModel(e, _workshopService) as object) ?? new List<object>();
|
return results.Data?.SearchEntries.Select(e => new SearchResultViewModel(e) as object) ?? new List<object>();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
<!-- <FluentTheme Mode="Dark"></FluentTheme> -->
|
<!-- <FluentTheme Mode="Dark"></FluentTheme> -->
|
||||||
<StyleInclude Source="avares://Artemis.UI.Shared/Styles/Artemis.axaml" />
|
<StyleInclude Source="avares://Artemis.UI.Shared/Styles/Artemis.axaml" />
|
||||||
|
<StyleInclude Source="avares://AsyncImageLoader.Avalonia/AdvancedImage.axaml" />
|
||||||
|
|
||||||
<Styles.Resources>
|
<Styles.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
|
|||||||
@ -23,40 +23,6 @@ public class WorkshopService : IWorkshopService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public async Task<Bitmap?> GetEntryIcon(Guid entryId, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
await _iconCacheLock.WaitAsync(cancellationToken);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_entryIconCache.TryGetValue(entryId, out Stream? cachedBitmap))
|
|
||||||
{
|
|
||||||
cachedBitmap.Seek(0, SeekOrigin.Begin);
|
|
||||||
return new Bitmap(cachedBitmap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_iconCacheLock.Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpClient client = _httpClientFactory.CreateClient(WorkshopConstants.WORKSHOP_CLIENT_NAME);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
HttpResponseMessage response = await client.GetAsync($"entries/{entryId}/icon", cancellationToken);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
Stream data = await response.Content.ReadAsStreamAsync(cancellationToken);
|
|
||||||
|
|
||||||
_entryIconCache[entryId] = data;
|
|
||||||
return new Bitmap(data);
|
|
||||||
}
|
|
||||||
catch (HttpRequestException)
|
|
||||||
{
|
|
||||||
// ignored
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken)
|
public async Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
icon.Seek(0, SeekOrigin.Begin);
|
icon.Seek(0, SeekOrigin.Begin);
|
||||||
@ -96,6 +62,5 @@ public class WorkshopService : IWorkshopService
|
|||||||
|
|
||||||
public interface IWorkshopService
|
public interface IWorkshopService
|
||||||
{
|
{
|
||||||
Task<Bitmap?> GetEntryIcon(Guid entryId, CancellationToken cancellationToken);
|
|
||||||
Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken);
|
Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user