1using CommunityToolkit.Mvvm.Input;
13 public partial class ServiceProviderViewModel(IServiceProvider ServiceProvider, int IconHeight, ServiceProvidersViewModel Parent)
16 private readonly IServiceProvider serviceProvider = ServiceProvider;
17 private readonly ServiceProvidersViewModel parent = Parent;
18 private ImageSource? iconSource;
23 public IServiceProvider ServiceProvider => this.serviceProvider;
28 public string Id => this.serviceProvider.Id;
33 public string Name => this.serviceProvider.Name;
38 public bool HasIcon => !
string.IsNullOrEmpty(this.serviceProvider.IconUrl);
43 public string IconUrl => this.serviceProvider.IconUrl;
48 public bool ShowImage => this.HasIcon;
53 public bool ShowText => !this.HasIcon || this.IconWidth <= 250 || this.serviceProvider.GetType().Assembly == typeof(
App).Assembly;
58 public int IconHeight {
get; } = IconHeight;
67 if (!this.HasIcon || this.serviceProvider.IconHeight == 0)
70 double s = ((double)this.IconHeight) / this.serviceProvider.IconHeight;
72 return (
int)(this.serviceProvider.IconWidth * s + 0.5);
76 private bool hasRun =
false;
81 public ImageSource? IconUrlSource
85 if (this.iconSource ==
null && !this.hasRun)
88 Task.Run(this.UpdateIconUrlSourceAsync);
91 return this.iconSource;
95 public async Task UpdateIconUrlSourceAsync()
97 if (this.iconSource !=
null)
return;
102 bool isSvg = this.IconUrl.EndsWith(
".svg", StringComparison.OrdinalIgnoreCase);
104 if (this.IconUrl.StartsWith(
"resource://", StringComparison.Ordinal))
105 this.iconSource = ImageSource.FromResource(this.IconUrl[11..]);
106 else if (this.IconUrl.StartsWith(
"file://", StringComparison.Ordinal))
109 this.iconSource = this.IconUrl[7..^4];
111 this.iconSource = this.IconUrl[7..];
113 else if (Uri.TryCreate(
this.IconUrl, UriKind.Absolute, out Uri? ParsedUri))
118 this.iconSource = ImageSource.FromUri(ParsedUri);
125 this.iconSource = ImageSource.FromFile(this.IconUrl[..^4]);
127 this.iconSource = ImageSource.FromFile(this.IconUrl);
135 MainThread.BeginInvokeOnMainThread(() => this.OnPropertyChanged(nameof(this.IconUrlSource)));
142 private Task SelectServiceProvider()
144 return this.parent.SelectServiceProvider(
this);
The Application class, representing an instance of the Neuro-Access app.
Base class that references services in the app.
static ILogService LogService
Log service.
static IUiService UiService
Service serializing and managing UI-related tasks.
Interface for information about a service provider.