ChannelSummaryViewModel.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. namespace HistoryView.ViewModels.Regions.SettingSubs;
  2. internal partial class ChannelSummaryViewModel : ObservableObject
  3. {
  4. public ChannelSummaryViewModel(Hardwares hardwares, HubSender sender, IDialogService dialogService)
  5. {
  6. _hardwares = hardwares;
  7. _sender = sender;
  8. _dialogService = dialogService;
  9. this.Channels = [];
  10. this.Display = [];
  11. RefreshDisplay("All");
  12. this.Refresh();
  13. }
  14. private readonly HubSender _sender;
  15. private readonly Hardwares _hardwares;
  16. private readonly IDialogService _dialogService;
  17. [ObservableProperty]
  18. private ObservableDictionary<Mini8Info, ObservableCollection<Channel>> _Channels;
  19. [ObservableProperty]
  20. private ObservableDictionary<Mini8Info, DisplayDetail> _Display;
  21. [RelayCommand]
  22. private void Select()
  23. {
  24. this.Channels.Clear();
  25. foreach (var item in this.Display)
  26. {
  27. if (!item.Value.IsDisplay)
  28. continue;
  29. if (!this._hardwares.Mini8Channels.TryGetValue(item.Key.Index, out ObservableDictionary<byte, Channel>? channels) || channels is null)
  30. continue;
  31. this.Channels[item.Key] ??= [];
  32. this.Channels[item.Key].Clear();
  33. this.Channels[item.Key].AddRange(channels.Values);
  34. }
  35. }
  36. [RelayCommand]
  37. private void RefreshDisplay(string para)
  38. {
  39. foreach (var item in this._hardwares.Mini8s)
  40. {
  41. if (!this._hardwares.Mini8Channels.TryGetValue(item.Key, out ObservableDictionary<byte, Channel>? channels) || channels is null)
  42. continue;
  43. this.Display[item.Value] = para switch
  44. {
  45. "All" => new(true),
  46. "None" => new(false),
  47. _ => new(true)
  48. };
  49. }
  50. this.Select();
  51. }
  52. [RelayCommand]
  53. private void Refresh()
  54. {
  55. this.Channels.Clear();
  56. foreach (var item in this._hardwares.Mini8s)
  57. {
  58. if (!this._hardwares.Mini8Channels.TryGetValue(item.Key, out ObservableDictionary<byte, Channel>? channels) || channels is null)
  59. continue;
  60. this.Channels[item.Value] = [];
  61. this.Channels[item.Value].AddRange(channels.Values);
  62. }
  63. }
  64. }