Skip to content

Commit

Permalink
feat: update android wallet service
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Antoine-Soucy committed May 24, 2024
1 parent 7da83f2 commit f91e23b
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,7 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/

# Firebase
*google-services.json
*GoogleService-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<PublishTrimmed>True</PublishTrimmed>
<TrimMode>partial</TrimMode>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Android\RemoteConfigRepository.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Chinook.BackButtonManager.Uno.WinUI" Version="2.1.0" />
<PackageReference Include="Chinook.DataLoader.Uno.WinUI" Version="2.0.0" />
Expand Down Expand Up @@ -100,7 +103,15 @@
<ItemGroup>
<PackageReference Include="Uno.UniversalImageLoader" Version="1.9.36" />
<PackageReference Include="Mono.AotProfiler.Android" Version="7.0.0" />
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="1.9.23.1" />
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="1.9.22.1" />
<PackageReference Include="Xamarin.Firebase.Config" Version="121.6.1.1" />
</ItemGroup>

<!-- Android Firebase configuration. -->
<ItemGroup>
<GoogleServicesJson Include="Android\google-services.json">
<Link>google-services.json</Link>
</GoogleServicesJson>
</ItemGroup>
<ItemGroup>
<AndroidAotProfile Include="custom.aprof" />
Expand Down Expand Up @@ -153,6 +164,12 @@
<!-- Workaround for clang++ error on iOS simulator on ARM base macOS system. See "https://github.com/dotnet/maui/issues/16778#issuecomment-1683343255" for more detail. -->
<ForceSimulatorX64ArchitectureInIDE>true</ForceSimulatorX64ArchitectureInIDE>
</PropertyGroup>
<!-- iOS Firebase configuration. -->
<ItemGroup>
<BundleResource Include="iOS\GoogleService-Info.plist">
<Link>GoogleService-Info.plist</Link>
</BundleResource>
</ItemGroup>
<Choose>
<When Condition="'$(Configuration)'=='Debug'">
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public static IServiceCollection AddApi(this IServiceCollection services, IConfi
.AddAuthentication()
.AddPosts(configuration)
.AddUserProfile()
.AddMinimumVersion()
.AddKillSwitch()
.AddDadJokes(configuration);

return services;
Expand All @@ -55,18 +53,6 @@ private static IServiceCollection AddUserProfile(this IServiceCollection service
return services.AddSingleton<IUserProfileRepository, UserProfileRepositoryMock>();
}

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<IMinimumVersionReposiory, MinimumVersionRepositoryMock>();
}

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<IKillSwitchRepository, KillSwitchRepositoryMock>();
}

private static IServiceCollection AddAuthentication(this IServiceCollection services)
{
// This one doesn't have an actual remote API yet. It's always a mock implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Helpers\DependencyObjectExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\FrameworkElementExtension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ObservableExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RemoteConfigRepository.Android.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Shell.xaml.cs">
<DependentUpon>Shell.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reactive.Concurrency;
using ApplicationTemplate.DataAccess;
using Chinook.DynamicMvvm;
using MessageDialogService;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -34,6 +35,14 @@ public static IServiceCollection AddViewServices(this IServiceCollection service
.AddSingleton<IEmailService, EmailService>()
.AddSingleton<IMemoryProvider, MemoryProvider>()
.AddSingleton<IReviewPrompter, ReviewPrompter>()
#if __ANDROID__
.AddSingleton<RemoteConfigRepository>()
.AddSingleton<IKillSwitchRepository>(s => s.GetRequiredService<RemoteConfigRepository>())
.AddSingleton<IMinimumVersionReposiory>(s => s.GetRequiredService<RemoteConfigRepository>())
#else
.AddSingleton<IKillSwitchRepository, KillSwitchRepositoryMock>()
.AddSingleton<IMinimumVersionReposiory, MinimumVersionRepositoryMock>()
#endif
.AddMessageDialog();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#if __ANDROID__
using System;
using System.Reactive.Subjects;
using ApplicationTemplate.DataAccess;
using Firebase.RemoteConfig;

namespace ApplicationTemplate.Views;

/// <summary>
/// RemoteConfigRepository is a repository for Firebase Remote Config.
/// </summary>
public sealed class RemoteConfigRepository : IKillSwitchRepository, IMinimumVersionReposiory, IDisposable
{
private Subject<bool> _killSwitchSubject = new Subject<bool>();
private Subject<Version> _versionSubject = new Subject<Version>();

/// <summary>
/// Initializes a new instance of the <see cref="RemoteConfigRepository"/> class.
/// </summary>
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));
}

/// <inheritdoc />
public IObservable<Version> MinimumVersionObservable => _versionSubject;

/// <inheritdoc />
public void CheckMinimumVersion()
{
throw new NotImplementedException();
}

/// <inheritdoc />
public IObservable<bool> ObserveKillSwitchActivation()
{
return _killSwitchSubject;
}

/// <inheritdoc />
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

0 comments on commit f91e23b

Please sign in to comment.