Class Appfigurate

java.lang.Object
nz.co.electricbolt.appfiguratelibrary.Appfigurate

public class Appfigurate extends Object
Appfigurate library static methods.
  • Method Details

    • version

      @NonNull public static String 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 in SharedPreferences into temporary storage. Some apps have functionality to erase SharedPreferences to reset apps back to 'factory defaults', which has the side effect of removing any Appfigurate configuration persisted in SharedPreferences
      See Also:
    • restoreConfiguration

      public static void restoreConfiguration()
      Restores the configuration from temporary storage back into SharedPreferences
      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 your Configuration 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 example
       Appfigurate.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 example
       Appfigurate.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 example
       Appfigurate.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 into fetchRemoteConfiguration(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 example
       this.remoteConfig.fetchAndActivate().addOnCompleteListener(this) { task ->
         if (task.isSuccessful()) {
           Appfigurate.flushRemoteConfiguration()
         }
       }
       
      > Java Launch Darkly example
       LDClient.get().registerAllFlagsListener(new LDAllFlagsListener() {
           &Override
           public void onChange(List<String> flagKey) {
               Appfigurate.flushRemoteConfiguration();
           }
       });
       
      > Kotlin Launch Darkly example
       LDClient.get().registerAllFlagsListener {
           Appfigurate.flushRemoteConfiguration()
       }