Files
Tornado3_2026Election/Tornado3_2026Election/ViewModels/SettingsViewModel.cs

71 lines
2.3 KiB
C#

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Tornado3_2026Election.Common;
using Tornado3_2026Election.Domain;
namespace Tornado3_2026Election.ViewModels;
public sealed class SettingsViewModel : ObservableObject
{
private string _selectedStationId = "KNN";
private string _imageRootPath = @"C:\Users\y2keu\Downloads\T3_Cut";
public SettingsViewModel(IEnumerable<BroadcastStationProfile> stations)
{
Stations = new ObservableCollection<StationFilterItemViewModel>(
stations.Select(station => new StationFilterItemViewModel(station)));
foreach (var station in Stations)
{
station.PropertyChanged += (_, args) =>
{
if (station == SelectedStation && args.PropertyName is nameof(StationFilterItemViewModel.RegionFiltersText) or nameof(StationFilterItemViewModel.RegionSelectionSummary))
{
OnPropertyChanged(nameof(SelectedStationRegionSummary));
}
};
}
if (Stations.Count > 0)
{
_selectedStationId = Stations[0].Id;
}
}
public ObservableCollection<StationFilterItemViewModel> Stations { get; }
public string SelectedStationId
{
get => _selectedStationId;
set
{
if (SetProperty(ref _selectedStationId, value))
{
OnPropertyChanged(nameof(SelectedStation), nameof(SelectedStationLogoAssetPath), nameof(SelectedStationRegions), nameof(SelectedStationRegionSummary));
}
}
}
public string ImageRootPath
{
get => _imageRootPath;
set => SetProperty(ref _imageRootPath, value);
}
public StationFilterItemViewModel SelectedStation
=> Stations.FirstOrDefault(station => station.Id == SelectedStationId) ?? Stations[0];
public string SelectedStationLogoAssetPath => SelectedStation.LogoAssetPath;
public ObservableCollection<RegionOptionViewModel> SelectedStationRegions => SelectedStation.Regions;
public string SelectedStationRegionSummary => SelectedStation.RegionSelectionSummary;
public BroadcastStationProfile BuildSelectedStationProfile()
{
return SelectedStation.ToProfile();
}
}