diff --git a/Maui.Android.InAppUpdates.sln.DotSettings b/Maui.Android.InAppUpdates.sln.DotSettings
new file mode 100644
index 0000000..1b6cb1a
--- /dev/null
+++ b/Maui.Android.InAppUpdates.sln.DotSettings
@@ -0,0 +1,2 @@
+
+ True
\ No newline at end of file
diff --git a/README.md b/README.md
index 18d3230..65672f3 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ NuGet package that implementing Android In-App Updates for MAUI with debugging c
# Usage
- Add NuGet package to your project:
```xml
-
+
```
- Add the following to your `MauiProgram.cs` `CreateMauiApp` method:
```diff
diff --git a/sample/MainPage.xaml b/sample/MainPage.xaml
index 4d2b957..8ff79f2 100644
--- a/sample/MainPage.xaml
+++ b/sample/MainPage.xaml
@@ -18,6 +18,7 @@
+
diff --git a/sample/MainPage.xaml.cs b/sample/MainPage.xaml.cs
index 54cfe95..e09ee91 100644
--- a/sample/MainPage.xaml.cs
+++ b/sample/MainPage.xaml.cs
@@ -84,9 +84,21 @@ private void InstallFails()
private void CompleteUpdate()
{
#if ANDROID
- Internal.Handler.Options.CompleteUpdateAction(
- Platform.CurrentActivity!,
- Internal.Handler.AppUpdateManager!);
+ Internal.Handler.Options.CompleteUpdateAction();
+#endif
+ }
+
+ [RelayCommand]
+ private async Task Downloading()
+ {
+#if ANDROID
+ for (var i = 0; i < 100; i += 10)
+ {
+ Internal.Handler.Options.DownloadingAction(i);
+ await Task.Delay(TimeSpan.FromMilliseconds(250));
+ }
+#else
+ await Task.Delay(TimeSpan.FromMilliseconds(250));
#endif
}
diff --git a/src/libs/Directory.Build.props b/src/libs/Directory.Build.props
index 0c8ee6d..4f8df2a 100755
--- a/src/libs/Directory.Build.props
+++ b/src/libs/Directory.Build.props
@@ -9,7 +9,7 @@
- 0.9.1
+ 1.0.0
true
true
Oscore
diff --git a/src/libs/Maui.Android.InAppUpdates/AndroidInAppUpdatesOptions.cs b/src/libs/Maui.Android.InAppUpdates/AndroidInAppUpdatesOptions.cs
index 910847a..ca433fc 100644
--- a/src/libs/Maui.Android.InAppUpdates/AndroidInAppUpdatesOptions.cs
+++ b/src/libs/Maui.Android.InAppUpdates/AndroidInAppUpdatesOptions.cs
@@ -1,8 +1,3 @@
-#if ANDROID
-using Android.Content;
-using Xamarin.Google.Android.Play.Core.AppUpdate;
-#endif
-
namespace Maui.Android.InAppUpdates;
///
@@ -32,36 +27,32 @@ public class AndroidInAppUpdatesOptions
/// This action will be triggered when the app is updated.
/// Default action will show the toast with english text.
///
- public Action AppUpdatedAction { get; set; } = static context =>
+ public Action AppUpdatedAction { get; set; } = static () =>
Internal.DefaultUserInterface.ShowShortToast(
- context: context,
text: "App updated");
///
/// This action will be triggered when the update is cancelled.
/// Default action will show the toast with english text.
///
- public Action UpdateCancelledAction { get; set; } = static context =>
+ public Action UpdateCancelledAction { get; set; } = static () =>
Internal.DefaultUserInterface.ShowShortToast(
- context: context,
text: "In app update cancelled");
///
/// This action will be triggered when the update is failed.
/// Default action will show the toast with english text.
///
- public Action UpdateFailedAction { get; set; } = static context =>
+ public Action UpdateFailedAction { get; set; } = static () =>
Internal.DefaultUserInterface.ShowShortToast(
- context: context,
text: "In app update failed");
///
/// This action will be triggered when the download is failed.
/// Default action will show the toast with english text.
///
- public Action DownloadFailedAction { get; set; } = static context =>
+ public Action DownloadFailedAction { get; set; } = static () =>
Internal.DefaultUserInterface.ShowShortToast(
- context: context,
text: "Update download failed.");
///
@@ -69,22 +60,19 @@ public class AndroidInAppUpdatesOptions
/// Second value is the percentage of the download.
/// Default action will show the toast with english text.
///
- public Action DownloadingAction { get; set; } = static (context, percents) =>
+ public Action DownloadingAction { get; set; } = static percents =>
Internal.DefaultUserInterface.ShowShortToast(
- context: context,
text: $"Downloaded {percents}%");
///
/// This action will be triggered when the update is completed.
/// Default action will show the alert dialog to complete the update.
///
- public Action CompleteUpdateAction { get; set; } = static (context, appUpdateManager) =>
- Internal.DefaultUserInterface.ShowAlertToCompleteUpdate(
- context: context,
- appUpdateManager: appUpdateManager,
- title: "Download completed",
- message: "Update is ready to be installed.", // "Application successfully updated! You need to restart the app in order to use this new features"
- positiveButton: "Perform update"); // "Restart"
+ public Action CompleteUpdateAction { get; set; } = static () =>
+ Internal.DefaultUserInterface.ShowSnackbar(
+ text: "An update has just been downloaded.",
+ actionText: "RESTART",
+ clickHandler: static _ => Internal.Handler.AppUpdateManager?.CompleteUpdate());
#endif
///
diff --git a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/AppUpdateSuccessListener.cs b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/AppUpdateSuccessListener.cs
index 230eefc..a50bdfc 100644
--- a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/AppUpdateSuccessListener.cs
+++ b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/AppUpdateSuccessListener.cs
@@ -45,9 +45,7 @@ public void OnSuccess(Java.Lang.Object p0)
case UpdateAvailability.UpdateAvailable or UpdateAvailability.DeveloperTriggeredUpdateInProgress when
isFlexibleUpdatesAllowed:
{
- InstallStateUpdatedListener ??= new InstallStateUpdatedListener(
- context: activity,
- appUpdateManager: appUpdateManager);
+ InstallStateUpdatedListener ??= new InstallStateUpdatedListener();
appUpdateManager.RegisterListener(InstallStateUpdatedListener);
_ = appUpdateManager.StartUpdateFlowForResult(
diff --git a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs
index 3f02d1b..ff9ead8 100644
--- a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs
+++ b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/DefaultUserInterface.cs
@@ -1,46 +1,47 @@
-using Android.App;
-using Android.Content;
+using Android.Views;
using Android.Widget;
-using Xamarin.Google.Android.Play.Core.AppUpdate;
+using Google.Android.Material.Snackbar;
namespace Maui.Android.InAppUpdates.Internal;
public static class DefaultUserInterface
{
///
- /// This method will show the alert dialog to complete the update.
+ /// Displays a short duration toast message at the center of the screen.
///
- ///
- ///
- public static void ShowAlertToCompleteUpdate(
- Context context,
- IAppUpdateManager appUpdateManager,
- string title,
- string message,
- string positiveButton)
+ /// The text to be displayed in the toast message.
+ public static void ShowShortToast(
+ string text)
{
- if (new AlertDialog.Builder(context).Create() is not {} alert)
+ Toast.MakeText(
+ context: Platform.AppContext,
+ text: text,
+ duration: ToastLength.Short)?.Show();
+ }
+
+ ///
+ /// Displays a snackbar with an action to complete the app update process.
+ ///
+ /// The text to display on the snackbar.
+ /// The text for the action button.
+ /// The handler for the action button.
+ 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)
{
return;
}
- alert.SetTitle(title);
- alert.SetMessage(message);
- alert.SetButton((int) DialogButtonType.Positive, positiveButton, (_, _) =>
- {
- appUpdateManager.CompleteUpdate();
- // You can start your activityonresult method when update is not available when using immediate update when testing with fakeappupdate manager
- //activity.StartActivityForResult(intent, 400);
- });
- alert.SetCancelable(false);
- alert.Show();
- }
-
- public static void ShowShortToast(Context context, string text)
- {
- Toast.MakeText(
- context: context,
- text: text,
- duration: ToastLength.Short)?.Show();
+ snackbar.SetAction(
+ text: actionText,
+ clickHandler: clickHandler);
+ snackbar.Show();
}
}
\ No newline at end of file
diff --git a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/Handler.cs b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/Handler.cs
index 1df9507..f5fa188 100644
--- a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/Handler.cs
+++ b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/Handler.cs
@@ -89,15 +89,15 @@ public static void HandleActivityResult(
switch (resultCode)
{
case Result.Ok:
- Options.AppUpdatedAction(activity);
+ Options.AppUpdatedAction();
break;
case Result.Canceled:
- Options.UpdateCancelledAction(activity);
+ Options.UpdateCancelledAction();
break;
case (Result)ActivityResult.ResultInAppUpdateFailed:
- Options.UpdateFailedAction(activity);
+ Options.UpdateFailedAction();
break;
}
}
diff --git a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/InstallStateUpdatedListener.cs b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/InstallStateUpdatedListener.cs
index 105dde8..16aaa14 100644
--- a/src/libs/Maui.Android.InAppUpdates/Platforms/Android/InstallStateUpdatedListener.cs
+++ b/src/libs/Maui.Android.InAppUpdates/Platforms/Android/InstallStateUpdatedListener.cs
@@ -1,5 +1,3 @@
-using Android.Content;
-using Xamarin.Google.Android.Play.Core.AppUpdate;
using Xamarin.Google.Android.Play.Core.Install;
using Xamarin.Google.Android.Play.Core.Install.Model;
using Object = Java.Lang.Object;
@@ -9,9 +7,7 @@ namespace Maui.Android.InAppUpdates.Internal;
///
/// Listener to track request state updates.
///
-public class InstallStateUpdatedListener(
- Context context,
- IAppUpdateManager appUpdateManager)
+public class InstallStateUpdatedListener
: Object, IInstallStateUpdatedListener
{
///
@@ -43,16 +39,16 @@ public void OnStateUpdate(InstallState state)
var percents = Math.Round(
100.0 * bytesDownloaded / totalBytesToDownload);
- Handler.Options.DownloadingAction(context, percents);
+ Handler.Options.DownloadingAction(percents);
break;
}
case InstallStatus.Downloaded:
- Handler.Options.CompleteUpdateAction(context, appUpdateManager);
+ Handler.Options.CompleteUpdateAction();
break;
case InstallStatus.Failed:
- Handler.Options.DownloadFailedAction(context);
+ Handler.Options.DownloadFailedAction();
break;
}
}