Skip to content

Commit

Permalink
Updating example app and adding function comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtursKadikis committed Jun 27, 2023
1 parent c9ac7c2 commit 8968db8
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<String, RCData> 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();
Expand All @@ -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<String, RCData> 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();
Expand All @@ -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<String, Object> values = Countly.sharedInstance().remoteConfig().getAllValues();
Map<String, RCData> values = Countly.sharedInstance().remoteConfig().getValues();

Countly.sharedInstance().L.d("Get all values test: [" + values.toString() + "]");

Expand All @@ -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 = "";

Expand Down
24 changes: 22 additions & 2 deletions sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,24 +481,44 @@ 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;
remoteConfigCallbackLegacy = callback;
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;
Expand All @@ -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) {
Expand Down
71 changes: 55 additions & 16 deletions sdk/src/main/java/ly/count/android/sdk/ModuleRemoteConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public void clearStoredValues() {

/**
* @return
* @deprecated
* @deprecated You should use "getValues"
*/
public Map<String, Object> getAllValues() {
synchronized (_cly) {
Expand All @@ -526,7 +526,7 @@ public Map<String, Object> getAllValues() {
*
* @param key
* @return
* @deprecated
* @deprecated You should use "getValue"
*/
public Object getValueForKey(String key) {
synchronized (_cly) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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");
Expand All @@ -701,6 +708,11 @@ public void downloadAllKeys(@Nullable RCDownloadCallback callback) {
}
}

/**
* Returns all available remote config values
*
* @return The available RC values
*/
public @NonNull Map<String, RCData> getValues() {
synchronized (_cly) {
L.i("[RemoteConfig] Getting all Remote config values v2");
Expand All @@ -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");
Expand Down Expand Up @@ -760,22 +778,37 @@ 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();
}

/**
* Returns all variant information as a Map<String, String[]>
*
* @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<String, String[]> testingGetAllVariants() {
synchronized (_cly) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 8968db8

Please sign in to comment.