From c236dabb0ec1be1229ddbdc867f482afe7ca4de7 Mon Sep 17 00:00:00 2001 From: Enrico Ludwig Date: Tue, 27 Aug 2024 20:02:12 +0200 Subject: [PATCH] Started working on reworking of event system for changed channel data --- Events/ChannelDataChangedEventArgs.cs | 16 ++++++++++++++++ ViewModels/RaidButtonViewModel.cs | 19 ++++++++++++++++++- Views/MainWindow.axaml.cs | 9 +-------- 3 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 Events/ChannelDataChangedEventArgs.cs diff --git a/Events/ChannelDataChangedEventArgs.cs b/Events/ChannelDataChangedEventArgs.cs new file mode 100644 index 0000000..7b36ebc --- /dev/null +++ b/Events/ChannelDataChangedEventArgs.cs @@ -0,0 +1,16 @@ +using System; + +namespace BetterRaid.Events; + +public class ChannelDataChangedEventArgs : EventArgs +{ + public static ChannelDataChangedEventArgs FromViewerCount(int old, int now) + { + return new ChannelDataChangedEventArgs(); + } + + public static ChannelDataChangedEventArgs FromIsLive(bool old, bool now) + { + return new ChannelDataChangedEventArgs(); + } +} \ No newline at end of file diff --git a/ViewModels/RaidButtonViewModel.cs b/ViewModels/RaidButtonViewModel.cs index d0df1a9..61985b2 100644 --- a/ViewModels/RaidButtonViewModel.cs +++ b/ViewModels/RaidButtonViewModel.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; using Avalonia.Media; using Avalonia.Threading; +using BetterRaid.Events; using BetterRaid.Models; using TwitchLib.Api.Helix.Models.Raids.StartRaid; using TwitchLib.Api.Helix.Models.Search; @@ -34,6 +35,8 @@ public class RaidButtonViewModel : ViewModelBase public DateTime? LastRaided => MainVm?.Database?.GetLastRaided(ChannelName); + public event EventHandler? ChannelDataChanged; + public RaidButtonViewModel(string channelName) { ChannelName = channelName; @@ -161,6 +164,20 @@ public class RaidButtonViewModel : ViewModelBase private void OnChannelDataChanged(object? sender, PropertyChangedEventArgs e) { - OnPropertyChanged(nameof(Channel)); + switch (e.PropertyName) + { + case "IsLive": + OnChannelDataChanged(ChannelDataChangedEventArgs.FromIsLive(false, true)); + break; + + case "ViewerCount": + OnChannelDataChanged(ChannelDataChangedEventArgs.FromViewerCount(0, 10)); + break; + } + } + + private void OnChannelDataChanged(ChannelDataChangedEventArgs args) + { + ChannelDataChanged?.Invoke(this, args); } } \ No newline at end of file diff --git a/Views/MainWindow.axaml.cs b/Views/MainWindow.axaml.cs index 07ba120..f7cc400 100644 --- a/Views/MainWindow.axaml.cs +++ b/Views/MainWindow.axaml.cs @@ -69,7 +69,7 @@ public partial class MainWindow : Window foreach (var rbvm in _raidButtonVMs) { - rbvm.PropertyChanged -= OnRaidButtonViewModelChanged; + } _raidButtonVMs.Clear(); @@ -89,8 +89,6 @@ public partial class MainWindow : Window MainVm = vm }; - rbvm.PropertyChanged += OnRaidButtonViewModelChanged; - _raidButtonVMs.Add(rbvm); } @@ -100,11 +98,6 @@ public partial class MainWindow : Window } } - private void OnRaidButtonViewModelChanged(object? sender, PropertyChangedEventArgs e) - { - - } - private void GenerateRaidGrid() { foreach (var child in raidGrid.Children)