diff --git a/CHANGELOG.md b/CHANGELOG.md index f917e4ea0..9dcd18409 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) Prefix your items with `(Template)` if the change is about the template and not the resulting application. +## 3.3.X +- Added a forced update feature to the app. + ## 3.2.X - Added support for mouse back button navigation. - Set `fetchDepth` to 0 on canary merge CI to avoid `refusing to merge unrelated histories` errors. diff --git a/README.md b/README.md index df66fa5e5..61a3e86fc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Uno Platform Application Template +# Uno Platform Application Template [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](LICENSE) ![Version](https://img.shields.io/nuget/v/NV.Templates.Mobile?style=flat-square) ![Downloads](https://img.shields.io/nuget/dt/NV.Templates.Mobile?style=flat-square) diff --git a/doc/Architecture.md b/doc/Architecture.md index e7f34a8e0..14582d112 100644 --- a/doc/Architecture.md +++ b/doc/Architecture.md @@ -139,6 +139,10 @@ Business services are always declared using an interface and implemented in a se This application uses [DynamicData](https://github.com/reactivemarbles/DynamicData) to expose observable lists from business services. These can then be used in the presentation layer to create ViewModels that are automatically disposed when their associated items are removed from the list. +### Forced Update + +This application uses the [IUpdateRequiredService](/src/app/ApplicationTemplate.Business/ForcedUpdates/IUpdateRequiredService.cs) which exposes an event that allows you to know when you should redirect the user to a page that will lead him to the appstore where he can update the app. + ## Presentation ### MVVM - ViewModels diff --git a/doc/ForcedUpdate.md b/doc/ForcedUpdate.md new file mode 100644 index 000000000..e6f2cf04c --- /dev/null +++ b/doc/ForcedUpdate.md @@ -0,0 +1,30 @@ +# Forced Update + +The forced update feature is for when you want to force the user to update the app. +You could use this, for example, when the backend changes and you do not want the users to still use the old API. + +To force an update, we suscribe to the UpdateRequired Event from the UpdateRequiredservice in the coreStartup. + +```cs + private void SuscribeToRequiredUpdate(IServiceProvider services) + { + var updateRequiredService = services.GetRequiredService(); + + updateRequiredService.UpdateRequired += ForceUpdate; + + void ForceUpdate(object sender, EventArgs e) + { + var navigationController = services.GetRequiredService(); + + _ = Task.Run(async () => + { + await navigationController.NavigateAndClear(CancellationToken.None, () => new ForcedUpdatePageViewModel()); + }); + + updateRequiredService.UpdateRequired -= ForceUpdate; + updateRequiredService.Dispose(); + } + } +``` + +This will direct the user to a page from which they cannot navigate back. The page will contain a button that leads them to the appropriate page for updating the app, with the links defined in AppSettings. diff --git a/src/app/ApplicationTemplate.Access/ApiClients/MinimumVersion/IMinimumVersionReposiory.cs b/src/app/ApplicationTemplate.Access/ApiClients/MinimumVersion/IMinimumVersionReposiory.cs new file mode 100644 index 000000000..14ed0748c --- /dev/null +++ b/src/app/ApplicationTemplate.Access/ApiClients/MinimumVersion/IMinimumVersionReposiory.cs @@ -0,0 +1,19 @@ +using System; + +namespace ApplicationTemplate.DataAccess; + +/// +/// Gets the minimum version required to use the application. +/// +public interface IMinimumVersionReposiory : IDisposable +{ + /// + /// Checks the minimum required version. + /// + void CheckMinimumVersion(); + + /// + /// An observable that emits the minimum version required to use the application. + /// + IObservable MinimumVersionObservable { get; } +} diff --git a/src/app/ApplicationTemplate.Access/ApiClients/MinimumVersion/MinimumVersionRepositoryMock.cs b/src/app/ApplicationTemplate.Access/ApiClients/MinimumVersion/MinimumVersionRepositoryMock.cs new file mode 100644 index 000000000..019882de6 --- /dev/null +++ b/src/app/ApplicationTemplate.Access/ApiClients/MinimumVersion/MinimumVersionRepositoryMock.cs @@ -0,0 +1,27 @@ +using System; +using System.Reactive.Subjects; + +namespace ApplicationTemplate.DataAccess; + +/// +/// A mock implementation of the minimum version repository. Used for testing. +/// +public sealed class MinimumVersionRepositoryMock : IMinimumVersionReposiory +{ + private readonly Subject _minimumVersionSubject = new(); + + /// + public IObservable MinimumVersionObservable => _minimumVersionSubject; + + /// + public void CheckMinimumVersion() + { + _minimumVersionSubject.OnNext(new Version(1, 0, 0, 0)); + } + + /// + public void Dispose() + { + _minimumVersionSubject.Dispose(); + } +} diff --git a/src/app/ApplicationTemplate.Access/Configuration/ApplicationStoreUrisOptions.cs b/src/app/ApplicationTemplate.Access/Configuration/ApplicationStoreUrisOptions.cs new file mode 100644 index 000000000..f481238cc --- /dev/null +++ b/src/app/ApplicationTemplate.Access/Configuration/ApplicationStoreUrisOptions.cs @@ -0,0 +1,19 @@ +using System; + +namespace ApplicationTemplate; + +/// +/// Contains the configuration for the application store URLs. +/// +public sealed class ApplicationStoreUrisOptions +{ + /// + /// The URL to the application store for Android. + /// + public Uri Android { get; set; } + + /// + /// The URL to the application store for iOS. + /// + public Uri Ios { get; set; } +} diff --git a/src/app/ApplicationTemplate.Business/ForcedUpdates/IUpdateRequiredService.cs b/src/app/ApplicationTemplate.Business/ForcedUpdates/IUpdateRequiredService.cs new file mode 100644 index 000000000..c1ce75151 --- /dev/null +++ b/src/app/ApplicationTemplate.Business/ForcedUpdates/IUpdateRequiredService.cs @@ -0,0 +1,14 @@ +using System; + +namespace ApplicationTemplate.Business; + +/// +/// This service checks if the application is running the minimum required version. +/// +public interface IUpdateRequiredService : IDisposable +{ + /// + /// Event that is raised when the application needs to be updated. + /// + event EventHandler UpdateRequired; +} diff --git a/src/app/ApplicationTemplate.Business/ForcedUpdates/UpdateRequiredServiceMock.cs b/src/app/ApplicationTemplate.Business/ForcedUpdates/UpdateRequiredServiceMock.cs new file mode 100644 index 000000000..42fcbd93a --- /dev/null +++ b/src/app/ApplicationTemplate.Business/ForcedUpdates/UpdateRequiredServiceMock.cs @@ -0,0 +1,33 @@ +using System; +using System.Reactive.Linq; +using ApplicationTemplate.DataAccess; + +namespace ApplicationTemplate.Business; + +/// +/// Mock implementation of the . +/// +public sealed class UpdateRequiredServiceMock : IUpdateRequiredService +{ + private readonly IDisposable _subscription; + + /// + /// Initializes a new instance of the class. + /// + /// A repository that contains an observable we can use to update the app. + public UpdateRequiredServiceMock(IMinimumVersionReposiory minimumVersionReposiory) + { + _subscription = minimumVersionReposiory.MinimumVersionObservable + .Subscribe(_ => UpdateRequired?.Invoke(this, EventArgs.Empty)); + } + + /// + public event EventHandler UpdateRequired; + + /// + public void Dispose() + { + _subscription.Dispose(); + UpdateRequired = null; + } +} diff --git a/src/app/ApplicationTemplate.Presentation/Configuration/ApiConfiguration.cs b/src/app/ApplicationTemplate.Presentation/Configuration/ApiConfiguration.cs index 0f6224574..f4ba0ed10 100644 --- a/src/app/ApplicationTemplate.Presentation/Configuration/ApiConfiguration.cs +++ b/src/app/ApplicationTemplate.Presentation/Configuration/ApiConfiguration.cs @@ -42,6 +42,7 @@ public static IServiceCollection AddApi(this IServiceCollection services, IConfi .AddAuthentication() .AddPosts(configuration) .AddUserProfile() + .AddMinimumVersion() .AddDadJokes(configuration); return services; @@ -53,6 +54,12 @@ private static IServiceCollection AddUserProfile(this IServiceCollection service return services.AddSingleton(); } + private static IServiceCollection AddMinimumVersion(this IServiceCollection services) + { + // This one doesn't have an actual remote API yet. It's always a mock implementation. + return services.AddSingleton(); + } + private static IServiceCollection AddAuthentication(this IServiceCollection services) { // This one doesn't have an actual remote API yet. It's always a mock implementation. diff --git a/src/app/ApplicationTemplate.Presentation/Configuration/AppServicesConfiguration.cs b/src/app/ApplicationTemplate.Presentation/Configuration/AppServicesConfiguration.cs index 8b364541a..1d7bd55f4 100644 --- a/src/app/ApplicationTemplate.Presentation/Configuration/AppServicesConfiguration.cs +++ b/src/app/ApplicationTemplate.Presentation/Configuration/AppServicesConfiguration.cs @@ -31,6 +31,7 @@ public static IServiceCollection AddAppServices(this IServiceCollection services .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton(); } } diff --git a/src/app/ApplicationTemplate.Presentation/CoreStartup.cs b/src/app/ApplicationTemplate.Presentation/CoreStartup.cs index ac5e9a0fe..22a17f456 100644 --- a/src/app/ApplicationTemplate.Presentation/CoreStartup.cs +++ b/src/app/ApplicationTemplate.Presentation/CoreStartup.cs @@ -76,6 +76,7 @@ protected override async Task StartServices(IServiceProvider services, bool isFi NotifyUserOnSessionExpired(services); services.GetRequiredService().Start(); await ExecuteInitialNavigation(CancellationToken.None, services); + SuscribeToRequiredUpdate(services); } } @@ -199,6 +200,26 @@ private static void HandleUnhandledExceptions(IServiceProvider services) }; } + private void SuscribeToRequiredUpdate(IServiceProvider services) + { + var updateRequiredService = services.GetRequiredService(); + + updateRequiredService.UpdateRequired += ForceUpdate; + + void ForceUpdate(object sender, EventArgs e) + { + var navigationController = services.GetRequiredService(); + + _ = Task.Run(async () => + { + await navigationController.NavigateAndClear(CancellationToken.None, () => new ForcedUpdatePageViewModel()); + }); + + updateRequiredService.UpdateRequired -= ForceUpdate; + updateRequiredService.Dispose(); + } + } + /// /// Starts deactivating and reactivating ViewModels based on navigation. /// diff --git a/src/app/ApplicationTemplate.Presentation/Framework/Launcher/IAppStoreUriProvider.cs b/src/app/ApplicationTemplate.Presentation/Framework/Launcher/IAppStoreUriProvider.cs new file mode 100644 index 000000000..8581116d9 --- /dev/null +++ b/src/app/ApplicationTemplate.Presentation/Framework/Launcher/IAppStoreUriProvider.cs @@ -0,0 +1,15 @@ +using System; + +namespace ApplicationTemplate; + +/// +/// Provides the Uri to the app store for the current platform. +/// +public interface IAppStoreUriProvider +{ + /// + /// Gets the Uri to the app store for the current platform. + /// + /// The Uri to the app store for the current platform. + Uri GetAppStoreUri(); +} diff --git a/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/Navigation/NavigationDebuggerViewModel.cs b/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/Navigation/NavigationDebuggerViewModel.cs index eda3baf03..945bb8672 100644 --- a/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/Navigation/NavigationDebuggerViewModel.cs +++ b/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/Navigation/NavigationDebuggerViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using ApplicationTemplate.DataAccess; using Chinook.DynamicMvvm; using Chinook.SectionsNavigation; using Uno; @@ -39,4 +40,12 @@ public NavigationDebuggerViewModel() { await CoreStartup.ExecuteInitialNavigation(ct, ServiceProvider); }); + + /// + /// Gets a command that raises the event that triggers the navigation to the force update page. + /// + public IDynamicCommand NavigateToForceUpdatePage => this.GetCommand(() => + { + this.GetService().CheckMinimumVersion(); + }); } diff --git a/src/app/ApplicationTemplate.Presentation/ViewModels/ForcedUpdatePageViewModel.cs b/src/app/ApplicationTemplate.Presentation/ViewModels/ForcedUpdatePageViewModel.cs new file mode 100644 index 000000000..e99406259 --- /dev/null +++ b/src/app/ApplicationTemplate.Presentation/ViewModels/ForcedUpdatePageViewModel.cs @@ -0,0 +1,21 @@ +using Chinook.DynamicMvvm; + +namespace ApplicationTemplate.Presentation; + +/// +/// The ViewModel for the forced update page. +/// +public sealed class ForcedUpdatePageViewModel : ViewModel +{ + /// + /// Navigates to the App Store. + /// + public IDynamicCommand NavigateToStore => this.GetCommandFromTask(async ct => + { + var uriProvider = this.GetService(); + + var uri = uriProvider.GetAppStoreUri(); + + await this.GetService().Launch(uri); + }); +} diff --git a/src/app/ApplicationTemplate.Presentation/appsettings.json b/src/app/ApplicationTemplate.Presentation/appsettings.json index 53c609244..a361b2cfc 100644 --- a/src/app/ApplicationTemplate.Presentation/appsettings.json +++ b/src/app/ApplicationTemplate.Presentation/appsettings.json @@ -13,5 +13,10 @@ }, "Mock": { "IsMockEnabled": false + }, + "ApplicationStoreUrls": { + // TODO: Update the URLs with the actual URLs. + "IOS": "https://apps.apple.com/us/app/duolingo-language-lessons/id570060128", + "Android": "https://play.google.com/store/apps/details?id=com.duolingo", } } \ No newline at end of file diff --git a/src/app/ApplicationTemplate.Shared.Views/ApplicationTemplate.Shared.Views.projitems b/src/app/ApplicationTemplate.Shared.Views/ApplicationTemplate.Shared.Views.projitems index 4c6d4436b..7a85aea10 100644 --- a/src/app/ApplicationTemplate.Shared.Views/ApplicationTemplate.Shared.Views.projitems +++ b/src/app/ApplicationTemplate.Shared.Views/ApplicationTemplate.Shared.Views.projitems @@ -61,6 +61,9 @@ NavigationDebuggerView.xaml + + ForcedUpdatePage.xaml + Menu.xaml @@ -98,6 +101,7 @@ + @@ -235,6 +239,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/src/app/ApplicationTemplate.Shared.Views/Configuration/NavigationConfiguration.cs b/src/app/ApplicationTemplate.Shared.Views/Configuration/NavigationConfiguration.cs index a6377485a..b665552cb 100644 --- a/src/app/ApplicationTemplate.Shared.Views/Configuration/NavigationConfiguration.cs +++ b/src/app/ApplicationTemplate.Shared.Views/Configuration/NavigationConfiguration.cs @@ -42,6 +42,7 @@ public static IServiceCollection AddNavigation(this IServiceCollection services) { typeof(DadJokesFiltersPageViewModel), typeof(DadJokesFiltersPage) }, { typeof(SentEmailConfirmationPageViewModel), typeof(SentEmailConfirmationPage) }, { typeof(ResetPasswordPageViewModel), typeof(ResetPasswordPage) }, + { typeof(ForcedUpdatePageViewModel), typeof(ForcedUpdatePage) }, }; /// diff --git a/src/app/ApplicationTemplate.Shared.Views/Configuration/ViewServicesConfiguration.cs b/src/app/ApplicationTemplate.Shared.Views/Configuration/ViewServicesConfiguration.cs index 0cbdc53e4..b6d91d4d6 100644 --- a/src/app/ApplicationTemplate.Shared.Views/Configuration/ViewServicesConfiguration.cs +++ b/src/app/ApplicationTemplate.Shared.Views/Configuration/ViewServicesConfiguration.cs @@ -27,6 +27,7 @@ public static IServiceCollection AddViewServices(this IServiceCollection service .AddSingleton() .AddSingleton(s => new LauncherService(s.GetRequiredService())) .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton(s => new ExtendedSplashscreenController(Shell.Instance.DispatcherQueue)) .AddSingleton() diff --git a/src/app/ApplicationTemplate.Shared.Views/Content/Diagnostics/NavigationDebuggerView.xaml b/src/app/ApplicationTemplate.Shared.Views/Content/Diagnostics/NavigationDebuggerView.xaml index d185a241d..77421114c 100644 --- a/src/app/ApplicationTemplate.Shared.Views/Content/Diagnostics/NavigationDebuggerView.xaml +++ b/src/app/ApplicationTemplate.Shared.Views/Content/Diagnostics/NavigationDebuggerView.xaml @@ -102,6 +102,10 @@