generated from nventive/Template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3418ae5
commit bfeed37
Showing
6 changed files
with
147 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/app/ApplicationTemplate.Shared.Views/RemoteConfigRepository.Android.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#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 class RemoteConfigRepository : IKillSwitchRepository, IMinimumVersionReposiory | ||
{ | ||
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; | ||
} | ||
|
||
private 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 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) | ||
{ | ||
_repository._killSwitchSubject.OnNext(FirebaseRemoteConfig.Instance.GetBoolean("kill_switch")); | ||
_repository._versionSubject.OnNext(new Version(FirebaseRemoteConfig.Instance.GetString("minimum_version"))); | ||
} | ||
} | ||
} | ||
#endif |