Skip to content

Commit 2d8513e

Browse files
feat: add forcedupdate firebase implementation
1 parent 3418ae5 commit 2d8513e

8 files changed

Lines changed: 206 additions & 17 deletions

File tree

src/app/ApplicationTemplate.Business/ForcedUpdates/UpdateRequiredService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ public sealed class UpdateRequiredService : IUpdateRequiredService, IDisposable
1818
public UpdateRequiredService(IMinimumVersionReposiory minimumVersionReposiory)
1919
{
2020
_subscription = minimumVersionReposiory.MinimumVersionObservable
21-
.Subscribe(_ => UpdateRequired?.Invoke(this, EventArgs.Empty));
21+
.Subscribe(version =>
22+
{
23+
if (version > new Version("1.1.0"))
24+
{
25+
UpdateRequired?.Invoke(this, EventArgs.Empty);
26+
}
27+
});
2228
}
2329

2430
/// <inheritdoc />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"project_info": {
3+
"project_number": "273937217541",
4+
"project_id": "unoapplicationtemplate",
5+
"storage_bucket": "unoapplicationtemplate.appspot.com"
6+
},
7+
"client": [
8+
{
9+
"client_info": {
10+
"mobilesdk_app_id": "1:273937217541:android:839280683beb019d9a846c",
11+
"android_client_info": {
12+
"package_name": "com.nventive.internal.applicationtemplate"
13+
}
14+
},
15+
"oauth_client": [],
16+
"api_key": [
17+
{
18+
"current_key": "AIzaSyC68jrNR8ZE-lK8KhaUh2T_s3Jr_giLLEs"
19+
}
20+
],
21+
"services": {
22+
"appinvite_service": {
23+
"other_platform_oauth_client": []
24+
}
25+
}
26+
}
27+
],
28+
"configuration_version": "1"
29+
}

src/app/ApplicationTemplate.Mobile/ApplicationTemplate.Mobile.csproj

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<LangVersion>12.0</LangVersion>
44
<TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
@@ -15,6 +15,9 @@
1515
<PublishTrimmed>True</PublishTrimmed>
1616
<TrimMode>partial</TrimMode>
1717
</PropertyGroup>
18+
<ItemGroup>
19+
<Compile Remove="Android\RemoteConfigRepository.cs" />
20+
</ItemGroup>
1821
<ItemGroup>
1922
<PackageReference Include="Chinook.BackButtonManager.Uno.WinUI" Version="2.1.0" />
2023
<PackageReference Include="Chinook.DataLoader.Uno.WinUI" Version="2.0.0" />
@@ -100,7 +103,25 @@
100103
<ItemGroup>
101104
<PackageReference Include="Uno.UniversalImageLoader" Version="1.9.36" />
102105
<PackageReference Include="Mono.AotProfiler.Android" Version="7.0.0" />
103-
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="1.9.0.1" />
106+
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="1.9.22.1" />
107+
<PackageReference Include="Xamarin.Firebase.Config" Version="121.6.1.1" />
108+
109+
<!-- These packages are needed because of this issue https://github.com/xamarin/AndroidX/issues/764 that xamarin.firebase.Messaging might have introduced -->
110+
<!--<PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.8.2.1" />
111+
<PackageReference Include="Xamarin.AndroidX.Collection" Version="1.4.0.2" />
112+
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.0.1" />
113+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common" Version="2.7.0.1" />
114+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData.Core" Version="2.7.0.1" />
115+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Runtime" Version="2.7.0.1" />
116+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.ViewModel" Version="2.7.0.1" />
117+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.ViewModelSavedState" Version="2.7.0.1" />-->
118+
</ItemGroup>
119+
120+
<!-- Android Firebase configuration. -->
121+
<ItemGroup>
122+
<GoogleServicesJson Include="Android\google-services.json">
123+
<Link>google-services.json</Link>
124+
</GoogleServicesJson>
104125
</ItemGroup>
105126
<ItemGroup>
106127
<AndroidAotProfile Include="custom.aprof" />
@@ -153,6 +174,12 @@
153174
<!-- 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. -->
154175
<ForceSimulatorX64ArchitectureInIDE>true</ForceSimulatorX64ArchitectureInIDE>
155176
</PropertyGroup>
177+
<!-- iOS Firebase configuration. -->
178+
<ItemGroup>
179+
<BundleResource Include="iOS\GoogleService-Info.plist">
180+
<Link>GoogleService-Info.plist</Link>
181+
</BundleResource>
182+
</ItemGroup>
156183
<Choose>
157184
<When Condition="'$(Configuration)'=='Debug'">
158185
<PropertyGroup>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>API_KEY</key>
6+
<string>AIzaSyB4Yci2AO0yKL04CDg_hbwuZJLFRtwWeQ0</string>
7+
<key>GCM_SENDER_ID</key>
8+
<string>273937217541</string>
9+
<key>PLIST_VERSION</key>
10+
<string>1</string>
11+
<key>BUNDLE_ID</key>
12+
<string>com.nventive.applicationtemplate</string>
13+
<key>PROJECT_ID</key>
14+
<string>unoapplicationtemplate</string>
15+
<key>STORAGE_BUCKET</key>
16+
<string>unoapplicationtemplate.appspot.com</string>
17+
<key>IS_ADS_ENABLED</key>
18+
<false></false>
19+
<key>IS_ANALYTICS_ENABLED</key>
20+
<false></false>
21+
<key>IS_APPINVITE_ENABLED</key>
22+
<true></true>
23+
<key>IS_GCM_ENABLED</key>
24+
<true></true>
25+
<key>IS_SIGNIN_ENABLED</key>
26+
<true></true>
27+
<key>GOOGLE_APP_ID</key>
28+
<string>1:273937217541:ios:67311e95701c4f089a846c</string>
29+
</dict>
30+
</plist>

src/app/ApplicationTemplate.Presentation/Configuration/ApiConfiguration.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public static IServiceCollection AddApi(this IServiceCollection services, IConfi
4242
.AddAuthentication()
4343
.AddPosts(configuration)
4444
.AddUserProfile()
45-
.AddMinimumVersion()
46-
.AddKillSwitch()
4745
.AddDadJokes(configuration);
4846

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

58-
private static IServiceCollection AddMinimumVersion(this IServiceCollection services)
59-
{
60-
// This one doesn't have an actual remote API yet. It's always a mock implementation.
61-
return services.AddSingleton<IMinimumVersionReposiory, MinimumVersionRepositoryMock>();
62-
}
63-
64-
private static IServiceCollection AddKillSwitch(this IServiceCollection services)
65-
{
66-
// This one doesn't have an actual remote API yet. It's always a mock implementation.
67-
return services.AddSingleton<IKillSwitchRepository, KillSwitchRepositoryMock>();
68-
}
69-
7056
private static IServiceCollection AddAuthentication(this IServiceCollection services)
7157
{
7258
// This one doesn't have an actual remote API yet. It's always a mock implementation.

src/app/ApplicationTemplate.Shared.Views/ApplicationTemplate.Shared.Views.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
<Compile Include="$(MSBuildThisFileDirectory)Helpers\DependencyObjectExtensions.cs" />
119119
<Compile Include="$(MSBuildThisFileDirectory)Helpers\FrameworkElementExtension.cs" />
120120
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ObservableExtensions.cs" />
121+
<Compile Include="$(MSBuildThisFileDirectory)RemoteConfigRepository.Android.cs" />
121122
<Compile Include="$(MSBuildThisFileDirectory)Shell.xaml.cs">
122123
<DependentUpon>Shell.xaml</DependentUpon>
123124
</Compile>

src/app/ApplicationTemplate.Shared.Views/Configuration/ViewServicesConfiguration.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Reactive.Concurrency;
2+
using ApplicationTemplate.DataAccess;
23
using Chinook.DynamicMvvm;
34
using MessageDialogService;
45
using Microsoft.Extensions.DependencyInjection;
@@ -34,6 +35,14 @@ public static IServiceCollection AddViewServices(this IServiceCollection service
3435
.AddSingleton<IEmailService, EmailService>()
3536
.AddSingleton<IMemoryProvider, MemoryProvider>()
3637
.AddSingleton<IReviewPrompter, ReviewPrompter>()
38+
#if __ANDROID__
39+
.AddSingleton<RemoteConfigRepository>()
40+
.AddSingleton<IKillSwitchRepository>(s => s.GetRequiredService<RemoteConfigRepository>())
41+
.AddSingleton<IMinimumVersionReposiory>(s => s.GetRequiredService<RemoteConfigRepository>())
42+
#else
43+
.AddSingleton<IKillSwitchRepository, KillSwitchRepositoryMock>()
44+
.AddSingleton<IMinimumVersionReposiory, MinimumVersionRepositoryMock>()
45+
#endif
3746
.AddMessageDialog();
3847
}
3948

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#if __ANDROID__
2+
using System;
3+
using System.Reactive.Subjects;
4+
using ApplicationTemplate.DataAccess;
5+
using Firebase.RemoteConfig;
6+
7+
namespace ApplicationTemplate.Views;
8+
9+
/// <summary>
10+
/// RemoteConfigRepository is a repository for Firebase Remote Config.
11+
/// </summary>
12+
public class RemoteConfigRepository : IKillSwitchRepository, IMinimumVersionReposiory
13+
{
14+
private Subject<bool> _killSwitchSubject = new Subject<bool>();
15+
private Subject<Version> _versionSubject = new Subject<Version>();
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="RemoteConfigRepository"/> class.
19+
/// </summary>
20+
public RemoteConfigRepository()
21+
{
22+
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.Instance;
23+
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
24+
.SetMinimumFetchIntervalInSeconds(3600)
25+
.Build();
26+
mFirebaseRemoteConfig.SetConfigSettingsAsync(configSettings);
27+
28+
FetchRemoteConfig();
29+
ListenForRealTimeChanges();
30+
}
31+
32+
private void FetchRemoteConfig()
33+
{
34+
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.Instance;
35+
mFirebaseRemoteConfig.FetchAndActivate()
36+
.AddOnCompleteListener(new FetchCompleteListener(this));
37+
}
38+
39+
private void ListenForRealTimeChanges()
40+
{
41+
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.Instance;
42+
43+
mFirebaseRemoteConfig.AddOnConfigUpdateListener(new ConfigUpdateListener(this));
44+
}
45+
46+
/// <inheritdoc />
47+
public IObservable<Version> MinimumVersionObservable => _versionSubject;
48+
49+
/// <inheritdoc />
50+
public void CheckMinimumVersion()
51+
{
52+
throw new NotImplementedException();
53+
}
54+
55+
/// <inheritdoc />
56+
public IObservable<bool> ObserveKillSwitchActivation()
57+
{
58+
return _killSwitchSubject;
59+
}
60+
61+
private class FetchCompleteListener : Java.Lang.Object, Android.Gms.Tasks.IOnCompleteListener
62+
{
63+
private readonly RemoteConfigRepository _repository;
64+
65+
public FetchCompleteListener(RemoteConfigRepository repository)
66+
{
67+
_repository = repository;
68+
}
69+
70+
public void OnComplete(Android.Gms.Tasks.Task task)
71+
{
72+
if (task.IsSuccessful)
73+
{
74+
_repository._killSwitchSubject.OnNext(FirebaseRemoteConfig.Instance.GetBoolean("kill_switch"));
75+
_repository._versionSubject.OnNext(new Version(FirebaseRemoteConfig.Instance.GetString("minimum_version")));
76+
}
77+
}
78+
}
79+
80+
private class ConfigUpdateListener : Java.Lang.Object, IConfigUpdateListener
81+
{
82+
private readonly RemoteConfigRepository _repository;
83+
84+
public ConfigUpdateListener(RemoteConfigRepository repository)
85+
{
86+
_repository = repository;
87+
}
88+
89+
public void OnError(FirebaseRemoteConfigException p0)
90+
{
91+
throw new NotImplementedException();
92+
}
93+
94+
public void OnUpdate(ConfigUpdate p0)
95+
{
96+
_repository._killSwitchSubject.OnNext(FirebaseRemoteConfig.Instance.GetBoolean("kill_switch"));
97+
_repository._versionSubject.OnNext(new Version(FirebaseRemoteConfig.Instance.GetString("minimum_version")));
98+
}
99+
}
100+
}
101+
#endif

0 commit comments

Comments
 (0)