mirror of
https://github.com/claunia/marechai.git
synced 2026-07-08 17:57:08 +00:00
Add random software hero cover in Uno app
This commit is contained in:
@@ -20,6 +20,7 @@ using Marechai.App.Services.Caching;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Windows.System;
|
||||
|
||||
namespace Marechai.App.Presentation.ViewModels;
|
||||
@@ -219,13 +220,22 @@ public partial class SoftwareViewViewModel : ObservableObject, IRegionAware
|
||||
[ObservableProperty]
|
||||
private Visibility _showDescription = Visibility.Collapsed;
|
||||
|
||||
[ObservableProperty]
|
||||
private ImageSource? _heroImageSource;
|
||||
|
||||
public bool HasDescription => !string.IsNullOrWhiteSpace(DescriptionHtml);
|
||||
public bool HasHeroImage => HeroImageSource is not null;
|
||||
|
||||
partial void OnDescriptionHtmlChanged(string value)
|
||||
{
|
||||
OnPropertyChanged(nameof(HasDescription));
|
||||
}
|
||||
|
||||
partial void OnHeroImageSourceChanged(ImageSource? value)
|
||||
{
|
||||
OnPropertyChanged(nameof(HasHeroImage));
|
||||
}
|
||||
|
||||
public SoftwareViewViewModel(ILogger<SoftwareViewViewModel> logger, IRegionManager regionManager,
|
||||
SoftwareBrowsingService browsingService, AuthService authService,
|
||||
ITokenService tokenService, IJwtService jwtService,
|
||||
@@ -451,6 +461,7 @@ public partial class SoftwareViewViewModel : ObservableObject, IRegionAware
|
||||
IsDataLoaded = false;
|
||||
HasError = false;
|
||||
ErrorMessage = string.Empty;
|
||||
HeroImageSource = null;
|
||||
Companies.Clear();
|
||||
Versions.Clear();
|
||||
CreditGroups.Clear();
|
||||
@@ -765,6 +776,14 @@ public partial class SoftwareViewViewModel : ObservableObject, IRegionAware
|
||||
|
||||
if(covers.Count == 0) return;
|
||||
|
||||
List<SoftwareCoverDto> frontCovers = covers.Where(cover => cover.Id.HasValue && cover.Type == 0).ToList();
|
||||
|
||||
if(frontCovers.Count > 0)
|
||||
{
|
||||
SoftwareCoverDto heroCover = frontCovers[Random.Shared.Next(frontCovers.Count)];
|
||||
_ = LoadHeroCoverAsync(heroCover.Id!.Value);
|
||||
}
|
||||
|
||||
var byGroup = new Dictionary<string, List<CoverDisplayItem>>();
|
||||
|
||||
foreach(SoftwareCoverDto cover in covers)
|
||||
@@ -804,6 +823,19 @@ public partial class SoftwareViewViewModel : ObservableObject, IRegionAware
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadHeroCoverAsync(Guid coverId)
|
||||
{
|
||||
try
|
||||
{
|
||||
Stream stream = await _coverCache.GetCoverAsync(coverId);
|
||||
HeroImageSource = await _imageSourceFactory.CreateBitmapImageSourceAsync(stream);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error loading hero cover {Id}", coverId);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadCoverThumbnailAsync(CoverDisplayItem item)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -101,7 +101,9 @@
|
||||
Spacing="16">
|
||||
|
||||
<components:HeroHeader HeroTitle="{Binding SoftwareName}"
|
||||
HeroSubtitle="{Binding Family}" />
|
||||
HeroSubtitle="{Binding Family}"
|
||||
HeroImageSource="{Binding HeroImageSource}"
|
||||
ShowImage="{Binding HasHeroImage}" />
|
||||
|
||||
<!-- Type Badges -->
|
||||
<wctui:WrapPanel Orientation="Horizontal"
|
||||
|
||||
Reference in New Issue
Block a user