Class Appfigurate
java.lang.Object
nz.co.electricbolt.appfiguratelibrary.Appfigurate
Appfigurate library static methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Used in conjunction withaddConfigurationUpdatedListener
andremoveConfigurationUpdatedListener
static interface
Used in conjunction withfetchRemoteConfiguration(FetchRemoteConfiguration)
. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Registers a delegate method that will be called back when Appfigurate has updated the configuration of the app.static void
fetchRemoteConfiguration
(Appfigurate.FetchRemoteConfiguration fetchRemoteConfiguration) When integrating with third party remote configuration providers, you must specify a block that is called back whenever Appfigurate requires the current value of a remote property.static void
Forces the callback passed intofetchRemoteConfiguration(nz.co.electricbolt.appfiguratelibrary.Appfigurate.FetchRemoteConfiguration)
to be invoked to reload the current values of remote properties.static void
Unregisters the delegate method that will be called back when Appfigurate has updated the configuration of the application.static void
Restores the configuration from temporary storage back intoSharedPreferences
static void
Saves the configuration persisted inSharedPreferences
into temporary storage.static void
setLogging
(boolean logging) When true, Appfigurate library debugging messages will be output to the console.static String
version()
The version of the Appfigurate library in the format major.minor.patch
-
Method Details
-
version
The version of the Appfigurate library in the format major.minor.patch- Returns:
- Version number. e.g. "5.1.2"
-
addConfigurationUpdatedListener
public static void addConfigurationUpdatedListener(@NonNull Appfigurate.ConfigurationUpdated target) Registers a delegate method that will be called back when Appfigurate has updated the configuration of the app. The delegate method will be called back on the main looper- Parameters:
target
- delegate method to be registered
-
removeConfigurationUpdatedListener
public static void removeConfigurationUpdatedListener(@NonNull Appfigurate.ConfigurationUpdated target) Unregisters the delegate method that will be called back when Appfigurate has updated the configuration of the application. You must call this method before the target is deallocated- Parameters:
target
- delegate method to unregister
-
setLogging
public static void setLogging(boolean logging) When true, Appfigurate library debugging messages will be output to the console. The default is false. It is best practice to distribute applications via Google Play with logging set to false. See `APLLogging` meta-data in the AndroidManifest.xml file- Parameters:
logging
- true if debugging messages should be output to the console
-
saveConfiguration
public static void saveConfiguration()Saves the configuration persisted inSharedPreferences
into temporary storage. Some apps have functionality to eraseSharedPreferences
to reset apps back to 'factory defaults', which has the side effect of removing any Appfigurate configuration persisted inSharedPreferences
- See Also:
-
restoreConfiguration
public static void restoreConfiguration()Restores the configuration from temporary storage back intoSharedPreferences
- See Also:
-
fetchRemoteConfiguration
public static void fetchRemoteConfiguration(Appfigurate.FetchRemoteConfiguration fetchRemoteConfiguration) When integrating with third party remote configuration providers, you must specify a block that is called back whenever Appfigurate requires the current value of a remote property. The block will be called for each @RemoteXProperty annotation you have specified in yourConfiguration
subclass> Java Firebase Remote Config example
Appfigurate.fetchRemoteConfiguration((remoteKey, propertyType, defaultValue) -> { return switch (propertyType) { case RemotePropertyTypeString -> this.remoteConfig.getString(remoteKey); case RemotePropertyTypeBoolean -> this.remoteConfig.getBoolean(remoteKey); case RemotePropertyTypeInt -> this.remoteConfig.getLong(remoteKey); case RemotePropertyTypeDouble -> this.remoteConfig.getDouble(remoteKey); }; });
> Kotlin Firebase Remote Config exampleAppfigurate.fetchRemoteConfiguration { remoteKey: String, propertyType: RemotePropertyType, defaultValue: Any? -> when (propertyType) { RemotePropertyTypeString -> this.remoteConfig.getString(remoteKey) RemotePropertyTypeBoolean -> this.remoteConfig.getBoolean(remoteKey) RemotePropertyTypeInt -> this.remoteConfig.getLong(remoteKey) RemotePropertyTypeDouble -> this.remoteConfig.getDouble(remoteKey) } }
> Java Launch Darkly exampleAppfigurate.fetchRemoteConfiguration((propertyKey, propertyType, defaultValue) -> { try { return switch (propertyType) { case RemotePropertyTypeString -> LDClient.get().stringVariation(propertyKey, (String) defaultValue); case RemotePropertyTypeBoolean -> LDClient.get().boolVariation(propertyKey, (Boolean) defaultValue); case RemotePropertyTypeInt -> LDClient.get().intVariation(propertyKey, (Integer) defaultValue); case RemotePropertyTypeDouble -> LDClient.get().doubleVariation(propertyKey, (Double) defaultValue); }; } catch(LaunchDarklyException e) { return defaultValue; } });
> Kotlin Launch Darkly exampleAppfigurate.fetchRemoteConfiguration { propertyKey: String, propertyType: RemotePropertyType, defaultValue: Any? -> try { if (propertyType == RemotePropertyTypeString) LDClient.get().stringVariation(propertyKey, defaultValue as String) else if (propertyType == RemotePropertyTypeBoolean) LDClient.get().boolVariation(propertyKey, defaultValue as Boolean) else if (propertyType == RemotePropertyTypeInt) LDClient.get().intVariation(propertyKey, defaultValue as Int) else // RemotePropertyTypeDouble LDClient.get().doubleVariation(propertyKey, defaultValue as Double) } catch (e: LaunchDarklyException) { defaultValue } }
- Parameters:
fetchRemoteConfiguration
- block that is called back whenever Appfigurate requires the current value of a remote property
-
flushRemoteConfiguration
public static void flushRemoteConfiguration()Forces the callback passed intofetchRemoteConfiguration(nz.co.electricbolt.appfiguratelibrary.Appfigurate.FetchRemoteConfiguration)
to be invoked to reload the current values of remote properties.> Java Firebase Remote Config example
this.remoteConfig.fetchAndActivate().addOnCompleteListener(this, task -> { if (task.isSuccessful()) { Appfigurate.flushRemoteConfiguration(); } });
> Kotlin Firebase Remote Config examplethis.remoteConfig.fetchAndActivate().addOnCompleteListener(this) { task -> if (task.isSuccessful()) { Appfigurate.flushRemoteConfiguration() } }
> Java Launch Darkly exampleLDClient.get().registerAllFlagsListener(new LDAllFlagsListener() { &Override public void onChange(List<String> flagKey) { Appfigurate.flushRemoteConfiguration(); } });
> Kotlin Launch Darkly exampleLDClient.get().registerAllFlagsListener { Appfigurate.flushRemoteConfiguration() }
-