using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; using Avalonia.Media; using MetaforceInstaller.Core.Models; namespace MetaforceInstaller.UI.ViewModels; public class MainWindowViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler? PropertyChanged; public ObservableCollection Installations { get; set; } = new(); private bool _isDeviceConnected; public bool IsDeviceConnected { get => _isDeviceConnected; set { if (_isDeviceConnected != value) { _isDeviceConnected = value; OnPropertyChanged(); OnPropertyChanged(nameof(StatusColor)); OnPropertyChanged(nameof(StatusText)); } } } private string _deviceSerial = string.Empty; public string DeviceSerial { get => _deviceSerial; set { if (_deviceSerial != value) { _deviceSerial = value; OnPropertyChanged(); OnPropertyChanged(nameof(StatusText)); } } } public IBrush StatusColor => IsDeviceConnected ? Brushes.Green : Brushes.Red; public string StatusText => IsDeviceConnected ? $"{Lang.Resources.ConnectedTo} {_deviceSerial}" : Lang.Resources.NotConnected; public void LoadInstallations(IEnumerable data) { Installations.Clear(); foreach (var installation in data) { Installations.Add(installation); } } protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } }