diff --git a/Marechai.App/Presentation/ViewModels/CompaniesViewModel.cs b/Marechai.App/Presentation/ViewModels/CompaniesViewModel.cs index 5aeed4e9..15919399 100644 --- a/Marechai.App/Presentation/ViewModels/CompaniesViewModel.cs +++ b/Marechai.App/Presentation/ViewModels/CompaniesViewModel.cs @@ -3,13 +3,16 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows.Input; using Marechai.App.Helpers; using Marechai.App.Presentation.Models; using Marechai.App.Services; +using Marechai.App.Services.Caching; using Uno.Extensions.Navigation; +using Microsoft.UI.Xaml.Media.Imaging; namespace Marechai.App.Presentation.ViewModels; @@ -17,6 +20,7 @@ public partial class CompaniesViewModel : ObservableObject { private readonly List _allCompanies = []; private readonly CompaniesService _companiesService; + private readonly CompanyLogoCache _logoCache; private readonly IStringLocalizer _localizer; private readonly ILogger _logger; private readonly INavigator _navigator; @@ -45,10 +49,12 @@ public partial class CompaniesViewModel : ObservableObject [ObservableProperty] private string _searchQuery = string.Empty; - public CompaniesViewModel(CompaniesService companiesService, IStringLocalizer localizer, - ILogger logger, INavigator navigator) + public CompaniesViewModel(CompaniesService companiesService, CompanyLogoCache logoCache, + IStringLocalizer localizer, ILogger logger, + INavigator navigator) { _companiesService = companiesService; + _logoCache = logoCache; _localizer = localizer; _logger = logger; _navigator = navigator; @@ -98,11 +104,29 @@ public partial class CompaniesViewModel : ObservableObject // Convert DateTimeOffset? to DateTime? DateTime? foundedDate = company.Founded?.DateTime; + // Load logo if available + SvgImageSource? logoSource = null; + if(company.LastLogo.HasValue) + { + try + { + var logoStream = await _logoCache.GetLogoAsync(company.LastLogo.Value); + logoSource = new SvgImageSource(); + await logoSource.SetSourceAsync(logoStream.AsRandomAccessStream()); + } + catch(Exception ex) + { + _logger.LogWarning("Failed to load logo for company {CompanyId}: {Exception}", + companyId, ex.Message); + } + } + _allCompanies.Add(new CompanyListItem { Id = companyId, Name = company.Name ?? string.Empty, - FoundationDate = foundedDate + FoundationDate = foundedDate, + LogoImageSource = logoSource }); } @@ -186,9 +210,10 @@ public partial class CompaniesViewModel : ObservableObject /// public class CompanyListItem { - public int Id { get; set; } - public string Name { get; set; } = string.Empty; - public DateTime? FoundationDate { get; set; } + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public DateTime? FoundationDate { get; set; } + public SvgImageSource? LogoImageSource { get; set; } public string FoundationDateDisplay => FoundationDate.HasValue ? FoundationDate.Value.ToString("MMMM d, yyyy") : string.Empty; diff --git a/Marechai.App/Presentation/ViewModels/CompanyDetailViewModel.cs b/Marechai.App/Presentation/ViewModels/CompanyDetailViewModel.cs index 9a107a23..36e433db 100644 --- a/Marechai.App/Presentation/ViewModels/CompanyDetailViewModel.cs +++ b/Marechai.App/Presentation/ViewModels/CompanyDetailViewModel.cs @@ -138,7 +138,7 @@ public partial class CompanyDetailViewModel : ObservableObject OnPropertyChanged(nameof(HasLogoContent)); } - partial void OnCompanyLogosChanged(ObservableCollection oldValue, + partial void OnCompanyLogosChanged(ObservableCollection? oldValue, ObservableCollection newValue) { // Notify that HasMultipleLogos has changed diff --git a/Marechai.App/Presentation/Views/CompaniesPage.xaml b/Marechai.App/Presentation/Views/CompaniesPage.xaml index b4a7be2b..84e67d11 100644 --- a/Marechai.App/Presentation/Views/CompaniesPage.xaml +++ b/Marechai.App/Presentation/Views/CompaniesPage.xaml @@ -97,15 +97,34 @@