From f91e23b81119c369a85a589c97dc6236ddf5b013 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Soucy Date: Fri, 24 May 2024 10:45:09 -0400 Subject: [PATCH] feat: update android wallet service --- .gitignore | 4 + .../ForcedUpdates/UpdateRequiredService.cs | 8 +- .../ApplicationTemplate.Mobile.csproj | 19 ++- .../Configuration/ApiConfiguration.cs | 14 --- ...ApplicationTemplate.Shared.Views.projitems | 1 + .../ViewServicesConfiguration.cs | 9 ++ .../RemoteConfigRepository.Android.cs | 114 ++++++++++++++++++ 7 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 src/app/ApplicationTemplate.Shared.Views/RemoteConfigRepository.Android.cs diff --git a/.gitignore b/.gitignore index 6272ab935..73dcc4f58 100644 --- a/.gitignore +++ b/.gitignore @@ -325,3 +325,7 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ + +# Firebase +*google-services.json +*GoogleService-Info.plist diff --git a/src/app/ApplicationTemplate.Business/ForcedUpdates/UpdateRequiredService.cs b/src/app/ApplicationTemplate.Business/ForcedUpdates/UpdateRequiredService.cs index 5882edd60..f2c23db26 100644 --- a/src/app/ApplicationTemplate.Business/ForcedUpdates/UpdateRequiredService.cs +++ b/src/app/ApplicationTemplate.Business/ForcedUpdates/UpdateRequiredService.cs @@ -18,7 +18,13 @@ public sealed class UpdateRequiredService : IUpdateRequiredService, IDisposable public UpdateRequiredService(IMinimumVersionReposiory minimumVersionReposiory) { _subscription = minimumVersionReposiory.MinimumVersionObservable - .Subscribe(_ => UpdateRequired?.Invoke(this, EventArgs.Empty)); + .Subscribe(version => + { + if (version > new Version("1.1.0")) + { + UpdateRequired?.Invoke(this, EventArgs.Empty); + } + }); } /// diff --git a/src/app/ApplicationTemplate.Mobile/ApplicationTemplate.Mobile.csproj b/src/app/ApplicationTemplate.Mobile/ApplicationTemplate.Mobile.csproj index 6678ad4b6..63c14fb79 100644 --- a/src/app/ApplicationTemplate.Mobile/ApplicationTemplate.Mobile.csproj +++ b/src/app/ApplicationTemplate.Mobile/ApplicationTemplate.Mobile.csproj @@ -15,6 +15,9 @@ True partial + + + @@ -100,7 +103,15 @@ - + + + + + + + + google-services.json + @@ -153,6 +164,12 @@ true + + + + GoogleService-Info.plist + + diff --git a/src/app/ApplicationTemplate.Presentation/Configuration/ApiConfiguration.cs b/src/app/ApplicationTemplate.Presentation/Configuration/ApiConfiguration.cs index 1bab32ae7..0f6224574 100644 --- a/src/app/ApplicationTemplate.Presentation/Configuration/ApiConfiguration.cs +++ b/src/app/ApplicationTemplate.Presentation/Configuration/ApiConfiguration.cs @@ -42,8 +42,6 @@ public static IServiceCollection AddApi(this IServiceCollection services, IConfi .AddAuthentication() .AddPosts(configuration) .AddUserProfile() - .AddMinimumVersion() - .AddKillSwitch() .AddDadJokes(configuration); return services; @@ -55,18 +53,6 @@ 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 AddKillSwitch(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.Shared.Views/ApplicationTemplate.Shared.Views.projitems b/src/app/ApplicationTemplate.Shared.Views/ApplicationTemplate.Shared.Views.projitems index 059e75fd1..80a485874 100644 --- a/src/app/ApplicationTemplate.Shared.Views/ApplicationTemplate.Shared.Views.projitems +++ b/src/app/ApplicationTemplate.Shared.Views/ApplicationTemplate.Shared.Views.projitems @@ -118,6 +118,7 @@ + Shell.xaml diff --git a/src/app/ApplicationTemplate.Shared.Views/Configuration/ViewServicesConfiguration.cs b/src/app/ApplicationTemplate.Shared.Views/Configuration/ViewServicesConfiguration.cs index b6d91d4d6..ca0c1ec18 100644 --- a/src/app/ApplicationTemplate.Shared.Views/Configuration/ViewServicesConfiguration.cs +++ b/src/app/ApplicationTemplate.Shared.Views/Configuration/ViewServicesConfiguration.cs @@ -1,4 +1,5 @@ using System.Reactive.Concurrency; +using ApplicationTemplate.DataAccess; using Chinook.DynamicMvvm; using MessageDialogService; using Microsoft.Extensions.DependencyInjection; @@ -34,6 +35,14 @@ public static IServiceCollection AddViewServices(this IServiceCollection service .AddSingleton() .AddSingleton() .AddSingleton() +#if __ANDROID__ + .AddSingleton() + .AddSingleton(s => s.GetRequiredService()) + .AddSingleton(s => s.GetRequiredService()) +#else + .AddSingleton() + .AddSingleton() +#endif .AddMessageDialog(); } diff --git a/src/app/ApplicationTemplate.Shared.Views/RemoteConfigRepository.Android.cs b/src/app/ApplicationTemplate.Shared.Views/RemoteConfigRepository.Android.cs new file mode 100644 index 000000000..3f02c45cf --- /dev/null +++ b/src/app/ApplicationTemplate.Shared.Views/RemoteConfigRepository.Android.cs @@ -0,0 +1,114 @@ +#if __ANDROID__ +using System; +using System.Reactive.Subjects; +using ApplicationTemplate.DataAccess; +using Firebase.RemoteConfig; + +namespace ApplicationTemplate.Views; + +/// +/// RemoteConfigRepository is a repository for Firebase Remote Config. +/// +public sealed class RemoteConfigRepository : IKillSwitchRepository, IMinimumVersionReposiory, IDisposable +{ + private Subject _killSwitchSubject = new Subject(); + private Subject _versionSubject = new Subject(); + + /// + /// Initializes a new instance of the class. + /// + public RemoteConfigRepository() + { + FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.Instance; + FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder() + .SetMinimumFetchIntervalInSeconds(3600) + .Build(); + mFirebaseRemoteConfig.SetConfigSettingsAsync(configSettings); + + FetchRemoteConfig(); + ListenForRealTimeChanges(); + } + + private void FetchRemoteConfig() + { + FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.Instance; + mFirebaseRemoteConfig.FetchAndActivate() + .AddOnCompleteListener(new FetchCompleteListener(this)); + } + + private void ListenForRealTimeChanges() + { + FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.Instance; + + mFirebaseRemoteConfig.AddOnConfigUpdateListener(new ConfigUpdateListener(this)); + } + + /// + public IObservable MinimumVersionObservable => _versionSubject; + + /// + public void CheckMinimumVersion() + { + throw new NotImplementedException(); + } + + /// + public IObservable ObserveKillSwitchActivation() + { + return _killSwitchSubject; + } + + /// + public void Dispose() + { + _killSwitchSubject.Dispose(); + _versionSubject.Dispose(); + } + + private sealed class FetchCompleteListener : Java.Lang.Object, Android.Gms.Tasks.IOnCompleteListener + { + private readonly RemoteConfigRepository _repository; + + public FetchCompleteListener(RemoteConfigRepository repository) + { + _repository = repository; + } + + public void OnComplete(Android.Gms.Tasks.Task task) + { + if (task.IsSuccessful) + { + _repository._killSwitchSubject.OnNext(FirebaseRemoteConfig.Instance.GetBoolean("kill_switch")); + _repository._versionSubject.OnNext(new Version(FirebaseRemoteConfig.Instance.GetString("minimum_version"))); + } + } + } + + private sealed class ConfigUpdateListener : Java.Lang.Object, IConfigUpdateListener + { + private readonly RemoteConfigRepository _repository; + + public ConfigUpdateListener(RemoteConfigRepository repository) + { + _repository = repository; + } + + public void OnError(FirebaseRemoteConfigException p0) + { + throw new NotImplementedException(); + } + + public void OnUpdate(ConfigUpdate p0) + { + var instance = FirebaseRemoteConfig.Instance; + + instance.FetchAndActivate(); + var isKillSwitchActivated = FirebaseRemoteConfig.Instance.GetBoolean("kill_switch"); + var minimumVersion = new Version(FirebaseRemoteConfig.Instance.GetString("minimum_version")); + + _repository._killSwitchSubject.OnNext(isKillSwitchActivated); + _repository._versionSubject.OnNext(minimumVersion); + } + } +} +#endif