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:
Robert committed 2023-08-24 19:38:47 +02:00
1 parent 2a34381926
commit e21edd0ed6
13 files changed
+75 -223

No files matched your search

@@ -3,17 +3,21 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
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:il="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
xmlns:converters="clr-namespace:Artemis.UI.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="110"
x:Class="Artemis.UI.Screens.Workshop.Entries.EntryListView"
x:DataType="entries1:EntryListViewModel">
<Button MinHeight="110"
MaxHeight="140"
<UserControl.Resources>
<converters:EntryIconUriConverter x:Key="EntryIconUriConverter" />
</UserControl.Resources>
<Button MinHeight="110"
MaxHeight="140"
Padding="16"
CornerRadius="8"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Command="{CompiledBinding NavigateToEntry}"
IsVisible="{CompiledBinding Entry, Converter={x:Static ObjectConverters.IsNotNull}}">
<Grid ColumnDefinitions="Auto,*,Auto">
@@ -26,24 +30,22 @@
Width="80"
Height="80"
ClipToBounds="True">
<Image Source="{CompiledBinding EntryIcon}"
Stretch="UniformToFill"
Classes="fade-in"
Classes.faded-in="{CompiledBinding EntryIcon, Converter={x:Static ObjectConverters.IsNotNull}}" />
<Image Stretch="UniformToFill" il:ImageLoader.Source="{CompiledBinding Entry.Id, Converter={StaticResource EntryIconUriConverter}, Mode=OneWay}" />
</Border>
<!-- Body -->
<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="subtitle">by</Run>
<Run Classes="subtitle" Text="{CompiledBinding Entry.Author, FallbackValue=Author}" />
</TextBlock>
<TextBlock Grid.Row="1"
Classes="subtitle"
<TextBlock Grid.Row="1"
Classes="subtitle"
TextWrapping="Wrap"
TextTrimming="CharacterEllipsis"
Text="{CompiledBinding Entry.Summary, FallbackValue=Summary}"></TextBlock>
TextTrimming="CharacterEllipsis"
Text="{CompiledBinding Entry.Summary, FallbackValue=Summary}">
</TextBlock>
<ItemsControl Grid.Row="2" ItemsSource="{CompiledBinding Entry.Categories}">
<ItemsControl.ItemsPanel>
@@ -61,7 +63,7 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<!-- Info -->
<StackPanel Grid.Column="2">
<TextBlock TextAlignment="Right" Text="{CompiledBinding Entry.CreatedAt, StringFormat={}{0:g}, FallbackValue=01-01-1337}" />
@@ -16,26 +16,16 @@ namespace Artemis.UI.Screens.Workshop.Entries;
public class EntryListViewModel : ActivatableViewModelBase
{
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;
_workshopService = workshopService;
Entry = entry;
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 Bitmap? EntryIcon => _entryIcon?.Value;
public ReactiveCommand<Unit, Unit> NavigateToEntry { get; }
private async Task ExecuteNavigateToEntry()
@@ -54,12 +44,4 @@ public class EntryListViewModel : ActivatableViewModelBase
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:profile="clr-namespace:Artemis.UI.Screens.Workshop.Profile"
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"
x:Class="Artemis.UI.Screens.Workshop.Profile.ProfileDetailsView"
x:DataType="profile:ProfileDetailsViewModel">
<UserControl.Resources>
<converters:EntryIconUriConverter x:Key="EntryIconUriConverter" />
</UserControl.Resources>
<Border Classes="router-container">
<Grid ColumnDefinitions="300,*" RowDefinitions="Auto,*" Margin="10">
<Border Classes="card" Grid.Row="1" Grid.Column="0" Margin="0 0 10 0">
@@ -18,10 +23,7 @@
Width="80"
Height="80"
ClipToBounds="True">
<Image Source="{CompiledBinding EntryIcon}"
Stretch="UniformToFill"
Classes="fade-in"
Classes.faded-in="{CompiledBinding EntryIcon, Converter={x:Static ObjectConverters.IsNotNull}}" />
<Image Stretch="UniformToFill" il:ImageLoader.Source="{CompiledBinding Entry.Id, Converter={StaticResource EntryIconUriConverter}, Mode=OneWay}" />
</Border>
<TextBlock Theme="{StaticResource TitleTextBlockStyle}"
@@ -5,7 +5,6 @@ using Artemis.UI.Screens.Workshop.Parameters;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Routing;
using Artemis.WebClient.Workshop;
using Artemis.WebClient.Workshop.Services;
using Avalonia.Media.Imaging;
using StrawberryShake;
@@ -14,14 +13,12 @@ namespace Artemis.UI.Screens.Workshop.Profile;
public class ProfileDetailsViewModel : RoutableScreen<ActivatableViewModelBase, WorkshopDetailParameters>, IWorkshopViewModel
{
private readonly IWorkshopClient _client;
private readonly IWorkshopService _workshopService;
private IGetEntryById_Entry? _entry;
private Bitmap? _entryIcon;
public ProfileDetailsViewModel(IWorkshopClient client, IWorkshopService workshopService)
public ProfileDetailsViewModel(IWorkshopClient client)
{
_client = client;
_workshopService = workshopService;
}
public EntryType? EntryType => null;
@@ -29,13 +26,7 @@ public class ProfileDetailsViewModel : RoutableScreen<ActivatableViewModelBase,
public IGetEntryById_Entry? Entry
{
get => _entry;
set => RaiseAndSetIfChanged(ref _entry, value);
}
public Bitmap? EntryIcon
{
get => _entryIcon;
set => RaiseAndSetIfChanged(ref _entryIcon, value);
private set => RaiseAndSetIfChanged(ref _entry, value);
}
public override async Task OnNavigating(WorkshopDetailParameters parameters, NavigationArguments args, CancellationToken cancellationToken)
@@ -48,11 +39,7 @@ public class ProfileDetailsViewModel : RoutableScreen<ActivatableViewModelBase,
IOperationResult<IGetEntryByIdResult> result = await _client.GetEntryById.ExecuteAsync(entryId, cancellationToken);
if (result.IsErrorResult())
return;
Bitmap? oldEntryIcon = EntryIcon;
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
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"
x:Class="Artemis.UI.Screens.Workshop.Search.SearchResultView"
x:DataType="search:SearchResultViewModel">
<UserControl.Resources>
<converters:EntryIconUriConverter x:Key="EntryIconUriConverter" />
</UserControl.Resources>
<Grid ColumnDefinitions="Auto,*,Auto" Margin="0 5">
<!-- Icon -->
<Border Grid.Column="0"
@@ -16,16 +21,13 @@
Width="50"
Height="50"
ClipToBounds="True">
<Image Source="{CompiledBinding EntryIcon}"
Stretch="UniformToFill"
Classes="fade-in"
Classes.faded-in="{CompiledBinding EntryIcon, Converter={x:Static ObjectConverters.IsNotNull}}" />
<Image Stretch="UniformToFill" il:ImageLoader.Source="{CompiledBinding Entry.Id, Converter={StaticResource EntryIconUriConverter}, Mode=OneWay}" />
</Border>
<!-- Body -->
<Grid Grid.Column="1" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
<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" Text="{CompiledBinding Entry.Author, FallbackValue=Author}" />
</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.WebClient.Workshop;
using Artemis.WebClient.Workshop.Services;
using Avalonia.Media.Imaging;
using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.Search;
public class SearchResultViewModel : ActivatableViewModelBase
{
private readonly IWorkshopService _workshopService;
private ObservableAsPropertyHelper<Bitmap?>? _entryIcon;
public SearchResultViewModel(ISearchEntries_SearchEntries entry, IWorkshopService workshopService)
public SearchResultViewModel(ISearchEntries_SearchEntries entry)
{
_workshopService = workshopService;
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 Bitmap? EntryIcon => _entryIcon?.Value;
}
@@ -19,16 +19,14 @@ public class SearchViewModel : ViewModelBase
private readonly ILogger _logger;
private readonly IRouter _router;
private readonly IWorkshopClient _workshopClient;
private readonly IWorkshopService _workshopService;
private EntryType? _entryType;
private bool _isLoading;
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;
_workshopClient = workshopClient;
_workshopService = workshopService;
_router = router;
CurrentUserViewModel = currentUserViewModel;
SearchAsync = ExecuteSearchAsync;
@@ -79,7 +77,7 @@ public class SearchViewModel : ViewModelBase
IsLoading = true;
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)
{