From b70a32d31d8434d6355affb4e07f055f1f45ec06 Mon Sep 17 00:00:00 2001 From: Vladislav Antonyuk <33021114+VladislavAntonyuk@users.noreply.github.com> Date: Sun, 23 Jul 2023 20:46:18 +0300 Subject: [PATCH] BadgeCounter #807 (#1126) * BadgeCounter #807 * Rename to Badge * Update tests * Remove Xamarin.Android.ShortcutBadger dependency * Fix Tizen build * Add default badge provider, add nova * Fix SamsungBadgeProvider * SetProvider * Initialize array only once * `dotnet format` * Update SamsungBadgeProvider.cs * Update BadgeViewModel.cs * Update DefaultBadgeProvider.android.cs * Use `Lazy` to ensure thread safety * GetCount - Uncommented lines in the csproj file to address Android App installation failure. Toggle Home Screen Icon Badge Count - Added column and row spacing to improve layout in the BadgePage.xaml file. SetBadgeProvider method update - Renamed SetProvider method to SetBadgeProvider in the BadgeFactory.android.cs file. GetCount method implementation - Implemented GetCount method in the BadgeImplementation.android.cs, DefaultBadgeProvider.android.cs, BadgeImplementation.macios.cs, and BadgeImplementation.tizen.cs files. Added GetCount method to IBadge interface - Added GetCount method to the IBadge.shared.cs file. * feat: Add support for Samsung badge provider This commit adds support for the Samsung badge provider in the Android platform. It includes changes to the `SamsungBadgeProvider` class and the `DefaultBadgeProvider.android.cs` file. - Added a new static readonly string array `packageNameArray` in the `SamsungBadgeProvider` class. - Modified the `SetCount` method in the `SamsungBadgeProvider` class to use `packageNameArray` instead of directly passing a string array. - Added a new method `GetCount()` in the `SamsungBadgeProvider` class. - Renamed the method `IsSupported()` to `CanSetBadgeCounter()` in the `DefaultBadgeProvider.android.cs` file. - Added debug log statements for error handling scenarios in both classes. * Fix SamsungBadgeProvider.cs and BadgeTests.cs - Fix a typo in SamsungBadgeProvider.cs by changing "new[1]" to "new string[1]" - Add a new test method GetBadgeFailsOnNet() in BadgeTests.cs that tests the behavior of getting badge count on .NET platform - Modify the existing test method SetBadgeFailsOnNet() in BadgeTests.cs to throw NotSupportedException instead of NotImplementedException - Add a new method GetCount() in BadgeImplementationMock.cs that throws NotImplementedException * Fix build error Sorry Vlad - this was my fault! * Update CommunityToolkit.Maui.Sample.csproj * Update DefaultBadgeProvider.android.cs * Update BadgeImplementation.macios.cs * Update EssentialsGalleryViewModel.cs * Update BaseGalleryViewModel.cs * Update MainApplication.cs * Add null check * Remove `count` field * Update DefaultBadgeProvider.android.cs * Add additional text explaining Bade * Remove GetCount, use uint instead of int * fix tizen build * Update src/CommunityToolkit.Maui.Core/Essentials/Badge/BadgeImplementation.windows.cs Co-authored-by: Pedro Jesus * Update src/CommunityToolkit.Maui.Core/Essentials/Badge/BadgeImplementation.tizen.cs Co-authored-by: Pedro Jesus * Update src/CommunityToolkit.Maui.Core/Essentials/Badge/Android/BadgeFactory.android.cs Co-authored-by: Pedro Jesus * Update src/CommunityToolkit.Maui.Core/Essentials/Badge/Android/DefaultBadgeProvider.android.cs Co-authored-by: Pedro Jesus --------- Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Co-authored-by: Pedro Jesus --- .gitignore | 1 + .../AppShell.xaml.cs | 1 + .../CommunityToolkit.Maui.Sample.csproj | 6 +- .../MauiProgram.cs | 3 + .../Pages/Essentials/BadgePage.xaml | 66 +++++++++++++++ .../Pages/Essentials/BadgePage.xaml.cs | 11 +++ .../Platforms/Android/AndroidManifest.xml | 5 ++ .../Platforms/Android/MainApplication.cs | 4 + .../Platforms/Android/SamsungBadgeProvider.cs | 84 +++++++++++++++++++ .../ViewModels/Base/BaseGalleryViewModel.cs | 2 +- .../ViewModels/Essentials/BadgeViewModel.cs | 33 ++++++++ .../Essentials/EssentialsGalleryViewModel.cs | 1 + .../CommunityToolkit.Maui.Core.csproj | 1 + .../Badge/Android/BadgeFactory.android.cs | 55 ++++++++++++ .../Android/BadgeImplementation.android.cs | 12 +++ .../Android/DefaultBadgeProvider.android.cs | 57 +++++++++++++ .../Badge/Android/IBadgeProvider.android.cs | 12 +++ .../Essentials/Badge/Badge.shared.cs | 19 +++++ .../Badge/BadgeImplementation.macios.cs | 22 +++++ .../Badge/BadgeImplementation.net.cs | 11 +++ .../Badge/BadgeImplementation.tizen.cs | 31 +++++++ .../Badge/BadgeImplementation.windows.cs | 28 +++++++ .../Essentials/Badge/IBadge.shared.cs | 13 +++ .../Essentials/BadgeTests.cs | 25 ++++++ .../Mocks/BadgeImplementationMock.cs | 11 +++ 25 files changed, 512 insertions(+), 2 deletions(-) create mode 100644 samples/CommunityToolkit.Maui.Sample/Pages/Essentials/BadgePage.xaml create mode 100644 samples/CommunityToolkit.Maui.Sample/Pages/Essentials/BadgePage.xaml.cs create mode 100644 samples/CommunityToolkit.Maui.Sample/Platforms/Android/SamsungBadgeProvider.cs create mode 100644 samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/BadgeViewModel.cs create mode 100644 src/CommunityToolkit.Maui.Core/Essentials/Badge/Android/BadgeFactory.android.cs create mode 100644 src/CommunityToolkit.Maui.Core/Essentials/Badge/Android/BadgeImplementation.android.cs create mode 100644 src/CommunityToolkit.Maui.Core/Essentials/Badge/Android/DefaultBadgeProvider.android.cs create mode 100644 src/CommunityToolkit.Maui.Core/Essentials/Badge/Android/IBadgeProvider.android.cs create mode 100644 src/CommunityToolkit.Maui.Core/Essentials/Badge/Badge.shared.cs create mode 100644 src/CommunityToolkit.Maui.Core/Essentials/Badge/BadgeImplementation.macios.cs create mode 100644 src/CommunityToolkit.Maui.Core/Essentials/Badge/BadgeImplementation.net.cs create mode 100644 src/CommunityToolkit.Maui.Core/Essentials/Badge/BadgeImplementation.tizen.cs create mode 100644 src/CommunityToolkit.Maui.Core/Essentials/Badge/BadgeImplementation.windows.cs create mode 100644 src/CommunityToolkit.Maui.Core/Essentials/Badge/IBadge.shared.cs create mode 100644 src/CommunityToolkit.Maui.UnitTests/Essentials/BadgeTests.cs create mode 100644 src/CommunityToolkit.Maui.UnitTests/Mocks/BadgeImplementationMock.cs diff --git a/.gitignore b/.gitignore index 4740b3fbf..de8ab5cf3 100644 --- a/.gitignore +++ b/.gitignore @@ -263,3 +263,4 @@ paket-files/ # Visual Studio Code .vscode +/samples/workload-install.ps1 diff --git a/samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs b/samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs index c3388b1c4..b74c6dde7 100644 --- a/samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs +++ b/samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs @@ -83,6 +83,7 @@ public partial class AppShell : Shell CreateViewModelMapping(), // Add Essentials View Models + CreateViewModelMapping(), CreateViewModelMapping(), CreateViewModelMapping(), CreateViewModelMapping(), diff --git a/samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj b/samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj index 8a96fe7b9..12cc434cf 100644 --- a/samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj +++ b/samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj @@ -22,12 +22,15 @@ 1 + + + @@ -79,4 +82,5 @@ maccatalyst-arm64;maccatalyst-x64 + diff --git a/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs b/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs index e55258f84..2a3e8a48c 100644 --- a/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs +++ b/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs @@ -1,3 +1,4 @@ +using CommunityToolkit.Maui.ApplicationModel; using CommunityToolkit.Maui.Maps; using CommunityToolkit.Maui.Markup; using CommunityToolkit.Maui.Media; @@ -156,6 +157,7 @@ static void RegisterViewsAndViewModels(in IServiceCollection services) services.AddTransientWithShellRoute(); // Add Essentials Pages + ViewModels + services.AddTransientWithShellRoute(); services.AddTransientWithShellRoute(); services.AddTransientWithShellRoute(); services.AddTransientWithShellRoute(); @@ -199,6 +201,7 @@ static void RegisterEssentials(in IServiceCollection services) services.AddSingleton(DeviceInfo.Current); services.AddSingleton(FileSaver.Default); services.AddSingleton(FolderPicker.Default); + services.AddSingleton(Badge.Default); services.AddSingleton(SpeechToText.Default); services.AddSingleton(TextToSpeech.Default); } diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/BadgePage.xaml b/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/BadgePage.xaml new file mode 100644 index 000000000..24e980bc5 --- /dev/null +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/BadgePage.xaml @@ -0,0 +1,66 @@ + + + + + +