From 8968db8013de1aecd5fbcb315ca588ae45e8b066 Mon Sep 17 00:00:00 2001 From: ArtursK Date: Tue, 27 Jun 2023 13:45:05 +0300 Subject: [PATCH] Updating example app and adding function comments --- .../demo/ActivityExampleRemoteConfig.java | 30 ++++---- .../ly/count/android/sdk/CountlyConfig.java | 24 ++++++- .../count/android/sdk/ModuleRemoteConfig.java | 71 ++++++++++++++----- 3 files changed, 91 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/ly/count/android/demo/ActivityExampleRemoteConfig.java b/app/src/main/java/ly/count/android/demo/ActivityExampleRemoteConfig.java index 99063db98..11f6f0fb0 100644 --- a/app/src/main/java/ly/count/android/demo/ActivityExampleRemoteConfig.java +++ b/app/src/main/java/ly/count/android/demo/ActivityExampleRemoteConfig.java @@ -39,7 +39,7 @@ public void onClickRemoteConfigUpdate(View v) { } public void onClickRemoteConfigGetValue(View v) { - Object value = Countly.sharedInstance().remoteConfig().getValueForKey("aa"); + Object value = Countly.sharedInstance().remoteConfig().getValue("aa").value; if (value != null) { Toast.makeText(getApplicationContext(), "Stored Remote Config Value with key 'a': [" + (int) value + "]", Toast.LENGTH_SHORT).show(); } else { @@ -48,10 +48,9 @@ public void onClickRemoteConfigGetValue(View v) { } public void onClickRemoteConfigGetValueInclusion(View v) { - Countly.sharedInstance().remoteConfig().updateForKeysOnly(new String[] { "aa", "dd" }, new RemoteConfigCallback() { - @Override - public void callback(String error) { - if (error == null) { + Countly.sharedInstance().remoteConfig().downloadSpecificKeys(new String[] { "aa", "dd" }, new RCDownloadCallback() { + @Override public void callback(RequestResult downloadResult, String error, boolean fullValueUpdate, Map downloadedValues) { + if (downloadResult != RequestResult.Success) { Toast.makeText(getApplicationContext(), "Update with inclusion finished", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Error: " + error, Toast.LENGTH_SHORT).show(); @@ -61,10 +60,9 @@ public void callback(String error) { } public void onClickRemoteConfigGetValueExclusion(View v) { - Countly.sharedInstance().remoteConfig().updateExceptKeys(new String[] { "aa", "dd" }, new RemoteConfigCallback() { - @Override - public void callback(String error) { - if (error == null) { + Countly.sharedInstance().remoteConfig().downloadOmittingKeys(new String[] { "aa", "dd" }, new RCDownloadCallback() { + @Override public void callback(RequestResult downloadResult, String error, boolean fullValueUpdate, Map downloadedValues) { + if (downloadResult != RequestResult.Success) { Toast.makeText(getApplicationContext(), "Update with exclusion finished", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Error: " + error, Toast.LENGTH_SHORT).show(); @@ -74,13 +72,13 @@ public void callback(String error) { } public void onClickRemoteConfigClearValues(View v) { - Countly.sharedInstance().remoteConfig().clearStoredValues(); + Countly.sharedInstance().remoteConfig().clearAll(); } public void onClickRemoteConfigPrintValues(View v) { //this sample assumes that there are 4 keys available on the server - Map values = Countly.sharedInstance().remoteConfig().getAllValues(); + Map values = Countly.sharedInstance().remoteConfig().getValues(); Countly.sharedInstance().L.d("Get all values test: [" + values.toString() + "]"); @@ -90,14 +88,14 @@ public void onClickRemoteConfigPrintValues(View v) { Object value_3 = null; if (values != null) { - value_1 = values.get("aa"); - value_2 = values.get("bb"); - value_3 = values.get("cc"); + value_1 = values.get("aa").value; + value_2 = values.get("bb").value; + value_3 = values.get("cc").value; } //access way #2 - Object value_4 = Countly.sharedInstance().remoteConfig().getValueForKey("dd"); - Object value_5 = Countly.sharedInstance().remoteConfig().getValueForKey("ee"); + Object value_4 = Countly.sharedInstance().remoteConfig().getValue("dd").value; + Object value_5 = Countly.sharedInstance().remoteConfig().getValue("ee").value; String printValues = ""; diff --git a/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java b/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java index 9a7314325..2c2bce7f6 100644 --- a/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java +++ b/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java @@ -481,7 +481,7 @@ public synchronized CountlyConfig setPushIntentAddMetadata(boolean enable) { * @param enabled set true for enabling it * @param callback callback called after the update was done * @return Returns the same config object for convenient linking - * @deprecated + * @deprecated use "enableRemoteConfigAutomaticTriggers" and "RemoteConfigRegisterGlobalCallback" in it's place */ public synchronized CountlyConfig setRemoteConfigAutomaticDownload(boolean enabled, RemoteConfigCallback callback) { enableRemoteConfigAutomaticDownloadTriggers = enabled; @@ -489,16 +489,36 @@ public synchronized CountlyConfig setRemoteConfigAutomaticDownload(boolean enabl return this; } + /** + * Calling this would enable automatic download triggers for remote config. + * This way the SDK would automatically initiate remote config download at specific points. + * For example, those include: the SDK finished initializing, device ID is changed, consent is given + * + * @return Returns the same config object for convenient linking + */ public synchronized CountlyConfig enableRemoteConfigAutomaticTriggers() { enableRemoteConfigAutomaticDownloadTriggers = true; return this; } + /** + * If this option is not enabled then when the device ID is changed without merging, remote config values are cleared + * If this option is enabled then the previous values are not cleared but they are marked as not from the current user. + * + * @return Returns the same config object for convenient linking + */ public synchronized CountlyConfig enableRemoteConfigValueCaching() { enableRemoteConfigValueCaching = true; return this; } + /** + * Calling this adds global listeners for remote config download callbacks. + * Calling this multiple times would add multiple listeners + * + * @param callback The callback that needs to be registered + * @return Returns the same config object for convenient linking + */ public synchronized CountlyConfig RemoteConfigRegisterGlobalCallback(RCDownloadCallback callback) { remoteConfigGlobalCallbackList.add(callback); return this; @@ -507,7 +527,7 @@ public synchronized CountlyConfig RemoteConfigRegisterGlobalCallback(RCDownloadC /** * Set if consent should be required * - * @param shouldRequireConsent + * @param shouldRequireConsent if set to "true" then the SDK will require consent to be used. If consent for features is not given, they would not function * @return Returns the same config object for convenient linking */ public synchronized CountlyConfig setRequiresConsent(boolean shouldRequireConsent) { diff --git a/sdk/src/main/java/ly/count/android/sdk/ModuleRemoteConfig.java b/sdk/src/main/java/ly/count/android/sdk/ModuleRemoteConfig.java index c9a515ab0..3778b4aa2 100644 --- a/sdk/src/main/java/ly/count/android/sdk/ModuleRemoteConfig.java +++ b/sdk/src/main/java/ly/count/android/sdk/ModuleRemoteConfig.java @@ -511,7 +511,7 @@ public void clearStoredValues() { /** * @return - * @deprecated + * @deprecated You should use "getValues" */ public Map getAllValues() { synchronized (_cly) { @@ -526,7 +526,7 @@ public Map getAllValues() { * * @param key * @return - * @deprecated + * @deprecated You should use "getValue" */ public Object getValueForKey(String key) { synchronized (_cly) { @@ -541,7 +541,7 @@ public Object getValueForKey(String key) { * * @param keysToExclude * @param callback - * @deprecated + * @deprecated You should use "downloadOmittingKeys" */ public void updateExceptKeys(String[] keysToExclude, RemoteConfigCallback callback) { synchronized (_cly) { @@ -568,11 +568,11 @@ public void updateExceptKeys(String[] keysToExclude, RemoteConfigCallback callba } /** - * Manual remote config_ update call. Will only update the keys provided. + * Manual remote config update call. Will only update the keys provided. * * @param keysToInclude * @param callback - * @deprecated + * @deprecated You should use "downloadSpecificKeys" */ public void updateForKeysOnly(String[] keysToInclude, RemoteConfigCallback callback) { synchronized (_cly) { @@ -598,10 +598,10 @@ public void updateForKeysOnly(String[] keysToInclude, RemoteConfigCallback callb } /** - * Manually update remote config_ values + * Manually update remote config values * * @param callback - * @deprecated + * @deprecated You should use "downloadAllKeys" */ public void update(RemoteConfigCallback callback) { synchronized (_cly) { @@ -625,10 +625,11 @@ public void update(RemoteConfigCallback callback) { } /** - * Manual remote config update call. Will update all keys except the ones provided + * Manual remote config call that will initiate a download of all except the given remote config keys. + * If no keys are provided then it will download all available RC values * - * @param keysToOmit - * @param callback + * @param keysToOmit A list of keys that need to be downloaded + * @param callback This is called when the operation concludes */ public void downloadOmittingKeys(@Nullable String[] keysToOmit, @Nullable RCDownloadCallback callback) { synchronized (_cly) { @@ -654,10 +655,11 @@ public void downloadOmittingKeys(@Nullable String[] keysToOmit, @Nullable RCDown } /** - * Manual remote config_ update call. Will only update the keys provided. + * Manual remote config call that will initiate a download of only the given remote config keys. + * If no keys are provided then it will download all available RC values * - * @param keysToInclude - * @param callback + * @param keysToInclude Keys for which the RC should be initialized + * @param callback This is called when the operation concludes */ public void downloadSpecificKeys(@Nullable String[] keysToInclude, @Nullable RCDownloadCallback callback) { synchronized (_cly) { @@ -681,6 +683,11 @@ public void downloadSpecificKeys(@Nullable String[] keysToInclude, @Nullable RCD } } + /** + * Manual remote config call that will initiate a download of all available remote config keys. + * + * @param callback This is called when the operation concludes + */ public void downloadAllKeys(@Nullable RCDownloadCallback callback) { synchronized (_cly) { L.i("[RemoteConfig] Manually calling to update Remote Config v2"); @@ -701,6 +708,11 @@ public void downloadAllKeys(@Nullable RCDownloadCallback callback) { } } + /** + * Returns all available remote config values + * + * @return The available RC values + */ public @NonNull Map getValues() { synchronized (_cly) { L.i("[RemoteConfig] Getting all Remote config values v2"); @@ -709,6 +721,12 @@ public void downloadAllKeys(@Nullable RCDownloadCallback callback) { } } + /** + * Return the remote config value for a specific key + * + * @param key Key for which the remote config value needs to be returned + * @return The returned value. If no value existed for the key then the inner object will be returned as "null" + */ public @NonNull RCData getValue(@Nullable String key) { synchronized (_cly) { L.i("[RemoteConfig] Getting Remote config values for key:[" + key + "] v2"); @@ -760,14 +778,27 @@ public void exitABTestsForKeys(@Nullable String[] keys) { } } + /** + * Register a global callback for when download operations have finished + * + * @param callback The callback that should be added + */ public void registerDownloadCallback(@Nullable RCDownloadCallback callback) { downloadCallbacks.add(callback); } + /** + * Unregister a global download callback + * + * @param callback The callback that should be removed + */ public void removeDownloadCallback(@Nullable RCDownloadCallback callback) { downloadCallbacks.remove(callback); } + /** + * Clear all stored remote config values. + */ public void clearAll() { clearStoredValues(); } @@ -775,7 +806,9 @@ public void clearAll() { /** * Returns all variant information as a Map * - * @return + * This call is not meant for production. It should only be used to facilitate testing of A/B test experiments. + * + * @return Return the information of all available variants */ public @NonNull Map testingGetAllVariants() { synchronized (_cly) { @@ -788,8 +821,10 @@ public void clearAll() { /** * Returns variant information for a key as a String[] * + * This call is not meant for production. It should only be used to facilitate testing of A/B test experiments. + * * @param key - key value to get variant information for - * @return + * @return If returns the stored variants for the given key. Returns "null" if there are no variants for that key. */ public @Nullable String[] testingGetVariantsForKey(@Nullable String key) { synchronized (_cly) { @@ -807,7 +842,9 @@ public void clearAll() { /** * Download all variants of A/B testing experiments * - * @param completionCallback + * This call is not meant for production. It should only be used to facilitate testing of A/B test experiments. + * + * @param completionCallback this callback will be called when the network request finished */ public void testingDownloadVariantInformation(@Nullable RCVariantCallback completionCallback) { synchronized (_cly) { @@ -829,6 +866,8 @@ public void testingDownloadVariantInformation(@Nullable RCVariantCallback comple /** * Enrolls user for a specific variant of A/B testing experiment * + * This call is not meant for production. It should only be used to facilitate testing of A/B test experiments. + * * @param keyName - key value retrieved from the fetched variants * @param variantName - name of the variant for the key to enroll * @param completionCallback