B4A Library Firebase RemoteConfig

Discussion in 'Additional libraries, classes and official updates' started by DonManfred, Jun 11, 2016.

  1. DonManfred

    DonManfred Expert Licensed User

    This library allows you to use Firebase RemoteConfig to your app.

    Requirements:
    - B4A 6+
    - To use this library you need to Setup your app to use Firebase-Services first.

    Go to the Firebase console and setup remoteconfig

    [​IMG]


    RemoteConfig
    Author:
    DonManfred (wrapper)
    Version: 1
    • RemoteConfig
      Events:
      • onFetchComplete (success As Boolean)
      Fields:
      • DEFAULT_VALUE_FOR_BOOLEAN As Boolean
      • DEFAULT_VALUE_FOR_DOUBLE As Double
      • DEFAULT_VALUE_FOR_LONG As Long
      • DEFAULT_VALUE_FOR_STRING As String
      • LAST_FETCH_STATUS_FAILURE As Int
      • LAST_FETCH_STATUS_NO_FETCH_YET As Int
      • LAST_FETCH_STATUS_SUCCESS As Int
      • LAST_FETCH_STATUS_THROTTLED As Int
      • VALUE_SOURCE_DEFAULT As Int
      • VALUE_SOURCE_REMOTE As Int
      • VALUE_SOURCE_STATIC As Int
      Methods:
      • Defaults (defaults As Map)
      • Initialize (EventName As String)
      • IsInitialized As Boolean
      • activateFetched As Boolean
        Fetches parameter values for your app. Parameter values may be from the
        Default Config (local cache), or from the Remote Config Server,
        depending on how much time has elapsed since parameter values were last
        fetched from the Remote Config server. This method uses the default
        cache expiration of 12 hours.
        Return type: @return:
      • fetch (cacheExpiration As Int)
      • getBoolean (key As String) As Boolean
        Gets the value corresponding to the specified key,
        as a boolean.
      • getBoolean2 (key As String, namespace As String) As Boolean
        Gets the value corresponding to the specified key,
        as a boolean, in the specified namespace.
      • getByteArray (key As String) As Byte[]
        Gets the value corresponding to the specified
        key as a byte array.
        Returns Value as a byte array if a value
        corresponding to the look up key was present;
        default (if set) or static default value otherwise.
      • getByteArray2 (key As String, namespace As String) As Byte[]
        Gets the value corresponding to the specified
        key, in the specified namespace, as a byte array.
        Returns Value as a byte array if a value
        corresponding to the look up key was present;
        default (if set) or static default value otherwise.
      • getDouble (key As String) As Double
        Gets the value corresponding to the specified
        key, in the specified namespace, as a double.
        Returns Value as a double if a value corresponding
        to the look up key was present and could be
        converted to a double; default (if set) or
        static default value otherwise.
      • getDouble2 (key As String, namespace As String) As Double
        Gets the value corresponding to the specified
        key as a double.
        Returns Value as a double if a value corresponding
        to the look up key was present and could be
        converted to a double; default (if set) or
        static default value otherwise.
      • getLong (key As String) As Long
        Gets the value corresponding to the
        specified key, as a long.

        returns Value as a long if a value corresponding
        to the look up key was present and could be
        converted to a long; default (if set) or
        static default value otherwise.
      • getLong2 (key As String, namespace As String) As Long
        Gets the value corresponding to the specified
        key, in the specified namespace, as a long.
      • getString (key As String) As String
        Gets the value corresponding to
        the specified key, as a string.

        returns alue as a string if a value corresponding
        to the look up key was present and could be converted
        to a string; default (if set) or
        static default value otherwise.
      • getString2 (key As String, namespace As String) As String
        Gets value as a string corresponding
        to the specified key in the specified namespace.
        returns alue as a string if a value corresponding
        to the look up key was present and could be converted
        to a string; default (if set) or
        static default value otherwise.
      • getValue (key As String) As FirebaseRemoteConfigValue
        Gets the FirebaseRemoteConfigValue
        corresponding to the specified key.
      • getValue2 (key As String, namespace As String) As FirebaseRemoteConfigValue
      • setDefaults2 (defaults As Map, namespace As String)
      Properties:
      • ConfigSettings As FirebaseRemoteConfigSettings [write only]
        Changes the settings for the FirebaseRemoteConfig
        object's operations, such as turning the developer mode on.
      • Info As FirebaseRemoteConfigInfo [read only]
        Gets the current state of the
        FirebaseRemoteConfig singleton object.
        returns A FirebaseRemoteConfigInfo wrapping the current state.
    • RemoteConfigValue
      Methods:
      • Initialize (cfg As FirebaseRemoteConfigValue)
      • IsInitialized As Boolean
      • asBoolean As Boolean
      • asByteArray As Byte[]
      • asDouble As Double
      • asLong As Long
      • asString As String
      Properties:
      • Source As Int [read only]
        VALUE_SOURCE_REMOTE if the value was retrieved
        from the server, VALUE_SOURCE_DEFAULT if the
        value was set as a default, or VALUE_SOURCE_STATIC
        if no value was found and a static default
        value was returned instead.


    Code:
    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
        Dim cfg As RemoteConfig
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
        cfg.Initialize("Config")
        cfg.Defaults(CreateMap(
    "Month"1"loading_phrase""Hallo world!"))
        
    Log("loading_phrase="&cfg.getString("loading_phrase"))
        
    Log("Fetching")
        cfg.fetch(
    86400)
    End Sub

    Sub Activity_Resume
    End Sub
    Sub Activity_Pause (UserClosed As Boolean)
    End Sub

    Sub Config_onFetchComplete(success As Boolean)
        
    Log($"Config_onFetchComplete(${success})"$)
        
    If success Then
            
    Log("Activate fetched values")
            cfg.activateFetched
            
    Log("loading_phrase="&cfg.getString("loading_phrase"))
        
    End If

    End Sub
     

    Attached Files:

    Last edited: Jun 21, 2016
  2. AndOrNot

    AndOrNot Active Member Licensed User

    Awesome
     
    DonManfred likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    Great job!

    Note that you can add the dependency in the library and save one step for the developers:
    Code:
    @DependsOn (values={"com.google.firebase:firebase-core"})
     
  4. EvgenyB4A

    EvgenyB4A Active Member Licensed User

    Firebase looks great! When Realtime database support will be available by B4A?
     
    fredo likes this.
  5. DonManfred

    DonManfred Expert Licensed User

    This is the wrong thread for this question!

    You can always create a thread in the bugs and wishlist forum or in the questionsforum about your wish/question.
     
  6. ivan.tellez

    ivan.tellez Active Member Licensed User

    Great Work!

    Please consider adding the DependsOn, and also, could you consider renaming your lib to FirebaseRemoteConfig?

    In this way you can make developers happier.

    Thanks
     
    DonManfred likes this.
  7. DonManfred

    DonManfred Expert Licensed User

    done
    done

    Updated lib in Post #1
     
    Erel, johndb and ivan.tellez like this.
  8. luke2012

    luke2012 Well-Known Member Licensed User

    Hi @DonManfred! First of all thanks for this wonderful and useful library!
    A little donation was sent to show you my appreciation :)

    I have tested the library and I can read parameters without problems using your library (Get... methods).
    But how to update (write) the existing (firebase remote config) parameters using your library ?
     
  9. DonManfred

    DonManfred Expert Licensed User

    Change the defaults in firebase console... There is no method to update in the lib. Remoteconfig is the way to get the defaults based on your settings in fb console
     
    luke2012 likes this.
  10. vbmundo

    vbmundo Well-Known Member Licensed User

    DONMANFRED FACE DETECTED !!!

    DonManfred.png

    JAJAJA
     

    Attached Files:

    aidymp and DonManfred like this.
  11. desof

    desof Active Member Licensed User

    How do I add the reference?

    B4A version: 6.50
    Parsing code. Error
    Error parsing program.
    Error description: Unknown type: remoteconfig
    Are you missing a library reference?
    Occurred on line: 28 (Main)
    Dim cfg As RemoteConfig
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Copy the library to the additional libraries folder and then check it in the libraries tab.
     
  13. desof

    desof Active Member Licensed User

    I already have it loaded

    [​IMG]
     
Loading...