From 83457b3168e9c22a4c176516d6e670aaf933a25f Mon Sep 17 00:00:00 2001 From: Leonard Harris Date: Mon, 14 Jul 2025 23:13:59 +1200 Subject: [PATCH 1/6] Update Microsoft.Maui.Controls to version 9.0.82 Updated the `Microsoft.Maui.Controls` package version from a variable reference `$(MauiVersion)` to a specific version `9.0.82` in both the `Maui.Android.InAppUpdates.SampleApp.csproj` and `Maui.Android.InAppUpdates.csproj` files. --- sample/Maui.Android.InAppUpdates.SampleApp.csproj | 2 +- .../Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/Maui.Android.InAppUpdates.SampleApp.csproj b/sample/Maui.Android.InAppUpdates.SampleApp.csproj index 10cfe02..bbbee27 100644 --- a/sample/Maui.Android.InAppUpdates.SampleApp.csproj +++ b/sample/Maui.Android.InAppUpdates.SampleApp.csproj @@ -63,7 +63,7 @@ - + diff --git a/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj b/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj index 24b0f24..c78d4d3 100644 --- a/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj +++ b/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj @@ -27,7 +27,7 @@ - + From 984df6f203470508b398f14386df31f88ba2434a Mon Sep 17 00:00:00 2001 From: Leonard Harris Date: Wed, 16 Jul 2025 20:45:37 +1200 Subject: [PATCH 2/6] Update package versions in project files Updated `Microsoft.Extensions.Logging.Debug` to version `9.0.7` in `Maui.Android.InAppUpdates.SampleApp.csproj`. In `Maui.Android.InAppUpdates.csproj`, incremented versions of several Xamarin.AndroidX and Google Play App Update packages to: - `Xamarin.AndroidX.Activity.Ktx` to `1.10.1.2` - `Xamarin.AndroidX.Collection.Ktx` to `1.5.0.2` - `Xamarin.AndroidX.Fragment.Ktx` to `1.8.8` - `Xamarin.Google.Android.Play.App.Update.Ktx` to `2.1.0.15` --- sample/Maui.Android.InAppUpdates.SampleApp.csproj | 2 +- .../Maui.Android.InAppUpdates.csproj | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sample/Maui.Android.InAppUpdates.SampleApp.csproj b/sample/Maui.Android.InAppUpdates.SampleApp.csproj index bbbee27..71ce34f 100644 --- a/sample/Maui.Android.InAppUpdates.SampleApp.csproj +++ b/sample/Maui.Android.InAppUpdates.SampleApp.csproj @@ -64,7 +64,7 @@ - + diff --git a/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj b/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj index c78d4d3..623d995 100644 --- a/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj +++ b/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj @@ -31,10 +31,10 @@ - - - - + + + + From f45607b5955d4ba3c2a24284dbb93dc477960c43 Mon Sep 17 00:00:00 2001 From: Leonard Harris Date: Wed, 16 Jul 2025 21:44:47 +1200 Subject: [PATCH 3/6] Enhance error handling in toast and snackbar methods - Modified `ShowShortToast` to include null checks and exception handling. - Refactored `ShowSnackbar` to add fallback to toast and improved error handling for theme-related exceptions. - Introduced `FallbackToToastWithAction` and `HandleSnackbarFailure` for better organization and readability. - Added `IsThemeRelated` method to identify theme-related exceptions. --- .../Platforms/Android/DefaultUserInterface.cs | 117 +++++++++++++++--- 1 file changed, 99 insertions(+), 18 deletions(-) diff --git a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs index 908fc34..56f81e3 100644 --- a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs +++ b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs @@ -10,38 +10,119 @@ public static class DefaultUserInterface /// Displays a short duration toast message at the center of the screen. /// /// The text to be displayed in the toast message. - public static void ShowShortToast( - string text) + public static void ShowShortToast(string text) { - Toast.MakeText( - context: Platform.AppContext, - text: text, - duration: ToastLength.Short)?.Show(); + try + { + if (Platform.AppContext is null) + { + Handler.Options.DebugAction($"Cannot show toast - Platform.AppContext is null: {text}"); + return; + } + + Toast.MakeText( + context: Platform.AppContext, + text: text, + duration: ToastLength.Short)?.Show(); + } + catch (Exception ex) + { + Handler.Options.DebugAction($"Failed to show toast '{text}': {ex}"); + } } /// /// Displays a snackbar with an action to complete the app update process. + /// If snackbar fails due to theme incompatibility, falls back to toast message. /// /// The text to display on the snackbar. /// The text for the action button. - /// The handler for the action button. + /// The handler for the action button. Can be null if no action is needed. public static void ShowSnackbar( string text, string actionText, Action clickHandler) { - if (Platform.CurrentActivity?.Window?.DecorView is not {} view || - Snackbar.Make( - text: text, - duration: BaseTransientBottomBar.LengthIndefinite, - view: view) is not {} snackbar) + var fallbackMessage = $"{text} - {actionText}"; + + try + { + var view = Platform.CurrentActivity?.Window?.DecorView; + if (view is null) + { + FallbackToToastWithAction("Cannot show snackbar - no active view", fallbackMessage, clickHandler, null); + return; + } + + var snackbar = Snackbar.Make(view, text, BaseTransientBottomBar.LengthIndefinite); + if (snackbar is null) + { + FallbackToToastWithAction("Cannot create snackbar", fallbackMessage, clickHandler, view); + return; + } + + snackbar.SetAction(text: actionText, clickHandler: clickHandler); + snackbar.Show(); + } + catch (Exception ex) when (IsThemeRelated(ex)) + { + HandleSnackbarFailure(ex, "theme related", fallbackMessage, clickHandler, Platform.CurrentActivity?.Window?.DecorView); + } + catch (Exception ex) { - return; + HandleSnackbarFailure(ex, "general exception", fallbackMessage, null, null); } - - snackbar.SetAction( - text: actionText, - clickHandler: clickHandler); - snackbar.Show(); } + + private static void FallbackToToastWithAction( + string debugMessage, + string fallbackMessage, + Action? clickHandler, + global::Android.Views.View? fallbackView) + { + Handler.Options.DebugAction($"{debugMessage}, falling back to toast and auto-triggering action"); + ShowShortToast(fallbackMessage); + + // Auto-trigger the action since user can't click the snackbar + if (clickHandler is not null && fallbackView is not null) + { + try + { + clickHandler(fallbackView); + } + catch (Exception actionEx) + { + Handler.Options.DebugAction($"Error auto-executing snackbar action: {actionEx}"); + } + } + } + + private static void HandleSnackbarFailure( + Exception ex, + string errorType, + string fallbackMessage, + Action? clickHandler, + global::Android.Views.View? view) + { + Handler.Options.DebugAction($"Snackbar {errorType}: {ex}"); + ShowShortToast(fallbackMessage); + + // Only auto-trigger for theme-related exceptions where user interaction was expected + if (clickHandler is not null && view is not null) + { + try + { + clickHandler(view); + } + catch (Exception actionEx) + { + Handler.Options.DebugAction($"Error executing snackbar action: {actionEx}"); + } + } + } + + private static bool IsThemeRelated(Exception ex) => + ex is global::Android.Views.InflateException || + (ex is Java.Lang.UnsupportedOperationException && + ex.Message?.Contains("Failed to resolve attribute", StringComparison.Ordinal) == true); } \ No newline at end of file From d62d6a07b50740b1d00f90081b3d1383645728c7 Mon Sep 17 00:00:00 2001 From: Leonard Harris Date: Wed, 16 Jul 2025 21:46:44 +1200 Subject: [PATCH 4/6] Update NuGet properties and package references - Added a new "NuGet" PropertyGroup in `Maui.Android.InAppUpdates.csproj` for package ID, description, and tags. - Replaced hardcoded `Microsoft.Maui.Controls` version with variable `$(MauiVersion)` for improved version management. - Updated ItemGroup for package references while retaining AndroidX library references. --- .../Maui.Android.InAppUpdates.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj b/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj index 623d995..77c58e0 100644 --- a/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj +++ b/src/libs/Maui.Android.InAppUpdates/Maui.Android.InAppUpdates.csproj @@ -19,7 +19,7 @@ 10.0.17763.0 6.5 - + Oscore.$(AssemblyName) NuGet package that implementing Android In-App Updates for MAUI with debugging capabilities. @@ -27,7 +27,7 @@ - + From 4eaf63e0f29ff10ffa2ac1efbe24192d7183a274 Mon Sep 17 00:00:00 2001 From: Leonard Harris Date: Wed, 16 Jul 2025 21:47:48 +1200 Subject: [PATCH 5/6] Update ShowSnackbar documentation in DefaultUserInterface Modified the parameter documentation for the `ShowSnackbar` method. Removed the note about the `clickHandler` parameter being nullable and replaced it with a simpler description of its purpose. --- .../Platforms/Android/DefaultUserInterface.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs index 56f81e3..d4ac321 100644 --- a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs +++ b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs @@ -37,7 +37,7 @@ public static void ShowShortToast(string text) /// /// The text to display on the snackbar. /// The text for the action button. - /// The handler for the action button. Can be null if no action is needed. + /// The handler for the action button. public static void ShowSnackbar( string text, string actionText, From 3964ce06d4141a1ccbcd03e96e1055ba099b50eb Mon Sep 17 00:00:00 2001 From: Leonard Harris Date: Wed, 16 Jul 2025 21:54:14 +1200 Subject: [PATCH 6/6] Update Maui.Controls package version management Replaced hardcoded version number for the Microsoft.Maui.Controls package in the project file `Maui.Android.InAppUpdates.SampleApp.csproj` with a variable `$(MauiVersion)` for improved version management. --- sample/Maui.Android.InAppUpdates.SampleApp.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample/Maui.Android.InAppUpdates.SampleApp.csproj b/sample/Maui.Android.InAppUpdates.SampleApp.csproj index 71ce34f..8fd362e 100644 --- a/sample/Maui.Android.InAppUpdates.SampleApp.csproj +++ b/sample/Maui.Android.InAppUpdates.SampleApp.csproj @@ -63,7 +63,7 @@ - +