From fab11698dcf85ef22018f1ce2f2656e21ad9bf5f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 24 Dec 2022 17:24:56 +0100 Subject: [PATCH 1/4] Update dependencies, bump to C# 11 --- src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj | 2 +- src/AmbientSounds/AmbientSounds.csproj | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj b/src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj index 0e449023b..93fb1efb0 100644 --- a/src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj +++ b/src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj @@ -18,7 +18,7 @@ {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} true false - 10.0 + 11.0 false diff --git a/src/AmbientSounds/AmbientSounds.csproj b/src/AmbientSounds/AmbientSounds.csproj index 2fdc3eed3..c60fb394d 100644 --- a/src/AmbientSounds/AmbientSounds.csproj +++ b/src/AmbientSounds/AmbientSounds.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 10.0 + 11.0 enable @@ -38,8 +38,8 @@ - - + + From 28a83712be73b97e9a4396bd5f909db9364fcce6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 24 Dec 2022 17:25:08 +0100 Subject: [PATCH 2/4] Use list patterns where appropriate --- src/AmbientSounds/Constants/IapConstants.cs | 15 ++++++--------- src/AmbientSounds/Models/Video.cs | 5 +++-- .../ViewModels/SoundListViewModel.cs | 15 ++++++--------- src/AmbientSounds/ViewModels/SoundViewModel.cs | 4 ++-- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/AmbientSounds/Constants/IapConstants.cs b/src/AmbientSounds/Constants/IapConstants.cs index 338d7fda1..7046be27e 100644 --- a/src/AmbientSounds/Constants/IapConstants.cs +++ b/src/AmbientSounds/Constants/IapConstants.cs @@ -40,17 +40,14 @@ public static (string, int) SplitIdAndVersion(this string iapId) return (string.Empty, 0); } - var split = iapId.Split('_'); - if (split.Length <= 1) + if (iapId.Split('_') is [string id, string version, ..]) { - return (iapId, 0); - } - else - { - return int.TryParse(split[1], out int result) - ? (split[0], result) - : (split[0], 0); + return int.TryParse(version, out int result) + ? (id, result) + : (id, 0); } + + return (iapId, 0); } } } diff --git a/src/AmbientSounds/Models/Video.cs b/src/AmbientSounds/Models/Video.cs index 5b14553ca..cfc61907d 100644 --- a/src/AmbientSounds/Models/Video.cs +++ b/src/AmbientSounds/Models/Video.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using System; +using System.Text.Json.Serialization; namespace AmbientSounds.Models { @@ -63,6 +64,6 @@ public class Video /// Ids used to identify the IAPs /// associated with this video. /// - public string[] IapIds { get; set; } = new string[0]; + public string[] IapIds { get; set; } = Array.Empty(); } } diff --git a/src/AmbientSounds/ViewModels/SoundListViewModel.cs b/src/AmbientSounds/ViewModels/SoundListViewModel.cs index 5d07f38d2..d7b34911a 100644 --- a/src/AmbientSounds/ViewModels/SoundListViewModel.cs +++ b/src/AmbientSounds/ViewModels/SoundListViewModel.cs @@ -184,17 +184,14 @@ private void OnSoundCollectionChanged(object sender, NotifyCollectionChangedEven { _reorderedOldIndex = e.OldStartingIndex; } - else if (e.Action == NotifyCollectionChangedAction.Add && !_isAdding) + else if (e is { Action: NotifyCollectionChangedAction.Add, NewItems: [SoundViewModel svm, ..] } && !_isAdding) { - if (e.NewItems.Count > 0 && e.NewItems[0] is SoundViewModel svm) - { - _ = _soundService.UpdatePositionsAsync( - svm.Id, - _reorderedOldIndex, - e.NewStartingIndex).ConfigureAwait(false); + _ = _soundService.UpdatePositionsAsync( + svm.Id, + _reorderedOldIndex, + e.NewStartingIndex).ConfigureAwait(false); - _telemetry.TrackEvent(TelemetryConstants.SoundReordered); - } + _telemetry.TrackEvent(TelemetryConstants.SoundReordered); } } diff --git a/src/AmbientSounds/ViewModels/SoundViewModel.cs b/src/AmbientSounds/ViewModels/SoundViewModel.cs index 4f8d837ef..fc6722263 100644 --- a/src/AmbientSounds/ViewModels/SoundViewModel.cs +++ b/src/AmbientSounds/ViewModels/SoundViewModel.cs @@ -148,11 +148,11 @@ public bool PlusBadgeVisible public bool HasSecondImage => IsMix && _sound.ImagePaths.Length == 2; - public string? SecondImagePath => _sound.ImagePaths.Length >= 2 ? _sound.ImagePaths[1] : "http://localhost:8000"; + public string? SecondImagePath => _sound.ImagePaths is [_, var path, ..] ? path : "http://localhost:8000"; public bool HasThirdImage => IsMix && _sound.ImagePaths.Length == 3; - public string? ThirdImagePath => _sound.ImagePaths.Length >= 3 ? _sound.ImagePaths[2] : "http://localhost:8000"; + public string? ThirdImagePath => _sound.ImagePaths is [_, _, var path, ..] ? path : "http://localhost:8000"; /// /// The path for the image to display for the current sound. From 6c07620bf106c3562dd4960e149f2ffe9c5ffa6a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 25 Dec 2022 10:58:49 +0100 Subject: [PATCH 3/4] Bump test project to .NET 6 --- AmbientSounds.Tests/AmbientSounds.Tests.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/AmbientSounds.Tests/AmbientSounds.Tests.csproj b/AmbientSounds.Tests/AmbientSounds.Tests.csproj index bd514f808..49ef3d265 100644 --- a/AmbientSounds.Tests/AmbientSounds.Tests.csproj +++ b/AmbientSounds.Tests/AmbientSounds.Tests.csproj @@ -1,8 +1,7 @@ - netcoreapp3.1 - + net6.0 false From ccbc5ef6cef4c0dbb09df8b64343a49a03f3bc7b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 25 Dec 2022 10:59:01 +0100 Subject: [PATCH 4/4] Centralize C# language version in shared .props --- Directory.Build.props | 21 +++++++++++++++++++ .../AmbientSounds.Uwp.csproj | 1 - .../Controls/ObservableUserControl.cs | 8 ++++--- src/AmbientSounds/AmbientSounds.csproj | 1 - .../ViewModels/SoundViewModel.cs | 4 ++++ 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 Directory.Build.props diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 000000000..89bab368c --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,21 @@ + + + 11.0 + + + 7 + + + 7-all + + + strict + + \ No newline at end of file diff --git a/src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj b/src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj index 93fb1efb0..81259a14f 100644 --- a/src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj +++ b/src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj @@ -18,7 +18,6 @@ {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} true false - 11.0 false diff --git a/src/AmbientSounds.Uwp/Controls/ObservableUserControl.cs b/src/AmbientSounds.Uwp/Controls/ObservableUserControl.cs index fd65e5bbf..64d2a2c2f 100644 --- a/src/AmbientSounds.Uwp/Controls/ObservableUserControl.cs +++ b/src/AmbientSounds.Uwp/Controls/ObservableUserControl.cs @@ -2,22 +2,24 @@ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +#nullable enable + namespace AmbientSounds.Controls { // Source: https://gist.github.com/dpaulino/2e988a78fee6d99198d306681b234437 public abstract class ObservableUserControl : UserControl, INotifyPropertyChanged { - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; protected void SetValueDp(DependencyProperty property, object value, - [System.Runtime.CompilerServices.CallerMemberName] string p = null) + [System.Runtime.CompilerServices.CallerMemberName] string? p = null) { SetValue(property, value); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(p)); } - protected void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string p = null) + protected void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string? p = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(p)); } diff --git a/src/AmbientSounds/AmbientSounds.csproj b/src/AmbientSounds/AmbientSounds.csproj index c60fb394d..49bcfbd15 100644 --- a/src/AmbientSounds/AmbientSounds.csproj +++ b/src/AmbientSounds/AmbientSounds.csproj @@ -2,7 +2,6 @@ netstandard2.0 - 11.0 enable diff --git a/src/AmbientSounds/ViewModels/SoundViewModel.cs b/src/AmbientSounds/ViewModels/SoundViewModel.cs index fc6722263..99fbda59a 100644 --- a/src/AmbientSounds/ViewModels/SoundViewModel.cs +++ b/src/AmbientSounds/ViewModels/SoundViewModel.cs @@ -117,7 +117,9 @@ public bool PlusBadgeVisible else { // backwards compatibility +#pragma warning disable CS0618 return _sound.IsPremium && _sound.IapId == IapConstants.MsStoreAmbiePlusId; +#pragma warning restore CS0618 } } } @@ -303,7 +305,9 @@ private async Task PlayAsync() var owned = _sound.IapIds.Count > 0 ? await _iapService.IsAnyOwnedAsync(_sound.IapIds) +#pragma warning disable CS0618 : await _iapService.IsOwnedAsync(_sound.IapId); // backwards compatibility +#pragma warning restore CS0618 if (!owned) {