From 93a9ecf7624c2da89d5661fc8aef510a02105fcd Mon Sep 17 00:00:00 2001 From: MicGan6 Date: Sun, 15 Feb 2026 09:59:00 +0800 Subject: [PATCH 1/5] feat: Modify message in the notification provider page --- .../BetterCountdown/BetterCountdown.axaml.cs | 2 +- .../BetterCountdown/BetterCountdownConfig.cs | 3 ++- .../BetterCountdownSettings.axaml | 15 +++++++++--- ...tion.cs => BetterCountdownNotification.cs} | 17 +++++++------ .../BetterCountdownNotificationSettings.cs | 11 +++++++++ ...CountdownNotificationSettingsControl.axaml | 24 +++++++++++++++++++ ...ntdownNotificationSettingsControl.axaml.cs | 13 ++++++++++ ExtraIsland/Plugin.cs | 2 +- 8 files changed, 72 insertions(+), 15 deletions(-) rename ExtraIsland/Notification/{TimeUpNotification.cs => BetterCountdownNotification.cs} (57%) create mode 100644 ExtraIsland/Notification/BetterCountdownNotificationSettings.cs create mode 100644 ExtraIsland/Notification/BetterCountdownNotificationSettingsControl.axaml create mode 100644 ExtraIsland/Notification/BetterCountdownNotificationSettingsControl.axaml.cs diff --git a/ExtraIsland/Components/BetterCountdown/BetterCountdown.axaml.cs b/ExtraIsland/Components/BetterCountdown/BetterCountdown.axaml.cs index 52ba596..76b19bc 100644 --- a/ExtraIsland/Components/BetterCountdown/BetterCountdown.axaml.cs +++ b/ExtraIsland/Components/BetterCountdown/BetterCountdown.axaml.cs @@ -201,7 +201,7 @@ void SilentUpdater() { } void Notify() { - TimeUpNotification.Notify(string.Format(Settings.Message, Settings.Prefix, Settings.Suffix), + BetterCountdownNotification.Notify(Settings.Name, Settings.Message, Settings.LeftIcon, Settings.RightIcon); Settings.IsNotified = true; } diff --git a/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs b/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs index 6c1dd6e..6417df3 100644 --- a/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs +++ b/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs @@ -81,7 +81,8 @@ public CountdownAccuracy Accuracy { public bool IsFocusedModeEnabled { get; set; } public bool IsNotify {get; set;} - public string Message { get; set; } = "{0} 已结束"; + public string Name {get; set;} = "倒计时名称"; + public string Message { get; set; } = ""; public string LeftIcon { get; set; } = "\uE352"; diff --git a/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml b/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml index de2ec27..7f6b663 100644 --- a/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml +++ b/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml @@ -163,14 +163,23 @@ + Description="启用后,倒计时到后将进行提醒,显示格式为{事件名称}{提醒消息}"> + + + + + + + + Content="提醒消息" + Description="修改提醒消息的文案, 留空以继承‘提醒渠道’中的设置"> diff --git a/ExtraIsland/Notification/TimeUpNotification.cs b/ExtraIsland/Notification/BetterCountdownNotification.cs similarity index 57% rename from ExtraIsland/Notification/TimeUpNotification.cs rename to ExtraIsland/Notification/BetterCountdownNotification.cs index 448769b..02d3039 100644 --- a/ExtraIsland/Notification/TimeUpNotification.cs +++ b/ExtraIsland/Notification/BetterCountdownNotification.cs @@ -1,7 +1,6 @@ using ClassIsland.Core.Abstractions.Services.NotificationProviders; using ClassIsland.Core.Attributes; using ClassIsland.Core.Models.Notification; -using ExtraIsland.Components; namespace ExtraIsland.Notification; @@ -13,27 +12,27 @@ namespace ExtraIsland.Notification; [NotificationChannelInfo( TimeUpChannelId, "倒计时结束", - "\u1000", + "\uE84C", "倒计时结束后的提醒")] -public class TimeUpNotification : NotificationProviderBase { +public class BetterCountdownNotification : NotificationProviderBase { const string TimeUpChannelId = "40f73a64-a0d8-480b-8026-f0a71a14d6fb"; - delegate void TwoIconsMaskNotify(string content, string leftIcon, string rightIcon); + delegate void TwoIconsMaskNotify(string name, string message, string leftIcon, string rightIcon); static event TwoIconsMaskNotify? OnNotify; - public static void Notify(string content, string leftIcon = "", string rightIcon = "") { - OnNotify?.Invoke(content, leftIcon, rightIcon); + public static void Notify(string name, string message, string leftIcon = "", string rightIcon = "") { + OnNotify?.Invoke(name, message, leftIcon, rightIcon); } - public TimeUpNotification() { + public BetterCountdownNotification() { OnNotify += DoNotify; } - void DoNotify(string content, string leftIcon, string rightIcon) { + void DoNotify(string name, string content, string leftIcon, string rightIcon) { Channel(TimeUpChannelId).ShowNotification(new NotificationRequest() { - MaskContent = NotificationContent.CreateTwoIconsMask(content, leftIcon, rightIcon) + MaskContent = NotificationContent.CreateTwoIconsMask(content==""?name+Settings.Message:name+content, leftIcon, rightIcon) }); } } \ No newline at end of file diff --git a/ExtraIsland/Notification/BetterCountdownNotificationSettings.cs b/ExtraIsland/Notification/BetterCountdownNotificationSettings.cs new file mode 100644 index 0000000..3a2b335 --- /dev/null +++ b/ExtraIsland/Notification/BetterCountdownNotificationSettings.cs @@ -0,0 +1,11 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace ExtraIsland.Notification; + +public class BetterCountdownNotificationSettings : ObservableRecipient{ + string _message = "的时间到了"; + public string Message { + get => _message; + set => SetProperty(ref _message, value); + } +} \ No newline at end of file diff --git a/ExtraIsland/Notification/BetterCountdownNotificationSettingsControl.axaml b/ExtraIsland/Notification/BetterCountdownNotificationSettingsControl.axaml new file mode 100644 index 0000000..0954fab --- /dev/null +++ b/ExtraIsland/Notification/BetterCountdownNotificationSettingsControl.axaml @@ -0,0 +1,24 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ExtraIsland/Notification/BetterCountdownNotificationSettingsControl.axaml.cs b/ExtraIsland/Notification/BetterCountdownNotificationSettingsControl.axaml.cs new file mode 100644 index 0000000..d8243ba --- /dev/null +++ b/ExtraIsland/Notification/BetterCountdownNotificationSettingsControl.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using ClassIsland.Core.Abstractions.Controls; +using ClassIsland.Core.Abstractions.Services.NotificationProviders; + +namespace ExtraIsland.Notification; + +public partial class BetterCountdownNotificationSettingsControl :NotificationProviderControlBase { + public BetterCountdownNotificationSettingsControl() { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/ExtraIsland/Plugin.cs b/ExtraIsland/Plugin.cs index 0ac8a8d..b2a3c54 100644 --- a/ExtraIsland/Plugin.cs +++ b/ExtraIsland/Plugin.cs @@ -123,7 +123,7 @@ public override void Initialize(HostBuilderContext context, IServiceCollection s } //NotificationProvider - services.AddNotificationProvider(); + services.AddNotificationProvider(); //Actions Register.Claim(services); From 42218afa2948c66bd5318395a85356b2d2240348 Mon Sep 17 00:00:00 2001 From: MicGan6 <142008387+MicGan6@users.noreply.github.com> Date: Sun, 8 Mar 2026 18:01:11 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E6=9B=B4=E5=A5=BD=E7=9A=84?= =?UTF-8?q?=E5=80=92=E8=AE=A1=E6=97=B6=E6=97=B6=E9=97=B4=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=8A=9F=E8=83=BDUI=E9=83=A8=E5=88=86=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BetterCountdown/BetterCountdownConfig.cs | 16 ++++- .../BetterCountdownSettings.axaml | 7 +++ .../BetterCountdown/TimeNodeControl.axaml | 60 ++++++++++++++++++ .../BetterCountdown/TimeNodeControl.axaml.cs | 62 +++++++++++++++++++ .../Shared/SortedObservableCollection.cs | 8 +++ 5 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml create mode 100644 ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml.cs create mode 100644 ExtraIsland/Shared/SortedObservableCollection.cs diff --git a/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs b/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs index 6417df3..fb553aa 100644 --- a/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs +++ b/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs @@ -1,10 +1,11 @@ -using System.ComponentModel; +using System.Collections.ObjectModel; +using System.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel; namespace ExtraIsland.Components; // ReSharper disable once ClassNeverInstantiated.Global -public class BetterCountdownConfig : ObservableObject { +public partial class BetterCountdownConfig : ObservableObject { public BetterCountdownConfig() { Separators.PropertyChanged += (_,_) => OnPropertyChanged(); TargetDateTime = DateTime.Now.AddMinutes(1); @@ -87,6 +88,9 @@ public CountdownAccuracy Accuracy { public string LeftIcon { get; set; } = "\uE352"; public string RightIcon { get; set; } = ""; + + [ObservableProperty] ObservableCollection _times = []; + //public BetterCountdownConfig Self => this; } public class CountdownSeparatorConfigs : ObservableObject { @@ -137,4 +141,12 @@ public enum CountdownAccuracy { Minute, [Description("秒")] Second +} + +public partial class TimeNode:ObservableObject { + //public BetterCountdownConfig Config {get;set;} + [ObservableProperty] + TimeSpan _countdownTime; + bool _changeText; + bool _notify; } \ No newline at end of file diff --git a/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml b/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml index 7f6b663..5a1e436 100644 --- a/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml +++ b/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml @@ -100,6 +100,13 @@ + + + + + diff --git a/ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml b/ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml new file mode 100644 index 0000000..304b876 --- /dev/null +++ b/ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml.cs b/ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml.cs new file mode 100644 index 0000000..4ef5041 --- /dev/null +++ b/ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml.cs @@ -0,0 +1,62 @@ +using Avalonia; +using Avalonia.Controls; +using System.Collections.ObjectModel; +using Avalonia.Interactivity; +using CommunityToolkit.Mvvm.Input; + + +namespace ExtraIsland.Components; + +public partial class TimeNodeControl : UserControl { + public TimeNodeControl() { + InitializeComponent(); + } + + //public BetterCountdownConfig Config {get; set;} + public static readonly StyledProperty> TimesProperty = + AvaloniaProperty.Register>(nameof(Times)); + + public ObservableCollection Times { + get => GetValue(TimesProperty); + set => SetValue(TimesProperty, value); + } + + public void ButtonAddTime_Click(object? sender, RoutedEventArgs e) { + Times.Add(new TimeNode()); + } + + [RelayCommand] + void ButtonRemoveTime(TimeNode node) { + Times.Remove(node); + } + + void CountdownTimeModeTp_OnLoaded(object? sender,RoutedEventArgs e) { + if (sender is TimePicker + { + DataContext: TimeNode tn, + } tp) { + Console.WriteLine((tn.CountdownTime.Hours,tn.CountdownTime.Minutes,tn.CountdownTime.Seconds)); + tp.SelectedTime = new TimeSpan(tn.CountdownTime.Hours,tn.CountdownTime.Minutes,tn.CountdownTime.Seconds); + } + } + void CountdownTimeModeTp_SelectedTimeChanged(object? sender,TimePickerSelectedValueChangedEventArgs e) { + if (sender is TimePicker + { + DataContext: TimeNode tn, + SelectedTime: not null + } tp) { + Console.WriteLine((tn.CountdownTime.Days, tp.SelectedTime.Value.Hours, tp.SelectedTime.Value.Minutes, tp.SelectedTime.Value.Seconds)); + tn.CountdownTime = new TimeSpan(tn.CountdownTime.Days, tp.SelectedTime.Value.Hours, tp.SelectedTime.Value.Minutes, tp.SelectedTime.Value.Seconds); + } + } + void NumericUpDown_OnValueChanged(object? sender,NumericUpDownValueChangedEventArgs e) { + if (sender is NumericUpDown + { + DataContext: TimeNode tn, + Value: not null + } numericUpDown) { + //Console.WriteLine((tn.CountdownTime.Days, tn.SelectedTime.Value.Hours, tp.SelectedTime.Value.Minutes, tp.SelectedTime.Value.Seconds)); + tn.CountdownTime = new TimeSpan((int)numericUpDown.Value, tn.CountdownTime.Hours, tn.CountdownTime.Minutes, tn.CountdownTime.Seconds); + } + } +} \ No newline at end of file diff --git a/ExtraIsland/Shared/SortedObservableCollection.cs b/ExtraIsland/Shared/SortedObservableCollection.cs new file mode 100644 index 0000000..3e3297f --- /dev/null +++ b/ExtraIsland/Shared/SortedObservableCollection.cs @@ -0,0 +1,8 @@ +using System.Collections.ObjectModel; + +namespace ExtraIsland.Shared; + +public class SortedObservableCollection : ObservableCollection { + + +} \ No newline at end of file From 64104369f3b282c1a24e549e5a287cbd5eccdef2 Mon Sep 17 00:00:00 2001 From: MicGan6 <142008387+MicGan6@users.noreply.github.com> Date: Sat, 14 Mar 2026 18:49:11 +0800 Subject: [PATCH 3/5] =?UTF-8?q?TimeNode=E6=8E=92=E5=BA=8F=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BetterCountdown/BetterCountdownConfig.cs | 10 +++- .../BetterCountdown/TimeNodeControl.axaml.cs | 55 +++++++++++++++---- .../Shared/SortedObservableCollection.cs | 8 --- .../Shared/TimeNodeObservableCollection.cs | 43 +++++++++++++++ 4 files changed, 94 insertions(+), 22 deletions(-) delete mode 100644 ExtraIsland/Shared/SortedObservableCollection.cs create mode 100644 ExtraIsland/Shared/TimeNodeObservableCollection.cs diff --git a/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs b/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs index fb553aa..cdd64ee 100644 --- a/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs +++ b/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; using System.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel; +using ExtraIsland.Shared; namespace ExtraIsland.Components; @@ -89,7 +90,7 @@ public CountdownAccuracy Accuracy { public string RightIcon { get; set; } = ""; - [ObservableProperty] ObservableCollection _times = []; + [ObservableProperty] TimeNodeObservableCollection _times = []; //public BetterCountdownConfig Self => this; } @@ -143,10 +144,13 @@ public enum CountdownAccuracy { Second } -public partial class TimeNode:ObservableObject { +public partial class TimeNode: ObservableObject { //public BetterCountdownConfig Config {get;set;} [ObservableProperty] - TimeSpan _countdownTime; + TimeSpan _countdownTime = new TimeSpan(1, 1 ,1 ,1 ); bool _changeText; bool _notify; + public override string ToString() { + return CountdownTime.ToString(); + } } \ No newline at end of file diff --git a/ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml.cs b/ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml.cs index 4ef5041..bb94a2f 100644 --- a/ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml.cs +++ b/ExtraIsland/Components/BetterCountdown/TimeNodeControl.axaml.cs @@ -2,8 +2,9 @@ using Avalonia.Controls; using System.Collections.ObjectModel; using Avalonia.Interactivity; +using Avalonia.Threading; using CommunityToolkit.Mvvm.Input; - +using ExtraIsland.Shared; namespace ExtraIsland.Components; @@ -13,10 +14,10 @@ public TimeNodeControl() { } //public BetterCountdownConfig Config {get; set;} - public static readonly StyledProperty> TimesProperty = - AvaloniaProperty.Register>(nameof(Times)); + public static readonly StyledProperty TimesProperty = + AvaloniaProperty.Register(nameof(Times)); - public ObservableCollection Times { + public TimeNodeObservableCollection Times { get => GetValue(TimesProperty); set => SetValue(TimesProperty, value); } @@ -35,28 +36,60 @@ void CountdownTimeModeTp_OnLoaded(object? sender,RoutedEventArgs e) { { DataContext: TimeNode tn, } tp) { - Console.WriteLine((tn.CountdownTime.Hours,tn.CountdownTime.Minutes,tn.CountdownTime.Seconds)); tp.SelectedTime = new TimeSpan(tn.CountdownTime.Hours,tn.CountdownTime.Minutes,tn.CountdownTime.Seconds); } } - void CountdownTimeModeTp_SelectedTimeChanged(object? sender,TimePickerSelectedValueChangedEventArgs e) { + + DispatcherTimer? _waitTimer; + public void OnTpTimeChanged() { + _waitTimer?.Start(); + _waitTimer = new DispatcherTimer( + TimeSpan.FromSeconds(3), + DispatcherPriority.Background, + (_, __) => { + _waitTimer?.Stop(); + Times.SortAll(); + }); + } + + bool _isProcessing = false; + async void CountdownTimeModeTp_SelectedTimeChanged(object? sender,TimePickerSelectedValueChangedEventArgs e) { + if(_isProcessing) return; if (sender is TimePicker { DataContext: TimeNode tn, SelectedTime: not null } tp) { - Console.WriteLine((tn.CountdownTime.Days, tp.SelectedTime.Value.Hours, tp.SelectedTime.Value.Minutes, tp.SelectedTime.Value.Seconds)); - tn.CountdownTime = new TimeSpan(tn.CountdownTime.Days, tp.SelectedTime.Value.Hours, tp.SelectedTime.Value.Minutes, tp.SelectedTime.Value.Seconds); + TimeSpan newTime = new TimeSpan(tn.CountdownTime.Days, tp.SelectedTime.Value.Hours, tp.SelectedTime.Value.Minutes, tp.SelectedTime.Value.Seconds); + if (newTime == tn.CountdownTime) return; + _isProcessing = true; + try { + tn.CountdownTime = newTime; + OnTpTimeChanged(); + } + finally { + await Task.Delay(200); + _isProcessing = false; + } } } - void NumericUpDown_OnValueChanged(object? sender,NumericUpDownValueChangedEventArgs e) { + async void NumericUpDown_OnValueChanged(object? sender,NumericUpDownValueChangedEventArgs e) { if (sender is NumericUpDown { DataContext: TimeNode tn, Value: not null } numericUpDown) { - //Console.WriteLine((tn.CountdownTime.Days, tn.SelectedTime.Value.Hours, tp.SelectedTime.Value.Minutes, tp.SelectedTime.Value.Seconds)); - tn.CountdownTime = new TimeSpan((int)numericUpDown.Value, tn.CountdownTime.Hours, tn.CountdownTime.Minutes, tn.CountdownTime.Seconds); + TimeSpan newTime = new TimeSpan((int)numericUpDown.Value, tn.CountdownTime.Hours, tn.CountdownTime.Minutes, tn.CountdownTime.Seconds); + if (newTime == tn.CountdownTime) return; + _isProcessing = true; + try { + tn.CountdownTime = newTime; + OnTpTimeChanged(); + } + finally { + await Task.Delay(200); + _isProcessing = false; + } } } } \ No newline at end of file diff --git a/ExtraIsland/Shared/SortedObservableCollection.cs b/ExtraIsland/Shared/SortedObservableCollection.cs deleted file mode 100644 index 3e3297f..0000000 --- a/ExtraIsland/Shared/SortedObservableCollection.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections.ObjectModel; - -namespace ExtraIsland.Shared; - -public class SortedObservableCollection : ObservableCollection { - - -} \ No newline at end of file diff --git a/ExtraIsland/Shared/TimeNodeObservableCollection.cs b/ExtraIsland/Shared/TimeNodeObservableCollection.cs new file mode 100644 index 0000000..ef52f4a --- /dev/null +++ b/ExtraIsland/Shared/TimeNodeObservableCollection.cs @@ -0,0 +1,43 @@ +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.ComponentModel; +using ClassIsland.Core.Abstractions.Services; +using ClassIsland.Shared; +using ExtraIsland.Components; +namespace ExtraIsland.Shared; + +public class TimeNodeObservableCollection : ObservableCollection { + readonly IExactTimeService _exactTimeService; + + public void SortAll() { + if (Count <= 1) return; + var sortedList = this.OrderBy(_ => _.CountdownTime).ToList(); + bool needSort = false; + for (int i = 0; i < Count; i++) { + if (!ReferenceEquals(this[i], sortedList[i])) + { + needSort = true; + break; + } + } + if (!needSort) return; + base.ClearItems(); + foreach (TimeNode tn in sortedList) { + base.InsertItem(Count, tn); + } + OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); + } + public TimeNodeObservableCollection() { + _exactTimeService = IAppHost.GetService(); + } + + public TimeNode? GetLatest(BetterCountdownConfig config) { + foreach (TimeNode tn in Items) { + if((config.TargetDateTime - + (!config.IsSystemTime ? + _exactTimeService.GetCurrentLocalDateTime() + : DateTime.Now)) <= tn.CountdownTime) return Items[IndexOf(tn)-1]; + } + return null; + } +} \ No newline at end of file From 7cc7f555a703ea783b9edca22f03047f4aa26465 Mon Sep 17 00:00:00 2001 From: MicGan6 <142008387+MicGan6@users.noreply.github.com> Date: Sat, 28 Mar 2026 21:24:20 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=8F=90=E9=86=92=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BetterCountdown/BetterCountdown.axaml.cs | 62 ++++++++++++---- .../BetterCountdown/BetterCountdownConfig.cs | 29 +++++--- .../BetterCountdownSettings.axaml | 24 +++---- .../BetterCountdown/TimeNodeControl.axaml | 70 ++++++++++++------- .../BetterCountdown/TimeNodeControl.axaml.cs | 51 +++++--------- .../BetterCountdownNotification.cs | 27 +++++-- ...CountdownNotificationSettingsControl.axaml | 2 +- .../Shared/TimeNodeObservableCollection.cs | 43 +++++++++--- 8 files changed, 195 insertions(+), 113 deletions(-) diff --git a/ExtraIsland/Components/BetterCountdown/BetterCountdown.axaml.cs b/ExtraIsland/Components/BetterCountdown/BetterCountdown.axaml.cs index 76b19bc..6cd4c33 100644 --- a/ExtraIsland/Components/BetterCountdown/BetterCountdown.axaml.cs +++ b/ExtraIsland/Components/BetterCountdown/BetterCountdown.axaml.cs @@ -39,6 +39,7 @@ void OnLoad() { SilentUpdater(); OnTimeChanged += DetectEvent; OnTimeChanged += DetectTimeUp; + OnTimeChanged += DetectTimeNode; Settings.OnAccuracyChanged += UpdateAccuracy; Settings.OnNoGapDisplayChanged += UpdateGap; LessonsService.PostMainTimerTicked += UpdateTime; @@ -115,7 +116,7 @@ void DetectEvent() { _dyAnimator.Update(_days,Settings.IsAnimationEnabled); } } - if ((_hours != span.Hours.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 1)) { + if ((_hours != span.Hours.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 1 | Settings.LatestNode is not null)) { int hourI = span.Hours; int hourCi = (int)Settings.Accuracy == 1 & Settings.IsCorrectorEnabled ? hourI + 1 : hourI; _hours = hourCi.ToString(); @@ -132,7 +133,7 @@ void DetectEvent() { _hrAnimator.Update(_hours,Settings.IsAnimationEnabled); } } - if ((_minutes != span.Minutes.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 2)) { + if ((_minutes != span.Minutes.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 2 | Settings.LatestNode is not null)) { int minuteI = span.Minutes; int minuteCi = (int)Settings.Accuracy == 2 & Settings.IsCorrectorEnabled ? minuteI + 1 : minuteI; _minutes = minuteCi.ToString(); @@ -156,7 +157,7 @@ void DetectEvent() { } } // ReSharper disable once InvertIf - if ((_seconds != span.Seconds.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 3)) { + if ((_seconds != span.Seconds.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 3 | Settings.LatestNode is not null)) { _seconds = span.Seconds.ToString(); string s = _seconds; if (s.Length == 1) { @@ -175,12 +176,12 @@ void SilentUpdater() { _days = (int)Settings.Accuracy == 0 ? (dayI + 1).ToString() : dayI.ToString(); _dyAnimator.SilentUpdate(_days); } - if ((_hours != span.Hours.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 1)) { + if ((_hours != span.Hours.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 1 | Settings.LatestNode is not null)) { int hourI = span.Hours; _hours = (int)Settings.Accuracy == 1 ? (hourI + 1).ToString() : hourI.ToString(); _hrAnimator.SilentUpdate(_hours); } - if ((_minutes != span.Minutes.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 2)) { + if ((_minutes != span.Minutes.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 2 | Settings.LatestNode is not null)) { int minuteI = span.Minutes; _minutes = (int)Settings.Accuracy == 2 ? (minuteI + 1).ToString() : minuteI.ToString(); string m = _minutes; @@ -190,7 +191,7 @@ void SilentUpdater() { _mnAnimator.SilentUpdate(m); } // ReSharper disable once InvertIf - if ((_seconds != span.Seconds.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 3)) { + if ((_seconds != span.Seconds.ToString() | _isAccurateChanged) & (Settings.IsNotify | (int)Settings.Accuracy >= 3 | Settings.LatestNode is not null)) { _seconds = span.Seconds.ToString(); string s = _seconds; if (s.Length == 1) { @@ -200,36 +201,73 @@ void SilentUpdater() { } } - void Notify() { - BetterCountdownNotification.Notify(Settings.Name, Settings.Message, + void TimeUpNotify() { + BetterCountdownNotification.Notify(Settings.Name, Settings.Message, 0, Settings.LeftIcon, Settings.RightIcon); Settings.IsNotified = true; } + void TimeNodeNotify(TimeNode tn) { + BetterCountdownNotification.Notify(Settings.Name, tn.NotifyText, 1, + Settings.LeftIcon, Settings.RightIcon, tn.ToString()); + Settings.IsNotified = true; + } void DetectTimeUp() { if (!Settings.IsNotify || Settings.IsNotified) return; if (Settings.IsCorrectorEnabled) { if ((int)Settings.Accuracy == 1 & _days == "0" & _hours == "1" & _minutes == "0" & _seconds == "-1") { - Notify(); + TimeUpNotify(); } if ((int)Settings.Accuracy == 2 & _days == "0" & _hours == "0" & _minutes == "1" & _seconds == "-1") { - Notify(); + TimeUpNotify(); } if ((int)Settings.Accuracy == 3 & _days == "0" & _hours == "0" & _minutes == "0" & _seconds == "0") { - Notify(); + TimeUpNotify(); } } else { if (_days == "0" & _hours == "0" & _minutes == "0" & _seconds == "0") { - Notify(); + TimeUpNotify(); + } + } + } + void DetectTimeNode() { + if (Settings.LatestNode is null || Settings.IsNotified) return; + int day = Settings.LatestNode.CountdownTime.Days; + int hr = Settings.LatestNode.CountdownTime.Hours; + int min = Settings.LatestNode.CountdownTime.Minutes; + int sec = Settings.LatestNode.CountdownTime.Seconds; + if (Settings.IsCorrectorEnabled) { + + if ((int)Settings.Accuracy == 1 & _days == day.ToString() & _hours == (hr+1).ToString()) { + TimeNodeNotify(Settings.LatestNode); + Settings.LatestNode = Settings.Times[Settings.Times.IndexOf(Settings.LatestNode)+1]; + } + if ((int)Settings.Accuracy == 2 & _days == day.ToString() & _hours == hr.ToString() & _minutes == (min+1).ToString()) { + TimeNodeNotify(Settings.LatestNode); + Settings.LatestNode = Settings.Times[Settings.Times.IndexOf(Settings.LatestNode)+1]; + } + if ((int)Settings.Accuracy == 3 & _days == day.ToString() & _hours == hr.ToString() & _minutes == min.ToString() & _seconds == sec.ToString()) { + TimeNodeNotify(Settings.LatestNode); + Settings.LatestNode = Settings.Times[Settings.Times.IndexOf(Settings.LatestNode)+1]; + } + } else { + if (_days == day.ToString() & _hours == hr.ToString() & _minutes == min.ToString() & _seconds == sec.ToString()) { + TimeNodeNotify(Settings.LatestNode); + Settings.LatestNode = Settings.Times[Settings.Times.IndexOf(Settings.LatestNode)+1]; } + System.Console.WriteLine(Settings.LatestNode); } } void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs visualTreeAttachmentEventArgs) { Dispatcher.UIThread.InvokeAsync(OnLoad); + Console.WriteLine("OATV调用!"); + Settings.Times.Config = Settings; + Settings.Times.GetLatest(); } void OnDetachedFromVisualTree(object? sender,VisualTreeAttachmentEventArgs visualTreeAttachmentEventArgs) { OnTimeChanged -= DetectEvent; OnTimeChanged -= DetectTimeUp; + OnTimeChanged -= DetectTimeNode; Settings.OnAccuracyChanged -= UpdateAccuracy; Settings.OnNoGapDisplayChanged -= UpdateGap; LessonsService.PostMainTimerTicked -= UpdateTime; diff --git a/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs b/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs index cdd64ee..12b9fdb 100644 --- a/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs +++ b/ExtraIsland/Components/BetterCountdown/BetterCountdownConfig.cs @@ -1,14 +1,16 @@ -using System.Collections.ObjectModel; -using System.ComponentModel; +using System.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel; using ExtraIsland.Shared; namespace ExtraIsland.Components; // ReSharper disable once ClassNeverInstantiated.Global -public partial class BetterCountdownConfig : ObservableObject { +public class BetterCountdownConfig : ObservableObject { public BetterCountdownConfig() { Separators.PropertyChanged += (_,_) => OnPropertyChanged(); + Console.WriteLine("Bcd Consturct!"); + Times = []; + Times.Config = this; TargetDateTime = DateTime.Now.AddMinutes(1); } @@ -19,6 +21,8 @@ public DateTime TargetDateTime { if (_targetDateTime == value) return; _targetDateTime = value; IsNotified = false; + + Times.GetLatest(); } } @@ -90,8 +94,15 @@ public CountdownAccuracy Accuracy { public string RightIcon { get; set; } = ""; - [ObservableProperty] TimeNodeObservableCollection _times = []; - //public BetterCountdownConfig Self => this; + //TimeNodeObservableCollection _times; + + public TimeNodeObservableCollection Times { + get; + set; + } + + public TimeNode? LatestNode { get; set; } + } public class CountdownSeparatorConfigs : ObservableObject { @@ -145,12 +156,12 @@ public enum CountdownAccuracy { } public partial class TimeNode: ObservableObject { - //public BetterCountdownConfig Config {get;set;} + [ObservableProperty] TimeSpan _countdownTime = new TimeSpan(1, 1 ,1 ,1 ); - bool _changeText; - bool _notify; + public bool IsNotify { get; set; } + public String NotifyText { get; set; } = "距离{n}仅剩{t}"; public override string ToString() { - return CountdownTime.ToString(); + return CountdownTime.Days + "天" + CountdownTime.Hours + "小时" + CountdownTime.Minutes+"分"+CountdownTime.Seconds+"秒"; } } \ No newline at end of file diff --git a/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml b/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml index 5a1e436..f9bd34c 100644 --- a/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml +++ b/ExtraIsland/Components/BetterCountdown/BetterCountdownSettings.axaml @@ -82,6 +82,13 @@ + + + + + @@ -170,27 +177,18 @@ + Description="启用后,倒计时到后将进行提醒,"> + Content="提醒消息" + Description="修改提醒消息的文案, 留空以继承‘提醒渠道’中的设置,{n}表示事件名称"> - + - - - - - - -