diff --git a/DownKyi/CustomAction/KeyUpBehavior.cs b/DownKyi/CustomAction/KeyUpBehavior.cs index 4236024..3106f7c 100644 --- a/DownKyi/CustomAction/KeyUpBehavior.cs +++ b/DownKyi/CustomAction/KeyUpBehavior.cs @@ -8,10 +8,9 @@ namespace DownKyi.CustomAction; public class KeyUpBehavior : Trigger { - private Key key = Key.None; + private Key _key = Key.None; - public static readonly StyledProperty KeyProperty = - AvaloniaProperty.Register(nameof(Key)); + public static readonly StyledProperty KeyProperty = AvaloniaProperty.Register(nameof(Key)); public Key Key { @@ -37,13 +36,13 @@ public class KeyUpBehavior : Trigger private void AssociatedObject_OnClick(object? sender, RoutedEventArgs e) { - if (AssociatedObject is null || Key != key) return; - key = Key.None; + if (AssociatedObject is null || Key != _key) return; + _key = Key.None; Interaction.ExecuteActions(AssociatedObject, Actions, e); } private void Button_OnKeyDown(object? sender, KeyEventArgs e) { - key = e.Key; + _key = e.Key; } } \ No newline at end of file diff --git a/DownKyi/CustomControl/CustomPagerViewModel.cs b/DownKyi/CustomControl/CustomPagerViewModel.cs index b39122d..9bdd83f 100644 --- a/DownKyi/CustomControl/CustomPagerViewModel.cs +++ b/DownKyi/CustomControl/CustomPagerViewModel.cs @@ -50,11 +50,11 @@ public class CustomPagerViewModel : INotifyPropertyChanged } } - private int count; + private int _count; public int Count { - get { return count; } + get => _count; set { if (value < Current || value < 0) @@ -65,11 +65,11 @@ public class CustomPagerViewModel : INotifyPropertyChanged } else { - count = value; + _count = value; - Visibility = count > 1; + Visibility = _count > 1; - OnCountChanged(count); + OnCountChanged(_count); SetView(); @@ -99,7 +99,7 @@ public class CustomPagerViewModel : INotifyPropertyChanged } else { - bool isSuccess = OnCurrentChanged(_current, value); + var isSuccess = OnCurrentChanged(_current, value); if (isSuccess) { _current = value; @@ -116,7 +116,7 @@ public class CustomPagerViewModel : INotifyPropertyChanged public int First { - get { return _first; } + get => _first; set { _first = value; diff --git a/DownKyi/CustomControl/Loading.cs b/DownKyi/CustomControl/Loading.cs index 1d0b1f8..4a62c98 100644 --- a/DownKyi/CustomControl/Loading.cs +++ b/DownKyi/CustomControl/Loading.cs @@ -4,116 +4,106 @@ using Avalonia.Controls.Primitives; namespace DownKyi.CustomControl; -public class Loading: TemplatedControl +public class Loading : TemplatedControl { private const string LargeState = ":large"; - private const string SmallState = ":small"; + private const string SmallState = ":small"; - private const string InactiveState = ":inactive"; - private const string ActiveState = ":active"; + private const string InactiveState = ":inactive"; + private const string ActiveState = ":active"; - private double _maxSideLength = 10; - private double _ellipseDiameter = 10; - private Thickness _ellipseOffset = new Thickness(2); + private double _maxSideLength = 10; + private double _ellipseDiameter = 10; + private Thickness _ellipseOffset = new(2); - static Loading() + static Loading() + { + //DefaultStyleKeyProperty.OverrideMetadata(typeof(ProgressRing), + // new FrameworkPropertyMetadata(typeof(ProgressRing))); + } + + public Loading() + { + } + + #region IsActive + + public bool IsActive + { + get => GetValue(IsActiveProperty); + set => SetValue(IsActiveProperty, value); + } + + + public static readonly StyledProperty IsActiveProperty = AvaloniaProperty.Register(nameof(IsActive), defaultValue: true); + + private static void OnIsActiveChanged(AvaloniaObject obj, bool arg2) + { + ((Loading)obj).UpdateVisualStates(); + } + + public static readonly DirectProperty MaxSideLengthProperty = AvaloniaProperty.RegisterDirect(nameof(MaxSideLength), o => o.MaxSideLength); + + public double MaxSideLength + { + get => _maxSideLength; + private set => SetAndRaise(MaxSideLengthProperty, ref _maxSideLength, value); + } + + public static readonly DirectProperty EllipseDiameterProperty = + AvaloniaProperty.RegisterDirect(nameof(EllipseDiameter), o => o.EllipseDiameter); + + public double EllipseDiameter + { + get => _ellipseDiameter; + private set => SetAndRaise(EllipseDiameterProperty, ref _ellipseDiameter, value); + } + + public static readonly DirectProperty EllipseOffsetProperty = + AvaloniaProperty.RegisterDirect(nameof(EllipseOffset), o => o.EllipseOffset); + + public Thickness EllipseOffset + { + get => _ellipseOffset; + private set => SetAndRaise(EllipseOffsetProperty, ref _ellipseOffset, value); + } + + #endregion + + + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + double maxSideLength = Math.Min(this.Width, this.Height); + double ellipseDiameter = 0.1 * maxSideLength; + if (maxSideLength <= 40) { - //DefaultStyleKeyProperty.OverrideMetadata(typeof(ProgressRing), - // new FrameworkPropertyMetadata(typeof(ProgressRing))); + ellipseDiameter += 1; } - public Loading() + EllipseDiameter = ellipseDiameter; + MaxSideLength = maxSideLength; + EllipseOffset = new Thickness(0, maxSideLength / 2 - ellipseDiameter, 0, 0); + UpdateVisualStates(); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == IsActiveProperty) { - } - - #region IsActive - - public bool IsActive - { - get => (bool)GetValue(IsActiveProperty); - set => SetValue(IsActiveProperty, value); - } - - - public static readonly StyledProperty IsActiveProperty = - AvaloniaProperty.Register( - nameof(IsActive), - defaultValue: true); - - private static void OnIsActiveChanged(AvaloniaObject obj, bool arg2) - { - ((Loading)obj).UpdateVisualStates(); - } - - public static readonly DirectProperty MaxSideLengthProperty = - AvaloniaProperty.RegisterDirect( - nameof(MaxSideLength), - o => o.MaxSideLength); - - public double MaxSideLength - { - get { return _maxSideLength; } - private set { SetAndRaise(MaxSideLengthProperty, ref _maxSideLength, value); } - } - - public static readonly DirectProperty EllipseDiameterProperty = - AvaloniaProperty.RegisterDirect( - nameof(EllipseDiameter), - o => o.EllipseDiameter); - - public double EllipseDiameter - { - get { return _ellipseDiameter; } - private set { SetAndRaise(EllipseDiameterProperty, ref _ellipseDiameter, value); } - } - - public static readonly DirectProperty EllipseOffsetProperty = - AvaloniaProperty.RegisterDirect( - nameof(EllipseOffset), - o => o.EllipseOffset); - - public Thickness EllipseOffset - { - get { return _ellipseOffset; } - private set { SetAndRaise(EllipseOffsetProperty, ref _ellipseOffset, value); } - } - - #endregion - - - protected override void OnApplyTemplate(TemplateAppliedEventArgs e) - { - base.OnApplyTemplate(e); - double maxSideLength = Math.Min(this.Width, this.Height); - double ellipseDiameter = 0.1 * maxSideLength; - if (maxSideLength <= 40) - { - ellipseDiameter += 1; - } - - EllipseDiameter = ellipseDiameter; - MaxSideLength = maxSideLength; - EllipseOffset = new Thickness(0, maxSideLength / 2 - ellipseDiameter, 0, 0); UpdateVisualStates(); } + } - protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) - { - base.OnPropertyChanged(change); - - if (change.Property == IsActiveProperty) - { - UpdateVisualStates(); - } - } - - private void UpdateVisualStates() - { - PseudoClasses.Remove(ActiveState); - PseudoClasses.Remove(InactiveState); - PseudoClasses.Remove(SmallState); - PseudoClasses.Remove(LargeState); - PseudoClasses.Add(IsActive ? ActiveState : InactiveState); - PseudoClasses.Add(_maxSideLength < 60 ? SmallState : LargeState); - } + private void UpdateVisualStates() + { + PseudoClasses.Remove(ActiveState); + PseudoClasses.Remove(InactiveState); + PseudoClasses.Remove(SmallState); + PseudoClasses.Remove(LargeState); + PseudoClasses.Add(IsActive ? ActiveState : InactiveState); + PseudoClasses.Add(_maxSideLength < 60 ? SmallState : LargeState); + } } \ No newline at end of file diff --git a/DownKyi/Images/ButtonIcon.cs b/DownKyi/Images/ButtonIcon.cs index 39a48a6..d8cd83b 100644 --- a/DownKyi/Images/ButtonIcon.cs +++ b/DownKyi/Images/ButtonIcon.cs @@ -15,8 +15,11 @@ public class ButtonIcon { Height = 20, Width = 20, - Data = - @"M697.91 755.7 q-132.36 103.48 -290.59 98.06 q-158.23 -5.41 -278.56 -120.92 q-127.54 -133.56 -128.75 -304.43
 q-1.21 -170.86 120.33 -304.43 q127.55 -126.34 297.21 -123.94 q169.66 2.41 303.22 123.94 q110.71 114.31 122.14 263.52
 q11.43 149.21 -75.21 275.55 l238.25 239.45 q18.05 18.05 18.05 42.12 q0 24.06 -18.05 41.51 q-18.05 17.45 -42.12 17.45
 q-24.07 0 -42.12 -16.85 l-223.81 -231.03 ZM643.76 647.41 q92.66 -96.26 92.66 -219 q0 -122.73 -92.66 -218.99 q-96.26 -92.66 -219 -92.66
 q-122.74 0 -218.99 92.66 q-92.65 96.26 -92.65 218.99 q0 122.74 92.65 219 q96.26 92.65 218.99 90.25 q122.74 -2.4 219 -90.25 Z", + Data = @"M697.91 755.7 q-132.36 103.48 -290.59 98.06 q-158.23 -5.41 -278.56 -120.92 q-127.54 -133.56 -128.75 -304.43 + q-1.21 -170.86 120.33 -304.43 q127.55 -126.34 297.21 -123.94 q169.66 2.41 303.22 123.94 q110.71 114.31 122.14 263.52 + q11.43 149.21 -75.21 275.55 l238.25 239.45 q18.05 18.05 18.05 42.12 q0 24.06 -18.05 41.51 q-18.05 17.45 -42.12 17.45 + q-24.07 0 -42.12 -16.85 l-223.81 -231.03 ZM643.76 647.41 q92.66 -96.26 92.66 -219 q0 -122.73 -92.66 -218.99 q-96.26 -92.66 -219 -92.66 + q-122.74 0 -218.99 92.66 q-92.65 96.26 -92.65 218.99 q0 122.74 92.65 219 q96.26 92.65 218.99 90.25 q122.74 -2.4 219 -90.25 Z", Fill = "#FF000000" }; @@ -24,8 +27,12 @@ public class ButtonIcon { Height = 32, Width = 32, - Data = - @"M19.4,13c0-0.3,0.1-0.6,0.1-1s0-0.7-0.1-1l2.1-1.7c0.2-0.2,0.2-0.4,0.1-0.6l-2-3.5C19.5,5,19.3,5,19,5l-2.5,1
 c-0.5-0.4-1.1-0.7-1.7-1l-0.4-2.7C14.5,2.2,14.3,2,14,2h-4C9.8,2,9.5,2.2,9.5,2.4L9.1,5.1C8.5,5.3,8,5.7,7.4,6L5,5
 C4.7,5,4.5,5,4.3,5.3l-2,3.5C2.2,9,2.3,9.2,2.5,9.4L4.6,11c0,0.3-0.1,0.6-0.1,1s0,0.7,0.1,1l-2.1,1.7c-0.2,0.1-0.2,0.4-0.1,0.6
 l2,3.5C4.5,19,4.7,19,5,19l2.5-1c0.5,0.4,1.1,0.7,1.7,1l0.4,2.7c0,0.2,0.2,0.4,0.5,0.4h4c0.3,0,0.5-0.2,0.5-0.4l0.4-2.7
 c0.6-0.3,1.2-0.6,1.7-1l2.5,1c0.2,0.1,0.5,0,0.6-0.2l2-3.5c0.1-0.2,0.1-0.5-0.1-0.6L19.4,13z M12,15.5c-1.9,0-3.5-1.6-3.5-3.5
 s1.6-3.5,3.5-3.5s3.5,1.6,3.5,3.5S13.9,15.5,12,15.5z", + Data = @"M19.4,13c0-0.3,0.1-0.6,0.1-1s0-0.7-0.1-1l2.1-1.7c0.2-0.2,0.2-0.4,0.1-0.6l-2-3.5C19.5,5,19.3,5,19,5l-2.5,1 + c-0.5-0.4-1.1-0.7-1.7-1l-0.4-2.7C14.5,2.2,14.3,2,14,2h-4C9.8,2,9.5,2.2,9.5,2.4L9.1,5.1C8.5,5.3,8,5.7,7.4,6L5,5 + C4.7,5,4.5,5,4.3,5.3l-2,3.5C2.2,9,2.3,9.2,2.5,9.4L4.6,11c0,0.3-0.1,0.6-0.1,1s0,0.7,0.1,1l-2.1,1.7c-0.2,0.1-0.2,0.4-0.1,0.6 + l2,3.5C4.5,19,4.7,19,5,19l2.5-1c0.5,0.4,1.1,0.7,1.7,1l0.4,2.7c0,0.2,0.2,0.4,0.5,0.4h4c0.3,0,0.5-0.2,0.5-0.4l0.4-2.7 + c0.6-0.3,1.2-0.6,1.7-1l2.5,1c0.2,0.1,0.5,0,0.6-0.2l2-3.5c0.1-0.2,0.1-0.5-0.1-0.6L19.4,13z M12,15.5c-1.9,0-3.5-1.6-3.5-3.5 + s1.6-3.5,3.5-3.5s3.5,1.6,3.5,3.5S13.9,15.5,12,15.5z", Fill = "#FF000000" }; @@ -35,8 +42,16 @@ public class ButtonIcon Width = 32, //Height = 20, //Width = 24, - Data = - @"M24,34c-2.4,0-4.9,0-7.3,0c-2.8,0-4.6-1.9-4.6-4.7c0-3.5,0-7,0-10.5c0-2.9,1.9-4.7,4.6-4.7c1.3,0,2.6,0,3.9,0
 c1.1-0.1,2,0.4,2.7,1.3c1.1,1.7,2.6,2.3,4.6,2.1c1.3-0.2,2.6-0.1,4,0c2.5,0.2,4,1.7,4.2,4.3c0.2,2.7,0.2,5.5,0,8.3
 c-0.2,2.4-2,4-4.3,4C29,34,26.5,34,24,34L24,34z
 M23.9,32.6c2.5,0,5,0,7.5,0c1.7,0,2.9-1,3-2.7c0.2-2.8,0.2-5.6,0-8.5
 c-0.1-1.5-1.1-2.4-2.5-2.6c-1.3-0.2-2.6-0.1-3.9-0.1c-4.1-0.1-3,0.5-6-2.6c-0.5-0.5-1-0.8-1.7-0.8c-1.3,0-2.5,0-3.8,0
 c-2,0-3.2,1.2-3.3,3.2c0,3.6,0,7.1,0,10.7c0,2,1.2,3.2,3.2,3.2C19,32.6,21.5,32.6,23.9,32.6L23.9,32.6z
 M29.9,14.2h3.3c0.5,0,0.9,0,0.9,0.7c0,0.7-0.4,0.8-0.9,0.8c-2.2,0-4.5,0-6.7,0c-0.5,0-0.9-0.1-0.9-0.7
 s0.4-0.7,0.9-0.7C27.6,14.2,28.7,14.2,29.9,14.2L29.9,14.2z M23.3,27.6v-5.4c0-0.5,0-1.1,0.7-1.1c0.7,0,0.6,0.6,0.6,1v5.2
 c0.7-0.7,1.2-1.2,1.7-1.7c0.3-0.4,0.7-0.7,1.2-0.2c0.5,0.5,0.1,0.9-0.2,1.2c-0.9,1-1.8,1.9-2.7,2.8c-0.4,0.5-0.8,0.5-1.3,0.1
 c-1-1-2-2.1-3-3.1c-0.3-0.3-0.4-0.7-0.1-1c0.3-0.4,0.7-0.3,1,0.1C22,26.1,22.6,26.7,23.3,27.6L23.3,27.6z", + Data = @"M24,34c-2.4,0-4.9,0-7.3,0c-2.8,0-4.6-1.9-4.6-4.7c0-3.5,0-7,0-10.5c0-2.9,1.9-4.7,4.6-4.7c1.3,0,2.6,0,3.9,0 + c1.1-0.1,2,0.4,2.7,1.3c1.1,1.7,2.6,2.3,4.6,2.1c1.3-0.2,2.6-0.1,4,0c2.5,0.2,4,1.7,4.2,4.3c0.2,2.7,0.2,5.5,0,8.3 + c-0.2,2.4-2,4-4.3,4C29,34,26.5,34,24,34L24,34z + M23.9,32.6c2.5,0,5,0,7.5,0c1.7,0,2.9-1,3-2.7c0.2-2.8,0.2-5.6,0-8.5 + c-0.1-1.5-1.1-2.4-2.5-2.6c-1.3-0.2-2.6-0.1-3.9-0.1c-4.1-0.1-3,0.5-6-2.6c-0.5-0.5-1-0.8-1.7-0.8c-1.3,0-2.5,0-3.8,0 + c-2,0-3.2,1.2-3.3,3.2c0,3.6,0,7.1,0,10.7c0,2,1.2,3.2,3.2,3.2C19,32.6,21.5,32.6,23.9,32.6L23.9,32.6z + M29.9,14.2h3.3c0.5,0,0.9,0,0.9,0.7c0,0.7-0.4,0.8-0.9,0.8c-2.2,0-4.5,0-6.7,0c-0.5,0-0.9-0.1-0.9-0.7 + s0.4-0.7,0.9-0.7C27.6,14.2,28.7,14.2,29.9,14.2L29.9,14.2z M23.3,27.6v-5.4c0-0.5,0-1.1,0.7-1.1c0.7,0,0.6,0.6,0.6,1v5.2 + c0.7-0.7,1.2-1.2,1.7-1.7c0.3-0.4,0.7-0.7,1.2-0.2c0.5,0.5,0.1,0.9-0.2,1.2c-0.9,1-1.8,1.9-2.7,2.8c-0.4,0.5-0.8,0.5-1.3,0.1 + c-1-1-2-2.1-3-3.1c-0.3-0.3-0.4-0.7-0.1-1c0.3-0.4,0.7-0.3,1,0.1C22,26.1,22.6,26.7,23.3,27.6L23.3,27.6z", Fill = "#FF000000" }; @@ -44,7 +59,10 @@ public class ButtonIcon { Height = 28, // 21 Width = 32, // 24 - Data = @"M20.2,14.5c-0.8,2.3-3.4,3.6-5.7,2.7c-1.3-0.5-2.3-1.5-2.7-2.7H5.5V13h21v1.5H20.2z M18.6,14.5h-5.2
 c0.8,1.4,2.7,1.9,4.1,1.1C18,15.3,18.3,15,18.6,14.5L18.6,14.5z M10,8.5V7c0-0.8,0.7-1.5,1.5-1.5h9C21.3,5.5,22,6.2,22,7v1.5h4.5
 c0.8,0,1.5,0.7,1.5,1.5v15c0,0.8-0.7,1.5-1.5,1.5l0,0h-21C4.7,26.5,4,25.8,4,25l0,0V10c0-0.8,0.7-1.5,1.5-1.5H10z M11.5,8.5h9V7h-9
 V8.5z M5.5,10v15h21V10H5.5z", + Data = @"M20.2,14.5c-0.8,2.3-3.4,3.6-5.7,2.7c-1.3-0.5-2.3-1.5-2.7-2.7H5.5V13h21v1.5H20.2z M18.6,14.5h-5.2 + c0.8,1.4,2.7,1.9,4.1,1.1C18,15.3,18.3,15,18.6,14.5L18.6,14.5z M10,8.5V7c0-0.8,0.7-1.5,1.5-1.5h9C21.3,5.5,22,6.2,22,7v1.5h4.5 + c0.8,0,1.5,0.7,1.5,1.5v15c0,0.8-0.7,1.5-1.5,1.5l0,0h-21C4.7,26.5,4,25.8,4,25l0,0V10c0-0.8,0.7-1.5,1.5-1.5H10z M11.5,8.5h9V7h-9 + V8.5z M5.5,10v15h21V10H5.5z", Fill = "#FF000000" }; @@ -52,8 +70,10 @@ public class ButtonIcon { Height = 20, Width = 20, - Data = - @"M683 85 q0 -27 -20.5 -55 q-20.5 -28 -65.5 -30 l-170 0 q-39 1 -62 23.5 q-23 22.5 -24 61.5 l-341 0 l0 86 l1024 0 l0 -86
 l-341 0 ZM341 256 l86 0 l0 597 l-86 0 l0 -597 ZM597 256 l86 0 l0 597 l-86 0 l0 -597 ZM853 853 q0 39 -23 62
 q-23 23 -62 24 l-512 0 q-39 -1 -62 -24 q-23 -23 -23 -62 l0 -597 l-86 0 l0 597 q2 73 50.5 121 q48.5 48 120.5 50 l512 0
 q72 -2 120.5 -50 q48.5 -48 50.5 -121 l0 -597 l-86 0 l0 597 Z", + Data = @"M683 85 q0 -27 -20.5 -55 q-20.5 -28 -65.5 -30 l-170 0 q-39 1 -62 23.5 q-23 22.5 -24 61.5 l-341 0 l0 86 l1024 0 l0 -86 + l-341 0 ZM341 256 l86 0 l0 597 l-86 0 l0 -597 ZM597 256 l86 0 l0 597 l-86 0 l0 -597 ZM853 853 q0 39 -23 62 + q-23 23 -62 24 l-512 0 q-39 -1 -62 -24 q-23 -23 -23 -62 l0 -597 l-86 0 l0 597 q2 73 50.5 121 q48.5 48 120.5 50 l512 0 + q72 -2 120.5 -50 q48.5 -48 50.5 -121 l0 -597 l-86 0 l0 597 Z", Fill = "#FF000000" }; @@ -61,8 +81,11 @@ public class ButtonIcon { Height = 18, Width = 18, - Data = - @"M634.29 513.52 l364.34 -363.32 q25.37 -27.4 25.37 -60.89 q0 -33.49 -26.38 -59.88 q-26.38 -26.39 -59.88 -26.39
 q-33.49 0 -60.9 25.38 l-363.32 364.33 l-363.32 -372.45 q-28.42 -20.3 -65.46 -20.3 q-37.04 0 -64.44 20.3
 q-20.3 27.4 -20.3 64.44 q0 37.04 20.3 65.46 l372.45 363.32 l-364.33 363.32 q-25.38 27.41 -25.38 60.9 q0 33.49 26.39 59.88
 q26.39 26.38 59.88 26.38 q33.49 0 60.89 -25.37 l363.32 -364.34 l363.32 364.34 q27.41 25.37 60.9 25.37 q33.49 0 59.88 -26.38
 q26.38 -26.38 26.38 -59.88 q0 -33.49 -25.37 -60.9 l-364.34 -363.32 Z", + Data = @"M634.29 513.52 l364.34 -363.32 q25.37 -27.4 25.37 -60.89 q0 -33.49 -26.38 -59.88 q-26.38 -26.39 -59.88 -26.39 + q-33.49 0 -60.9 25.38 l-363.32 364.33 l-363.32 -372.45 q-28.42 -20.3 -65.46 -20.3 q-37.04 0 -64.44 20.3 + q-20.3 27.4 -20.3 64.44 q0 37.04 20.3 65.46 l372.45 363.32 l-364.33 363.32 q-25.38 27.41 -25.38 60.9 q0 33.49 26.39 59.88 + q26.39 26.38 59.88 26.38 q33.49 0 60.89 -25.37 l363.32 -364.34 l363.32 364.34 q27.41 25.37 60.9 25.37 q33.49 0 59.88 -26.38 + q26.38 -26.38 26.38 -59.88 q0 -33.49 -25.37 -60.9 l-364.34 -363.32 Z", Fill = "#FF000000" }; @@ -70,8 +93,10 @@ public class ButtonIcon { Height = 20, Width = 17, - Data = - @"M895.12 402.34 l-633.28 -383.81 q-30.16 -17.82 -64.43 -18.51 q-34.27 -0.69 -65.11 16.45 q-30.84 17.13 -47.97 47.29
 q-17.13 30.16 -17.13 64.42 l0 767.62 q0 34.27 17.13 63.74 q17.14 29.47 47.97 47.29 q30.84 17.82 65.11 17.13
 q34.27 -0.69 64.43 -18.5 l633.28 -383.81 q28.79 -17.82 45.24 -46.6 q16.45 -28.79 16.45 -63.06 q0 -34.27 -16.45 -63.05
 q-16.45 -28.79 -45.24 -46.61 Z", + Data = @"M895.12 402.34 l-633.28 -383.81 q-30.16 -17.82 -64.43 -18.51 q-34.27 -0.69 -65.11 16.45 q-30.84 17.13 -47.97 47.29 + q-17.13 30.16 -17.13 64.42 l0 767.62 q0 34.27 17.13 63.74 q17.14 29.47 47.97 47.29 q30.84 17.82 65.11 17.13 + q34.27 -0.69 64.43 -18.5 l633.28 -383.81 q28.79 -17.82 45.24 -46.6 q16.45 -28.79 16.45 -63.06 q0 -34.27 -16.45 -63.05 + q-16.45 -28.79 -45.24 -46.61 Z", Fill = "#FF000000" }; @@ -79,8 +104,10 @@ public class ButtonIcon { Height = 20, Width = 15, - Data = - @"M255.66 0 q-53.75 0 -90.97 37.21 q-37.21 37.21 -37.21 90.96 l0 769.04 q1.38 55.12 37.21 90.95 q35.84 35.84 90.28 35.84
 q54.44 0 90.96 -35.84 q36.52 -35.83 37.9 -90.95 l0 -769.04 q-1.38 -53.75 -38.59 -90.96 q-37.21 -37.21 -89.58 -37.21
 ZM768.34 0 q-52.37 0 -89.58 37.21 q-37.21 37.21 -38.59 90.96 l0 769.04 q1.38 55.12 37.9 90.95 q36.52 35.84 90.96 35.84
 q54.44 0 90.28 -35.84 q35.83 -35.83 37.21 -90.95 l0 -769.04 q0 -53.75 -37.21 -90.96 q-37.22 -37.21 -90.97 -37.21 Z", + Data = @"M255.66 0 q-53.75 0 -90.97 37.21 q-37.21 37.21 -37.21 90.96 l0 769.04 q1.38 55.12 37.21 90.95 q35.84 35.84 90.28 35.84 + q54.44 0 90.96 -35.84 q36.52 -35.83 37.9 -90.95 l0 -769.04 q-1.38 -53.75 -38.59 -90.96 q-37.21 -37.21 -89.58 -37.21 + ZM768.34 0 q-52.37 0 -89.58 37.21 q-37.21 37.21 -38.59 90.96 l0 769.04 q1.38 55.12 37.9 90.95 q36.52 35.84 90.96 35.84 + q54.44 0 90.28 -35.84 q35.83 -35.83 37.21 -90.95 l0 -769.04 q0 -53.75 -37.21 -90.96 q-37.22 -37.21 -90.97 -37.21 Z", Fill = "#FF000000" }; @@ -88,7 +115,15 @@ public class ButtonIcon { Height = 20, Width = 20, - Data = @"M536.69 128.65 q-161.14 5.2 -270.3 113.71 q-109.15 108.5 -113.05 269.64 q3.9 161.14 113.05 269.64
 q109.16 108.5 270.3 113.71 q101.36 -1.3 185.82 -47.43 q84.47 -46.13 140.35 -129.3 q6.5 -14.3 22.09 -24.7
 q15.6 -10.39 31.19 -10.39 q28.59 0 47.44 18.85 q18.84 18.85 20.14 48.74 q0 11.69 -5.2 20.79 q0 3.9 0 7.8 l-3.9 5.19
 q-72.77 111.76 -185.82 174.78 q-113.06 63.03 -246.91 64.33 q-102.66 0 -196.22 -38.34 q-93.57 -38.33 -166.34 -111.11
 q-72.77 -72.77 -111.1 -166.34 q-38.33 -93.56 -38.33 -196.22 q0 -102.66 38.33 -196.23 q38.34 -93.56 111.1 -166.33
 q72.77 -72.77 166.34 -111.1 q93.56 -38.34 196.22 -38.34 q92.26 0 176.73 31.19 q84.47 31.19 152.04 89.66 l0 -25.99
 q1.3 -27.29 18.2 -44.83 q16.89 -17.54 42.88 -17.54 q25.99 0 44.18 18.19 q18.19 18.19 18.19 44.18 l0 189.73
 q0 24.69 -18.19 42.88 q-18.19 18.19 -42.88 18.19 l-191.03 0 q-24.69 0 -42.88 -18.19 q-18.2 -18.19 -18.2 -42.88
 q0 -28.59 16.25 -47.43 q16.25 -18.84 44.84 -20.13 l37.69 0 q-51.98 -42.89 -114.36 -65.63 q-62.38 -22.74 -128.65 -22.74 Z", + Data = @"M536.69 128.65 q-161.14 5.2 -270.3 113.71 q-109.15 108.5 -113.05 269.64 q3.9 161.14 113.05 269.64 + q109.16 108.5 270.3 113.71 q101.36 -1.3 185.82 -47.43 q84.47 -46.13 140.35 -129.3 q6.5 -14.3 22.09 -24.7 + q15.6 -10.39 31.19 -10.39 q28.59 0 47.44 18.85 q18.84 18.85 20.14 48.74 q0 11.69 -5.2 20.79 q0 3.9 0 7.8 l-3.9 5.19 + q-72.77 111.76 -185.82 174.78 q-113.06 63.03 -246.91 64.33 q-102.66 0 -196.22 -38.34 q-93.57 -38.33 -166.34 -111.11 + q-72.77 -72.77 -111.1 -166.34 q-38.33 -93.56 -38.33 -196.22 q0 -102.66 38.33 -196.23 q38.34 -93.56 111.1 -166.33 + q72.77 -72.77 166.34 -111.1 q93.56 -38.34 196.22 -38.34 q92.26 0 176.73 31.19 q84.47 31.19 152.04 89.66 l0 -25.99 + q1.3 -27.29 18.2 -44.83 q16.89 -17.54 42.88 -17.54 q25.99 0 44.18 18.19 q18.19 18.19 18.19 44.18 l0 189.73 + q0 24.69 -18.19 42.88 q-18.19 18.19 -42.88 18.19 l-191.03 0 q-24.69 0 -42.88 -18.19 q-18.2 -18.19 -18.2 -42.88 + q0 -28.59 16.25 -47.43 q16.25 -18.84 44.84 -20.13 l37.69 0 q-51.98 -42.89 -114.36 -65.63 q-62.38 -22.74 -128.65 -22.74 Z", Fill = "#FF000000" }; diff --git a/DownKyi/Images/SystemIcon.cs b/DownKyi/Images/SystemIcon.cs index b00f0ab..9de562e 100644 --- a/DownKyi/Images/SystemIcon.cs +++ b/DownKyi/Images/SystemIcon.cs @@ -38,7 +38,7 @@ public class SystemIcon Height = 1.2, Width = 12, Data = - @"M17.8,25.8c-0.5,0-0.8-0.3-0.8-0.8s0.3-0.8,0.8-0.8h14.4c0.5,0,0.8,0.3,0.8,0.8s-0.3,0.8-0.8,0.8H17.8z", + "M17.8,25.8c-0.5,0-0.8-0.3-0.8-0.8s0.3-0.8,0.8-0.8h14.4c0.5,0,0.8,0.3,0.8,0.8s-0.3,0.8-0.8,0.8H17.8z", Fill = "#FF000000" }; diff --git a/DownKyi/Models/Downloaded.cs b/DownKyi/Models/Downloaded.cs index cf492e9..e269380 100644 --- a/DownKyi/Models/Downloaded.cs +++ b/DownKyi/Models/Downloaded.cs @@ -19,8 +19,8 @@ public class Downloaded // : DownloadBase { FinishedTimestamp = finishedTimestamp; - DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 - DateTime dateTime = startTime.AddSeconds(finishedTimestamp); + var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 + var dateTime = startTime.AddSeconds(finishedTimestamp); FinishedTime = dateTime.ToString("yyyy-MM-dd HH:mm:ss"); } diff --git a/DownKyi/Services/AlertService.cs b/DownKyi/Services/AlertService.cs index f97ca21..ce7feef 100644 --- a/DownKyi/Services/AlertService.cs +++ b/DownKyi/Services/AlertService.cs @@ -24,8 +24,8 @@ public class AlertService /// public Task ShowInfo(string message, int buttonNumber = 2) { - VectorImage image = SystemIcon.Instance().Info; - string title = DictionaryResource.GetString("Info"); + var image = SystemIcon.Instance().Info; + var title = DictionaryResource.GetString("Info"); return ShowMessage(image, title, message, buttonNumber); } @@ -37,8 +37,8 @@ public class AlertService /// public Task ShowWarning(string message, int buttonNumber = 1) { - VectorImage image = SystemIcon.Instance().Warning; - string title = DictionaryResource.GetString("Warning"); + var image = SystemIcon.Instance().Warning; + var title = DictionaryResource.GetString("Warning"); return ShowMessage(image, title, message, buttonNumber); } @@ -49,8 +49,8 @@ public class AlertService /// public Task ShowError(string message) { - VectorImage image = SystemIcon.Instance().Error; - string title = DictionaryResource.GetString("Error"); + var image = SystemIcon.Instance().Error; + var title = DictionaryResource.GetString("Error"); return ShowMessage(image, title, message, 1); } @@ -70,11 +70,7 @@ public class AlertService { "button_number", buttonNumber } }; - await dialogService.ShowDialogAsync(ViewAlertDialogViewModel.Tag, param, - buttonResult => - { - result = buttonResult.Result; - }); + await dialogService.ShowDialogAsync(ViewAlertDialogViewModel.Tag, param, buttonResult => { result = buttonResult.Result; }); return result; } } \ No newline at end of file diff --git a/DownKyi/Services/FavoritesService.cs b/DownKyi/Services/FavoritesService.cs index e164156..cb713b5 100644 --- a/DownKyi/Services/FavoritesService.cs +++ b/DownKyi/Services/FavoritesService.cs @@ -29,10 +29,9 @@ public class FavoritesService : IFavoritesService } // 查询、保存封面 - StorageCover storageCover = new StorageCover(); - string coverUrl = favoritesMetaInfo.Cover; - Bitmap cover = storageCover.GetCoverThumbnail(favoritesMetaInfo.Id, "Favorites", favoritesMetaInfo.Mid, - coverUrl, 300, 188); + var storageCover = new StorageCover(); + var coverUrl = favoritesMetaInfo.Cover; + var cover = storageCover.GetCoverThumbnail(favoritesMetaInfo.Id, "Favorites", favoritesMetaInfo.Mid, coverUrl, 300, 188); // 获取用户头像 string upName; @@ -40,9 +39,8 @@ public class FavoritesService : IFavoritesService if (favoritesMetaInfo.Upper != null) { upName = favoritesMetaInfo.Upper.Name; - StorageHeader storageHeader = new StorageHeader(); - header = storageHeader.GetHeader(favoritesMetaInfo.Upper.Mid, favoritesMetaInfo.Upper.Name, - favoritesMetaInfo.Upper.Face); + var storageHeader = new StorageHeader(); + header = storageHeader.GetHeader(favoritesMetaInfo.Upper.Mid, favoritesMetaInfo.Upper.Name, favoritesMetaInfo.Upper.Face); } else { @@ -51,16 +49,16 @@ public class FavoritesService : IFavoritesService } // 为Favorites赋值 - Favorites favorites = new Favorites(); - App.PropertyChangeAsync(new Action(() => + var favorites = new Favorites(); + App.PropertyChangeAsync(() => { favorites.CoverUrl = coverUrl; favorites.Cover = cover; favorites.Title = favoritesMetaInfo.Title; - DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 - DateTime dateTime = startTime.AddSeconds(favoritesMetaInfo.Ctime); + var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 + var dateTime = startTime.AddSeconds(favoritesMetaInfo.Ctime); favorites.CreateTime = dateTime.ToString("yyyy-MM-dd HH:mm:ss"); favorites.PlayNumber = Format.FormatNumber(favoritesMetaInfo.CntInfo.Play); @@ -73,7 +71,7 @@ public class FavoritesService : IFavoritesService favorites.UpName = upName; if (header != null) { - StorageHeader storageHeader = new StorageHeader(); + var storageHeader = new StorageHeader(); favorites.UpHeader = storageHeader.GetHeaderThumbnail(header, 48, 48); favorites.UpperMid = favoritesMetaInfo.Upper.Mid; @@ -82,7 +80,7 @@ public class FavoritesService : IFavoritesService { favorites.UpHeader = null; } - })); + }); return favorites; } @@ -123,11 +121,11 @@ public class FavoritesService : IFavoritesService /// /// /// - public void GetFavoritesMediaList(List medias, - ObservableCollection result, IEventAggregator eventAggregator, + /// + public void GetFavoritesMediaList(List medias, ObservableCollection result, IEventAggregator eventAggregator, CancellationToken cancellationToken) { - int order = 0; + var order = 0; foreach (var media in medias) { if (media.Title == "已失效视频") @@ -138,47 +136,46 @@ public class FavoritesService : IFavoritesService order++; // 查询、保存封面 - StorageCover storageCover = new StorageCover(); - string coverUrl = media.Cover; + var storageCover = new StorageCover(); + var coverUrl = media.Cover; Bitmap cover = storageCover.GetCoverThumbnail(media.Id, media.Bvid, -1, coverUrl, 200, 125); // 当地时区 DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 创建时间 - DateTime dateCTime = startTime.AddSeconds(media.Ctime); - string ctime = dateCTime.ToString("yyyy-MM-dd"); + var dateCTime = startTime.AddSeconds(media.Ctime); + var ctime = dateCTime.ToString("yyyy-MM-dd"); // 收藏时间 - DateTime dateFavTime = startTime.AddSeconds(media.FavTime); - string favTime = dateFavTime.ToString("yyyy-MM-dd"); + var dateFavTime = startTime.AddSeconds(media.FavTime); + var favTime = dateFavTime.ToString("yyyy-MM-dd"); - App.PropertyChangeAsync(new Action(() => + App.PropertyChangeAsync(() => { - ViewModels.PageViewModels.FavoritesMedia newMedia = - new ViewModels.PageViewModels.FavoritesMedia(eventAggregator) - { - Avid = media.Id, - Bvid = media.Bvid, - Order = order, - Cover = cover, - Title = media.Title, - PlayNumber = media.CntInfo != null ? Format.FormatNumber(media.CntInfo.Play) : "0", - DanmakuNumber = media.CntInfo != null ? Format.FormatNumber(media.CntInfo.Danmaku) : "0", - FavoriteNumber = media.CntInfo != null ? Format.FormatNumber(media.CntInfo.Collect) : "0", - Duration = Format.FormatDuration2(media.Duration), - UpName = media.Upper != null ? media.Upper.Name : string.Empty, - UpMid = media.Upper != null ? media.Upper.Mid : -1, - CreateTime = ctime, - FavTime = favTime - }; + var newMedia = new ViewModels.PageViewModels.FavoritesMedia(eventAggregator) + { + Avid = media.Id, + Bvid = media.Bvid, + Order = order, + Cover = cover, + Title = media.Title, + PlayNumber = media.CntInfo != null ? Format.FormatNumber(media.CntInfo.Play) : "0", + DanmakuNumber = media.CntInfo != null ? Format.FormatNumber(media.CntInfo.Danmaku) : "0", + FavoriteNumber = media.CntInfo != null ? Format.FormatNumber(media.CntInfo.Collect) : "0", + Duration = Format.FormatDuration2(media.Duration), + UpName = media.Upper != null ? media.Upper.Name : string.Empty, + UpMid = media.Upper != null ? media.Upper.Mid : -1, + CreateTime = ctime, + FavTime = favTime + }; if (!result.ToList().Exists(t => t.Avid == newMedia.Avid)) { result.Add(newMedia); Thread.Sleep(10); } - })); + }); // 判断是否该结束线程,若为true,跳出循环 if (cancellationToken.IsCancellationRequested) @@ -193,8 +190,8 @@ public class FavoritesService : IFavoritesService /// /// /// - public void GetCreatedFavorites(long mid, ObservableCollection tabHeaders, - CancellationToken cancellationToken) + /// + public void GetCreatedFavorites(long mid, ObservableCollection tabHeaders, CancellationToken cancellationToken) { var favorites = FavoritesInfo.GetAllCreatedFavorites(mid); if (favorites.Count == 0) @@ -212,11 +209,7 @@ public class FavoritesService : IFavoritesService break; } - App.PropertyChangeAsync(new Action(() => - { - tabHeaders.Add(new TabHeader - { Id = item.Id, Title = item.Title, SubTitle = item.MediaCount.ToString() }); - })); + App.PropertyChangeAsync(() => { tabHeaders.Add(new TabHeader { Id = item.Id, Title = item.Title, SubTitle = item.MediaCount.ToString() }); }); } } @@ -225,8 +218,8 @@ public class FavoritesService : IFavoritesService /// /// /// - public void GetCollectedFavorites(long mid, ObservableCollection tabHeaders, - CancellationToken cancellationToken) + /// + public void GetCollectedFavorites(long mid, ObservableCollection tabHeaders, CancellationToken cancellationToken) { var favorites = FavoritesInfo.GetAllCollectedFavorites(mid); if (favorites.Count == 0) @@ -242,11 +235,7 @@ public class FavoritesService : IFavoritesService break; } - App.PropertyChangeAsync(new Action(() => - { - tabHeaders.Add(new TabHeader - { Id = item.Id, Title = item.Title, SubTitle = item.MediaCount.ToString() }); - })); + App.PropertyChangeAsync(() => { tabHeaders.Add(new TabHeader { Id = item.Id, Title = item.Title, SubTitle = item.MediaCount.ToString() }); }); } } } \ No newline at end of file diff --git a/DownKyi/Services/IFavoritesService.cs b/DownKyi/Services/IFavoritesService.cs index 5f36e6e..41c7619 100644 --- a/DownKyi/Services/IFavoritesService.cs +++ b/DownKyi/Services/IFavoritesService.cs @@ -13,13 +13,10 @@ public interface IFavoritesService //void GetFavoritesMediaList(long mediaId, ObservableCollection result, IEventAggregator eventAggregator, CancellationToken cancellationToken); //void GetFavoritesMediaList(long mediaId, int pn, int ps, ObservableCollection result, IEventAggregator eventAggregator, CancellationToken cancellationToken); - void GetFavoritesMediaList(List medias, - ObservableCollection result, IEventAggregator eventAggregator, + void GetFavoritesMediaList(List medias, ObservableCollection result, IEventAggregator eventAggregator, CancellationToken cancellationToken); - void GetCreatedFavorites(long mid, ObservableCollection tabHeaders, - CancellationToken cancellationToken); + void GetCreatedFavorites(long mid, ObservableCollection tabHeaders, CancellationToken cancellationToken); - void GetCollectedFavorites(long mid, ObservableCollection tabHeaders, - CancellationToken cancellationToken); + void GetCollectedFavorites(long mid, ObservableCollection tabHeaders, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/DownKyi/Services/SearchService.cs b/DownKyi/Services/SearchService.cs index 7fd0660..6001f74 100644 --- a/DownKyi/Services/SearchService.cs +++ b/DownKyi/Services/SearchService.cs @@ -27,13 +27,12 @@ public class SearchService public bool BiliInput(string input, string parentViewName, IEventAggregator eventAggregator) { // 移除剪贴板id - string justId = input.Replace(AppConstant.ClipboardId, ""); + var justId = input.Replace(AppConstant.ClipboardId, ""); // 视频 if (ParseEntrance.IsAvId(justId)) { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, - $"{ParseEntrance.VideoUrl}{input.ToLower()}"); + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, $"{ParseEntrance.VideoUrl}{input.ToLower()}"); } else if (ParseEntrance.IsAvUrl(justId)) { @@ -41,8 +40,7 @@ public class SearchService } else if (ParseEntrance.IsBvId(justId)) { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, - $"{ParseEntrance.VideoUrl}{input}"); + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, $"{ParseEntrance.VideoUrl}{input}"); } else if (ParseEntrance.IsBvUrl(justId)) { @@ -51,8 +49,7 @@ public class SearchService // 番剧(电影、电视剧) else if (ParseEntrance.IsBangumiSeasonId(justId)) { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, - $"{ParseEntrance.BangumiUrl}{input.ToLower()}"); + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, $"{ParseEntrance.BangumiUrl}{input.ToLower()}"); } else if (ParseEntrance.IsBangumiSeasonUrl(justId)) { @@ -60,8 +57,7 @@ public class SearchService } else if (ParseEntrance.IsBangumiEpisodeId(justId)) { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, - $"{ParseEntrance.BangumiUrl}{input.ToLower()}"); + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, $"{ParseEntrance.BangumiUrl}{input.ToLower()}"); } else if (ParseEntrance.IsBangumiEpisodeUrl(justId)) { @@ -69,39 +65,35 @@ public class SearchService } else if (ParseEntrance.IsBangumiMediaId(justId)) { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, - $"{ParseEntrance.BangumiMediaUrl}{input.ToLower()}"); + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, $"{ParseEntrance.BangumiMediaUrl}{input.ToLower()}"); } else if (ParseEntrance.IsBangumiMediaUrl(justId)) { NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, input); } // 课程 - else if (ParseEntrance.IsCheeseSeasonUrl(justId) - || ParseEntrance.IsCheeseEpisodeUrl(justId)) + else if (ParseEntrance.IsCheeseSeasonUrl(justId) || ParseEntrance.IsCheeseEpisodeUrl(justId)) { NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, input); } // 用户(参数传入mid) else if (ParseEntrance.IsUserId(justId)) { - NavigateToView.NavigateToViewUserSpace(eventAggregator, ViewIndexViewModel.Tag, - ParseEntrance.GetUserId(input)); + NavigateToView.NavigateToViewUserSpace(eventAggregator, ViewIndexViewModel.Tag, ParseEntrance.GetUserId(input)); } else if (ParseEntrance.IsUserUrl(justId)) { - NavigateToView.NavigateToViewUserSpace(eventAggregator, ViewIndexViewModel.Tag, - ParseEntrance.GetUserId(input)); + NavigateToView.NavigateToViewUserSpace(eventAggregator, ViewIndexViewModel.Tag, ParseEntrance.GetUserId(input)); + } + // 收藏夹 + else if (ParseEntrance.IsFavoritesId(justId)) + { + NavigateToView.NavigationView(eventAggregator, ViewPublicFavoritesViewModel.Tag, parentViewName, ParseEntrance.GetFavoritesId(input)); + } + else if (ParseEntrance.IsFavoritesUrl(justId)) + { + NavigateToView.NavigationView(eventAggregator, ViewPublicFavoritesViewModel.Tag, parentViewName, ParseEntrance.GetFavoritesId(input)); } - // // 收藏夹 - // else if (ParseEntrance.IsFavoritesId(justId)) - // { - // NavigateToView.NavigationView(eventAggregator, ViewPublicFavoritesViewModel.Tag, parentViewName, ParseEntrance.GetFavoritesId(input)); - // } - // else if (ParseEntrance.IsFavoritesUrl(justId)) - // { - // NavigateToView.NavigationView(eventAggregator, ViewPublicFavoritesViewModel.Tag, parentViewName, ParseEntrance.GetFavoritesId(input)); - // } else { return false; diff --git a/DownKyi/Services/Utils.cs b/DownKyi/Services/Utils.cs index c330b0d..2602310 100644 --- a/DownKyi/Services/Utils.cs +++ b/DownKyi/Services/Utils.cs @@ -28,10 +28,10 @@ internal static class Utils page.PlayUrl = playUrl; // 获取设置 - UserInfoSettings userInfo = SettingsManager.GetInstance().GetUserInfo(); - int defaultQuality = SettingsManager.GetInstance().GetQuality(); - int videoCodecs = SettingsManager.GetInstance().GetVideoCodecs(); - int defaultAudioQuality = SettingsManager.GetInstance().GetAudioQuality(); + var userInfo = SettingsManager.GetInstance().GetUserInfo(); + var defaultQuality = SettingsManager.GetInstance().GetQuality(); + var videoCodecs = SettingsManager.GetInstance().GetVideoCodecs(); + var defaultAudioQuality = SettingsManager.GetInstance().GetAudioQuality(); // 未登录时,最高仅720P if (userInfo.Mid == -1) @@ -106,13 +106,13 @@ internal static class Utils /// private static ObservableCollection GetAudioQualityFormatList(PlayUrl playUrl, int defaultAudioQuality) { - List audioQualityFormatList = new List(); - List sortList = new List(); - List audioQualities = Constant.GetAudioQualities(); + var audioQualityFormatList = new List(); + var sortList = new List(); + var audioQualities = Constant.GetAudioQualities(); if (playUrl.Dash.Audio != null && playUrl.Dash.Audio.Count > 0) { - foreach (PlayUrlDashVideo audio in playUrl.Dash.Audio) + foreach (var audio in playUrl.Dash.Audio) { // 音质id大于设置音质时,跳过 if (audio.Id > defaultAudioQuality) @@ -120,7 +120,7 @@ internal static class Utils continue; } - Quality audioQuality = audioQualities.FirstOrDefault(t => { return t.Id == audio.Id; }); + var audioQuality = audioQualities.FirstOrDefault(t => { return t.Id == audio.Id; }); if (audioQuality != null) { ListHelper.AddUnique(audioQualityFormatList, audioQuality.Name); @@ -171,15 +171,15 @@ internal static class Utils private static List GetVideoQualityList(PlayUrl playUrl, UserInfoSettings userInfo, int defaultQuality, int videoCodecs) { - List videoQualityList = new List(); - List codeIds = Constant.GetCodecIds(); + var videoQualityList = new List(); + var codeIds = Constant.GetCodecIds(); if (playUrl.Dash.Video == null) { return videoQualityList; } - foreach (PlayUrlDashVideo video in playUrl.Dash.Video) + foreach (var video in playUrl.Dash.Video) { // 画质id大于设置画质时,跳过 if (video.Id > defaultQuality) @@ -197,8 +197,8 @@ internal static class Utils } } - string qualityFormat = string.Empty; - PlayUrlSupportFormat selectedQuality = playUrl.SupportFormats.FirstOrDefault(t => t.Quality == video.Id); + var qualityFormat = string.Empty; + var selectedQuality = playUrl.SupportFormats.FirstOrDefault(t => t.Quality == video.Id); if (selectedQuality != null) { qualityFormat = selectedQuality.NewDescription; @@ -207,17 +207,17 @@ internal static class Utils // 寻找是否已存在这个画质 // 不存在则添加,存在则修改 //string codecName = GetVideoCodecName(video.Codecs); - string codecName = codeIds.FirstOrDefault(t => t.Id == video.CodecId).Name; - VideoQuality videoQualityExist = videoQualityList.FirstOrDefault(t => t.Quality == video.Id); + var codecName = codeIds.FirstOrDefault(t => t.Id == video.CodecId).Name; + var videoQualityExist = videoQualityList.FirstOrDefault(t => t.Quality == video.Id); if (videoQualityExist == null) { - List videoCodecList = new List(); + var videoCodecList = new List(); if (codecName != string.Empty) { ListHelper.AddUnique(videoCodecList, codecName); } - VideoQuality videoQuality = new VideoQuality() + var videoQuality = new VideoQuality { Quality = video.Id, QualityFormat = qualityFormat, @@ -238,23 +238,22 @@ internal static class Utils } // 设置选中的视频编码 - VideoQuality selectedVideoQuality = videoQualityList.FirstOrDefault(t => t.Quality == video.Id); + var selectedVideoQuality = videoQualityList.FirstOrDefault(t => t.Quality == video.Id); if (selectedVideoQuality == null) { continue; } // 设置选中的视频编码 - string videoCodecsName = codeIds.FirstOrDefault(t => t.Id == videoCodecs).Name; - if (videoQualityList[videoQualityList.IndexOf(selectedVideoQuality)].VideoCodecList - .Contains(videoCodecsName)) + var videoCodecsName = codeIds.FirstOrDefault(t => t.Id == videoCodecs).Name; + if (videoQualityList[videoQualityList.IndexOf(selectedVideoQuality)].VideoCodecList.Contains(videoCodecsName)) { videoQualityList[videoQualityList.IndexOf(selectedVideoQuality)].SelectedVideoCodec = videoCodecsName; } else { // 当获取的视频没有设置的视频编码时 - foreach (Quality codec in codeIds) + foreach (var codec in codeIds) { if (videoQualityList[videoQualityList.IndexOf(selectedVideoQuality)].VideoCodecList .Contains(codec.Name)) diff --git a/DownKyi/Utils/DialogUtils.cs b/DownKyi/Utils/DialogUtils.cs index c05f821..2c46e5b 100644 --- a/DownKyi/Utils/DialogUtils.cs +++ b/DownKyi/Utils/DialogUtils.cs @@ -20,8 +20,7 @@ public static class DialogUtils /// public static async Task SetDownloadDirectory() { - if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop || - desktop.MainWindow?.StorageProvider is not { } provider) + if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop || desktop.MainWindow?.StorageProvider is not { } provider) throw new NullReferenceException("Missing StorageProvider instance."); var folders = await provider.OpenFolderPickerAsync(new FolderPickerOpenOptions { @@ -38,16 +37,14 @@ public static class DialogUtils /// public static async Task SelectVideoFile() { - if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop || - desktop.MainWindow?.StorageProvider is not { } provider) + if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop || desktop.MainWindow?.StorageProvider is not { } provider) throw new NullReferenceException("Missing StorageProvider instance."); var files = await provider.OpenFilePickerAsync(new FilePickerOpenOptions { Title = "选择视频", SuggestedStartLocation = await provider.TryGetFolderFromPathAsync(new Uri(DefaultDirectory)), AllowMultiple = false, - FileTypeFilter = new FilePickerFileType[] - { new("select") { Patterns = new[] { "*.mp4" }, MimeTypes = new[] { "video/mp4" } } } + FileTypeFilter = new FilePickerFileType[] { new("select") { Patterns = new[] { "*.mp4" }, MimeTypes = new[] { "video/mp4" } } } }); // 选择文件 @@ -60,8 +57,7 @@ public static class DialogUtils /// public static async Task SelectMultiVideoFile() { - if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop || - desktop.MainWindow?.StorageProvider is not { } provider) + if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop || desktop.MainWindow?.StorageProvider is not { } provider) throw new NullReferenceException("Missing StorageProvider instance."); var files = await provider.OpenFilePickerAsync( new FilePickerOpenOptions @@ -69,8 +65,7 @@ public static class DialogUtils Title = "选择视频", SuggestedStartLocation = await provider.TryGetFolderFromPathAsync(new Uri(DefaultDirectory)), AllowMultiple = true, - FileTypeFilter = new FilePickerFileType[] - { new("select") { Patterns = new[] { "*.mp4" } } } + FileTypeFilter = new FilePickerFileType[] { new("select") { Patterns = new[] { "*.mp4" } } } } ); diff --git a/DownKyi/Utils/NavigateToView.cs b/DownKyi/Utils/NavigateToView.cs index 67f165c..a5d55ee 100644 --- a/DownKyi/Utils/NavigateToView.cs +++ b/DownKyi/Utils/NavigateToView.cs @@ -18,7 +18,7 @@ public static class NavigateToView /// public static void NavigateToViewUserSpace(IEventAggregator eventAggregator, string parentViewName, long mid) { - UserInfoSettings userInfo = SettingsManager.GetInstance().GetUserInfo(); + var userInfo = SettingsManager.GetInstance().GetUserInfo(); if (userInfo != null && userInfo.Mid == mid) { NavigationView(eventAggregator, ViewMySpaceViewModel.Tag, parentViewName, mid); @@ -34,11 +34,10 @@ public static class NavigateToView /// /// /// - public static void NavigationView(IEventAggregator eventAggregator, string viewName, string parentViewName, - object param) + public static void NavigationView(IEventAggregator eventAggregator, string viewName, string parentViewName, object param) { // LogManager.Debug(Tag, $"NavigationView: {viewName}, Parameter: {param}"); - NavigationParam parameter = new NavigationParam + var parameter = new NavigationParam { ViewName = viewName, ParentViewName = parentViewName, diff --git a/DownKyi/ViewModels/Dialogs/BaseDialogViewModel.cs b/DownKyi/ViewModels/Dialogs/BaseDialogViewModel.cs index 5ba2d8d..1b14ab8 100644 --- a/DownKyi/ViewModels/Dialogs/BaseDialogViewModel.cs +++ b/DownKyi/ViewModels/Dialogs/BaseDialogViewModel.cs @@ -12,20 +12,20 @@ public class BaseDialogViewModel : BindableBase, IDialogAware { #region 页面属性申明 - private string title; + private string _title; public string Title { - get => title; - set => SetProperty(ref title, value); + get => _title; + set => SetProperty(ref _title, value); } - private VectorImage closeIcon; + private VectorImage _closeIcon; public VectorImage CloseIcon { - get => closeIcon; - set => SetProperty(ref closeIcon, value); + get => _closeIcon; + set => SetProperty(ref _closeIcon, value); } #endregion @@ -49,10 +49,9 @@ public class BaseDialogViewModel : BindableBase, IDialogAware #region 命令申明 // 鼠标进入关闭按钮事件 - private DelegateCommand closeEnterCommand; + private DelegateCommand? _closeEnterCommand; - public DelegateCommand CloseEnterCommand => - closeEnterCommand ?? (closeEnterCommand = new DelegateCommand(ExecuteCloseEnterCommand)); + public DelegateCommand CloseEnterCommand => _closeEnterCommand ??= new DelegateCommand(ExecuteCloseEnterCommand); /// /// 鼠标进入关闭按钮事件 @@ -63,10 +62,9 @@ public class BaseDialogViewModel : BindableBase, IDialogAware } // 鼠标离开关闭按钮事件 - private DelegateCommand closeLeaveCommand; + private DelegateCommand? _closeLeaveCommand; - public DelegateCommand CloseLeaveCommand => - closeLeaveCommand ?? (closeLeaveCommand = new DelegateCommand(ExecuteCloseLeaveCommand)); + public DelegateCommand CloseLeaveCommand => _closeLeaveCommand ??= new DelegateCommand(ExecuteCloseLeaveCommand); /// /// 鼠标离开关闭按钮事件 @@ -77,16 +75,15 @@ public class BaseDialogViewModel : BindableBase, IDialogAware } // 关闭窗口事件 - private DelegateCommand closeCommand; - public DelegateCommand CloseCommand => closeCommand ?? (closeCommand = new DelegateCommand(ExecuteCloseCommand)); + private DelegateCommand? _closeCommand; + public DelegateCommand CloseCommand => _closeCommand ??= new DelegateCommand(ExecuteCloseCommand); /// /// 关闭窗口事件 /// private void ExecuteCloseCommand() { - ButtonResult result = ButtonResult.Cancel; - RaiseRequestClose(new DialogResult(result)); + RaiseRequestClose(new DialogResult(ButtonResult.Cancel)); } #endregion diff --git a/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs b/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs index 4ab866a..85ceff2 100644 --- a/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs +++ b/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs @@ -10,37 +10,37 @@ public class ViewAlertDialogViewModel : BaseDialogViewModel #region 页面属性申明 - private VectorImage image; + private VectorImage _image; public VectorImage Image { - get => image; - set => SetProperty(ref image, value); + get => _image; + set => SetProperty(ref _image, value); } - private string message; + private string _message; public string Message { - get => message; - set => SetProperty(ref message, value); + get => _message; + set => SetProperty(ref _message, value); } - private bool aloneButton; + private bool _aloneButton; public bool AloneButton { - get => aloneButton; - set => SetProperty(ref aloneButton, value); + get => _aloneButton; + set => SetProperty(ref _aloneButton, value); } - private bool twoButton; + private bool _twoButton; public bool TwoButton { - get => twoButton; - set => SetProperty(ref twoButton, value); + get => _twoButton; + set => SetProperty(ref _twoButton, value); } #endregion @@ -52,8 +52,8 @@ public class ViewAlertDialogViewModel : BaseDialogViewModel #region 命令申明 // 确认事件 - private DelegateCommand allowCommand; - public DelegateCommand AllowCommand => allowCommand ?? (allowCommand = new DelegateCommand(ExecuteAllowCommand)); + private DelegateCommand? _allowCommand; + public DelegateCommand AllowCommand => _allowCommand ??= new DelegateCommand(ExecuteAllowCommand); /// /// 确认事件 @@ -75,7 +75,7 @@ public class ViewAlertDialogViewModel : BaseDialogViewModel Image = parameters.GetValue("image"); Title = parameters.GetValue("title"); Message = parameters.GetValue("message"); - int number = parameters.GetValue("button_number"); + var number = parameters.GetValue("button_number"); switch (number) { diff --git a/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs b/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs index a3d2e74..82157c4 100644 --- a/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs +++ b/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs @@ -18,121 +18,121 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel private readonly IEventAggregator eventAggregator; // 历史文件夹的数量 - private readonly int maxDirectoryListCount = 20; + private const int MaxDirectoryListCount = 20; #region 页面属性申明 - private VectorImage cloudDownloadIcon; + private VectorImage _cloudDownloadIcon; public VectorImage CloudDownloadIcon { - get { return cloudDownloadIcon; } - set { SetProperty(ref cloudDownloadIcon, value); } + get => _cloudDownloadIcon; + set => SetProperty(ref _cloudDownloadIcon, value); } - private VectorImage folderIcon; + private VectorImage _folderIcon; public VectorImage FolderIcon { - get { return folderIcon; } - set { SetProperty(ref folderIcon, value); } + get => _folderIcon; + set => SetProperty(ref _folderIcon, value); } - private bool isDefaultDownloadDirectory; + private bool _isDefaultDownloadDirectory; public bool IsDefaultDownloadDirectory { - get { return isDefaultDownloadDirectory; } - set { SetProperty(ref isDefaultDownloadDirectory, value); } + get => _isDefaultDownloadDirectory; + set => SetProperty(ref _isDefaultDownloadDirectory, value); } - private List directoryList; + private List _directoryList; public List DirectoryList { - get { return directoryList; } - set { SetProperty(ref directoryList, value); } + get => _directoryList; + set => SetProperty(ref _directoryList, value); } - private string directory; + private string _directory; public string Directory { - get { return directory; } + get => _directory; set { - SetProperty(ref directory, value); + SetProperty(ref _directory, value); - if (directory != null && directory != string.Empty) + if (!string.IsNullOrEmpty(_directory)) { - DriveName = directory.Substring(0, 1).ToUpper(); + DriveName = _directory[..1].ToUpper(); DriveNameFreeSpace = Format.FormatFileSize(HardDisk.GetHardDiskFreeSpace(DriveName)); } } } - private string driveName; + private string _driveName; public string DriveName { - get { return driveName; } - set { SetProperty(ref driveName, value); } + get => _driveName; + set => SetProperty(ref _driveName, value); } - private string driveNameFreeSpace; + private string _driveNameFreeSpace; public string DriveNameFreeSpace { - get { return driveNameFreeSpace; } - set { SetProperty(ref driveNameFreeSpace, value); } + get => _driveNameFreeSpace; + set => SetProperty(ref _driveNameFreeSpace, value); } - private bool downloadAll; + private bool _downloadAll; public bool DownloadAll { - get { return downloadAll; } - set { SetProperty(ref downloadAll, value); } + get => _downloadAll; + set => SetProperty(ref _downloadAll, value); } - private bool downloadAudio; + private bool _downloadAudio; public bool DownloadAudio { - get { return downloadAudio; } - set { SetProperty(ref downloadAudio, value); } + get => _downloadAudio; + set => SetProperty(ref _downloadAudio, value); } - private bool downloadVideo; + private bool _downloadVideo; public bool DownloadVideo { - get { return downloadVideo; } - set { SetProperty(ref downloadVideo, value); } + get => _downloadVideo; + set => SetProperty(ref _downloadVideo, value); } - private bool downloadDanmaku; + private bool _downloadDanmaku; public bool DownloadDanmaku { - get { return downloadDanmaku; } - set { SetProperty(ref downloadDanmaku, value); } + get => _downloadDanmaku; + set => SetProperty(ref _downloadDanmaku, value); } - private bool downloadSubtitle; + private bool _downloadSubtitle; public bool DownloadSubtitle { - get { return downloadSubtitle; } - set { SetProperty(ref downloadSubtitle, value); } + get => _downloadSubtitle; + set => SetProperty(ref _downloadSubtitle, value); } - private bool downloadCover; + private bool _downloadCover; public bool DownloadCover { - get { return downloadCover; } - set { SetProperty(ref downloadCover, value); } + get => _downloadCover; + set => SetProperty(ref _downloadCover, value); } #endregion @@ -152,7 +152,7 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel FolderIcon.Fill = DictionaryResource.GetColor("ColorPrimary"); // 下载内容 - VideoContentSettings videoContent = SettingsManager.GetInstance().GetVideoContent(); + var videoContent = SettingsManager.GetInstance().GetVideoContent(); DownloadAudio = videoContent.DownloadAudio; DownloadVideo = videoContent.DownloadVideo; @@ -171,7 +171,7 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel // 历史下载目录 DirectoryList = SettingsManager.GetInstance().GetHistoryVideoRootPaths(); - string directory = SettingsManager.GetInstance().GetSaveVideoRootPath(); + var directory = SettingsManager.GetInstance().GetSaveVideoRootPath(); if (!DirectoryList.Contains(directory)) { ListHelper.InsertUnique(DirectoryList, directory, 0); @@ -188,10 +188,9 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel #region 命令申明 // 浏览文件夹事件 - private DelegateCommand browseCommand; + private DelegateCommand? _browseCommand; - public DelegateCommand BrowseCommand => - browseCommand ?? (browseCommand = new DelegateCommand(ExecuteBrowseCommand)); + public DelegateCommand BrowseCommand => _browseCommand ??= new DelegateCommand(ExecuteBrowseCommand); /// /// 浏览文件夹事件 @@ -210,18 +209,17 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel ListHelper.InsertUnique(DirectoryList, directory, 0); Directory = directory; - if (DirectoryList.Count > maxDirectoryListCount) + if (DirectoryList.Count > MaxDirectoryListCount) { - DirectoryList.RemoveAt(maxDirectoryListCount); + DirectoryList.RemoveAt(MaxDirectoryListCount); } } } // 所有内容选择事件 - private DelegateCommand downloadAllCommand; + private DelegateCommand? _downloadAllCommand; - public DelegateCommand DownloadAllCommand => - downloadAllCommand ?? (downloadAllCommand = new DelegateCommand(ExecuteDownloadAllCommand)); + public DelegateCommand DownloadAllCommand => _downloadAllCommand ??= new DelegateCommand(ExecuteDownloadAllCommand); /// /// 所有内容选择事件 @@ -249,11 +247,9 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel } // 音频选择事件 - private DelegateCommand downloadAudioCommand; + private DelegateCommand? _downloadAudioCommand; - public DelegateCommand DownloadAudioCommand => downloadAudioCommand ?? - (downloadAudioCommand = - new DelegateCommand(ExecuteDownloadAudioCommand)); + public DelegateCommand DownloadAudioCommand => _downloadAudioCommand ??= new DelegateCommand(ExecuteDownloadAudioCommand); /// /// 音频选择事件 @@ -274,11 +270,9 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel } // 视频选择事件 - private DelegateCommand downloadVideoCommand; + private DelegateCommand? _downloadVideoCommand; - public DelegateCommand DownloadVideoCommand => downloadVideoCommand ?? - (downloadVideoCommand = - new DelegateCommand(ExecuteDownloadVideoCommand)); + public DelegateCommand DownloadVideoCommand => _downloadVideoCommand ??= new DelegateCommand(ExecuteDownloadVideoCommand); /// /// 视频选择事件 @@ -299,11 +293,9 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel } // 弹幕选择事件 - private DelegateCommand downloadDanmakuCommand; + private DelegateCommand? _downloadDanmakuCommand; - public DelegateCommand DownloadDanmakuCommand => downloadDanmakuCommand ?? - (downloadDanmakuCommand = - new DelegateCommand(ExecuteDownloadDanmakuCommand)); + public DelegateCommand DownloadDanmakuCommand => _downloadDanmakuCommand ??= new DelegateCommand(ExecuteDownloadDanmakuCommand); /// /// 弹幕选择事件 @@ -324,11 +316,9 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel } // 字幕选择事件 - private DelegateCommand downloadSubtitleCommand; + private DelegateCommand? _downloadSubtitleCommand; - public DelegateCommand DownloadSubtitleCommand => downloadSubtitleCommand ?? - (downloadSubtitleCommand = - new DelegateCommand(ExecuteDownloadSubtitleCommand)); + public DelegateCommand DownloadSubtitleCommand => _downloadSubtitleCommand ??= new DelegateCommand(ExecuteDownloadSubtitleCommand); /// /// 字幕选择事件 @@ -349,11 +339,9 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel } // 封面选择事件 - private DelegateCommand downloadCoverCommand; + private DelegateCommand? _downloadCoverCommand; - public DelegateCommand DownloadCoverCommand => downloadCoverCommand ?? - (downloadCoverCommand = - new DelegateCommand(ExecuteDownloadCoverCommand)); + public DelegateCommand DownloadCoverCommand => _downloadCoverCommand ??= new DelegateCommand(ExecuteDownloadCoverCommand); /// /// 封面选择事件 @@ -374,30 +362,22 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel } // 确认下载事件 - private DelegateCommand downloadCommand; + private DelegateCommand? _downloadCommand; - public DelegateCommand DownloadCommand => - downloadCommand ?? (downloadCommand = new DelegateCommand(ExecuteDownloadCommand)); + public DelegateCommand DownloadCommand => _downloadCommand ??= new DelegateCommand(ExecuteDownloadCommand); /// /// 确认下载事件 /// private void ExecuteDownloadCommand() { - if (Directory == null || Directory == string.Empty) + if (string.IsNullOrEmpty(Directory)) { return; } // 设此文件夹为默认下载文件夹 - if (IsDefaultDownloadDirectory) - { - SettingsManager.GetInstance().IsUseSaveVideoRootPath(AllowStatus.YES); - } - else - { - SettingsManager.GetInstance().IsUseSaveVideoRootPath(AllowStatus.NO); - } + SettingsManager.GetInstance().IsUseSaveVideoRootPath(IsDefaultDownloadDirectory ? AllowStatus.YES : AllowStatus.NO); // 将Directory移动到第一项 // 如果直接在ComboBox中选择的就需要 @@ -409,7 +389,6 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel SettingsManager.GetInstance().SetHistoryVideoRootPaths(DirectoryList); // 返回数据 - ButtonResult result = ButtonResult.OK; IDialogParameters parameters = new DialogParameters { { "directory", Directory }, @@ -420,7 +399,7 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel { "downloadCover", DownloadCover } }; - RaiseRequestClose(new DialogResult(result, parameters)); + RaiseRequestClose(new DialogResult(ButtonResult.OK, parameters)); } #endregion @@ -430,7 +409,7 @@ public class ViewDownloadSetterViewModel : BaseDialogViewModel /// private void SetVideoContent() { - VideoContentSettings videoContent = new VideoContentSettings + var videoContent = new VideoContentSettings { DownloadAudio = DownloadAudio, DownloadVideo = DownloadVideo, diff --git a/DownKyi/ViewModels/Dialogs/ViewParsingSelectorViewModel.cs b/DownKyi/ViewModels/Dialogs/ViewParsingSelectorViewModel.cs index 8ffba88..342e452 100644 --- a/DownKyi/ViewModels/Dialogs/ViewParsingSelectorViewModel.cs +++ b/DownKyi/ViewModels/Dialogs/ViewParsingSelectorViewModel.cs @@ -11,12 +11,12 @@ public class ViewParsingSelectorViewModel : BaseDialogViewModel #region 页面属性申明 - private bool isParseDefault; + private bool _isParseDefault; public bool IsParseDefault { - get { return isParseDefault; } - set { SetProperty(ref isParseDefault, value); } + get => _isParseDefault; + set => SetProperty(ref _isParseDefault, value); } #endregion @@ -28,7 +28,7 @@ public class ViewParsingSelectorViewModel : BaseDialogViewModel Title = DictionaryResource.GetString("ParsingSelector"); // 解析范围 - ParseScope parseScope = SettingsManager.GetInstance().GetParseScope(); + var parseScope = SettingsManager.GetInstance().GetParseScope(); IsParseDefault = parseScope != ParseScope.NONE; #endregion @@ -37,11 +37,9 @@ public class ViewParsingSelectorViewModel : BaseDialogViewModel #region 命令申明 // 解析当前项事件 - private DelegateCommand parseSelectedItemCommand; + private DelegateCommand? _parseSelectedItemCommand; - public DelegateCommand ParseSelectedItemCommand => parseSelectedItemCommand ?? - (parseSelectedItemCommand = - new DelegateCommand(ExecuteParseSelectedItemCommand)); + public DelegateCommand ParseSelectedItemCommand => _parseSelectedItemCommand ??= new DelegateCommand(ExecuteParseSelectedItemCommand); /// /// 解析当前项事件 @@ -50,21 +48,18 @@ public class ViewParsingSelectorViewModel : BaseDialogViewModel { SetParseScopeSetting(ParseScope.SELECTED_ITEM); - ButtonResult result = ButtonResult.OK; IDialogParameters parameters = new DialogParameters { { "parseScope", ParseScope.SELECTED_ITEM } }; - RaiseRequestClose(new DialogResult(result, parameters)); + RaiseRequestClose(new DialogResult(ButtonResult.OK, parameters)); } // 解析当前页视频事件 - private DelegateCommand parseCurrentSectionCommand; + private DelegateCommand? _parseCurrentSectionCommand; - public DelegateCommand ParseCurrentSectionCommand => parseCurrentSectionCommand ?? - (parseCurrentSectionCommand = - new DelegateCommand(ExecuteParseCurrentSectionCommand)); + public DelegateCommand ParseCurrentSectionCommand => _parseCurrentSectionCommand ??= new DelegateCommand(ExecuteParseCurrentSectionCommand); /// /// 解析当前页视频事件 @@ -73,20 +68,18 @@ public class ViewParsingSelectorViewModel : BaseDialogViewModel { SetParseScopeSetting(ParseScope.CURRENT_SECTION); - ButtonResult result = ButtonResult.OK; IDialogParameters parameters = new DialogParameters { { "parseScope", ParseScope.CURRENT_SECTION } }; - RaiseRequestClose(new DialogResult(result, parameters)); + RaiseRequestClose(new DialogResult(ButtonResult.OK, parameters)); } // 解析所有视频事件 - private DelegateCommand parseAllCommand; + private DelegateCommand? _parseAllCommand; - public DelegateCommand ParseAllCommand => - parseAllCommand ?? (parseAllCommand = new DelegateCommand(ExecuteParseAllCommand)); + public DelegateCommand ParseAllCommand => _parseAllCommand ??= new DelegateCommand(ExecuteParseAllCommand); /// /// 解析所有视频事件 @@ -95,13 +88,12 @@ public class ViewParsingSelectorViewModel : BaseDialogViewModel { SetParseScopeSetting(ParseScope.ALL); - ButtonResult result = ButtonResult.OK; IDialogParameters parameters = new DialogParameters { { "parseScope", ParseScope.ALL } }; - RaiseRequestClose(new DialogResult(result, parameters)); + RaiseRequestClose(new DialogResult(ButtonResult.OK, parameters)); } #endregion @@ -112,13 +104,6 @@ public class ViewParsingSelectorViewModel : BaseDialogViewModel /// private void SetParseScopeSetting(ParseScope parseScope) { - if (IsParseDefault) - { - SettingsManager.GetInstance().SetParseScope(parseScope); - } - else - { - SettingsManager.GetInstance().SetParseScope(ParseScope.NONE); - } + SettingsManager.GetInstance().SetParseScope(IsParseDefault ? parseScope : ParseScope.NONE); } } \ No newline at end of file diff --git a/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs b/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs index feee46c..7a646da 100644 --- a/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs +++ b/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; @@ -23,18 +22,18 @@ namespace DownKyi.ViewModels.DownloadManager #region 页面属性申明 - private ObservableCollection downloadedList; + private ObservableCollection _downloadedList; public ObservableCollection DownloadedList { - get => downloadedList; - set => SetProperty(ref downloadedList, value); + get => _downloadedList; + set => SetProperty(ref _downloadedList, value); } - private int finishedSortBy; + private int _finishedSortBy; public int FinishedSortBy { - get => finishedSortBy; - set => SetProperty(ref finishedSortBy, value); + get => _finishedSortBy; + set => SetProperty(ref _finishedSortBy, value); } #endregion @@ -53,26 +52,20 @@ namespace DownKyi.ViewModels.DownloadManager SetDialogService(); DownloadFinishedSort finishedSort = SettingsManager.GetInstance().GetDownloadFinishedSort(); - switch (finishedSort) + FinishedSortBy = finishedSort switch { - case DownloadFinishedSort.DOWNLOAD: - FinishedSortBy = 0; - break; - case DownloadFinishedSort.NUMBER: - FinishedSortBy = 1; - break; - default: - FinishedSortBy = 0; - break; - } + DownloadFinishedSort.DOWNLOAD => 0, + DownloadFinishedSort.NUMBER => 1, + _ => 0 + }; App.SortDownloadedList(finishedSort); } #region 命令申明 // 下载完成列表排序事件 - private DelegateCommand finishedSortCommand; - public DelegateCommand FinishedSortCommand => finishedSortCommand ?? (finishedSortCommand = new DelegateCommand(ExecuteFinishedSortCommand)); + private DelegateCommand? _finishedSortCommand; + public DelegateCommand FinishedSortCommand => _finishedSortCommand ??= new DelegateCommand(ExecuteFinishedSortCommand); /// /// 下载完成列表排序事件 @@ -103,16 +96,16 @@ namespace DownKyi.ViewModels.DownloadManager } // 清空下载完成列表事件 - private DelegateCommand clearAllDownloadedCommand; - public DelegateCommand ClearAllDownloadedCommand => clearAllDownloadedCommand ?? (clearAllDownloadedCommand = new DelegateCommand(ExecuteClearAllDownloadedCommand)); + private DelegateCommand? _clearAllDownloadedCommand; + public DelegateCommand ClearAllDownloadedCommand => _clearAllDownloadedCommand ??= new DelegateCommand(ExecuteClearAllDownloadedCommand); /// /// 清空下载完成列表事件 /// private async void ExecuteClearAllDownloadedCommand() { - AlertService alertService = new AlertService(DialogService); - ButtonResult result = await alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete")); + var alertService = new AlertService(DialogService); + var result = await alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete")); if (result != ButtonResult.OK) { return; @@ -123,8 +116,8 @@ namespace DownKyi.ViewModels.DownloadManager // DownloadingList中元素被删除后不能继续遍历 await Task.Run(() => { - List list = DownloadedList.ToList(); - foreach (DownloadedItem item in list) + var list = DownloadedList.ToList(); + foreach (var item in list) { App.PropertyChangeAsync(() => { @@ -142,7 +135,7 @@ namespace DownKyi.ViewModels.DownloadManager { await Task.Run(() => { - List list = DownloadedList.ToList(); + var list = DownloadedList.ToList(); foreach (var item in list) { if (item != null && item.DialogService == null) diff --git a/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs b/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs index 8503709..a68c062 100644 --- a/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs +++ b/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; @@ -24,12 +23,12 @@ namespace DownKyi.ViewModels.DownloadManager #region 页面属性申明 - private ObservableCollection downloadingList; + private ObservableCollection _downloadingList; public ObservableCollection DownloadingList { - get => downloadingList; - set => SetProperty(ref downloadingList, value); + get => _downloadingList; + set => SetProperty(ref _downloadingList, value); } #endregion @@ -52,19 +51,16 @@ namespace DownKyi.ViewModels.DownloadManager #region 命令申明 // 暂停所有下载事件 - private DelegateCommand pauseAllDownloadingCommand; + private DelegateCommand? _pauseAllDownloadingCommand; - public DelegateCommand PauseAllDownloadingCommand => pauseAllDownloadingCommand ?? - (pauseAllDownloadingCommand = - new DelegateCommand( - ExecutePauseAllDownloadingCommand)); + public DelegateCommand PauseAllDownloadingCommand => _pauseAllDownloadingCommand ??= new DelegateCommand(ExecutePauseAllDownloadingCommand); /// /// 暂停所有下载事件 /// private void ExecutePauseAllDownloadingCommand() { - foreach (DownloadingItem downloading in downloadingList) + foreach (var downloading in _downloadingList) { switch (downloading.Downloading.DownloadStatus) { @@ -99,19 +95,16 @@ namespace DownKyi.ViewModels.DownloadManager } // 继续所有下载事件 - private DelegateCommand continueAllDownloadingCommand; + private DelegateCommand? _continueAllDownloadingCommand; - public DelegateCommand ContinueAllDownloadingCommand => continueAllDownloadingCommand ?? - (continueAllDownloadingCommand = - new DelegateCommand( - ExecuteContinueAllDownloadingCommand)); + public DelegateCommand ContinueAllDownloadingCommand => _continueAllDownloadingCommand ??= new DelegateCommand(ExecuteContinueAllDownloadingCommand); /// /// 继续所有下载事件 /// private void ExecuteContinueAllDownloadingCommand() { - foreach (DownloadingItem downloading in downloadingList) + foreach (var downloading in _downloadingList) { switch (downloading.Downloading.DownloadStatus) { @@ -150,10 +143,9 @@ namespace DownKyi.ViewModels.DownloadManager } // 删除所有下载事件 - private DelegateCommand? deleteAllDownloadingCommand; + private DelegateCommand? _deleteAllDownloadingCommand; - public DelegateCommand DeleteAllDownloadingCommand => deleteAllDownloadingCommand ??= - new DelegateCommand(ExecuteDeleteAllDownloadingCommand); + public DelegateCommand DeleteAllDownloadingCommand => _deleteAllDownloadingCommand ??= new DelegateCommand(ExecuteDeleteAllDownloadingCommand); /// /// 删除所有下载事件 @@ -188,7 +180,7 @@ namespace DownKyi.ViewModels.DownloadManager { await Task.Run(() => { - List list = DownloadingList.ToList(); + var list = DownloadingList.ToList(); foreach (var item in list) { if (item != null && item.DialogService == null) diff --git a/DownKyi/ViewModels/Friends/ViewFollowingViewModel.cs b/DownKyi/ViewModels/Friends/ViewFollowingViewModel.cs index 5b71aa8..a23dffa 100644 --- a/DownKyi/ViewModels/Friends/ViewFollowingViewModel.cs +++ b/DownKyi/ViewModels/Friends/ViewFollowingViewModel.cs @@ -24,7 +24,7 @@ public class ViewFollowingViewModel : ViewModelBase private long _mid = -1; // 每页数量,暂时在此写死,以后在设置中增加选项 - private readonly int NumberInPage = 20; + private const int NumberInPage = 20; #region 页面属性申明