Skip to content

Commit

Permalink
Merge pull request #662 from CleverTap/develop
Browse files Browse the repository at this point in the history
Release corev7.0.1
  • Loading branch information
Anush-Shand authored Sep 2, 2024
2 parents c101918 + 3799d53 commit 4b1ea75
Show file tree
Hide file tree
Showing 16 changed files with 261 additions and 45 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## CHANGE LOG.

### September 2, 2024
* [CleverTap Android SDK v7.0.1](docs/CTCORECHANGELOG.md)

### August 5, 2024
* [CleverTap Android SDK v7.0.0](docs/CTCORECHANGELOG.md)
* [CleverTap Push Templates SDK v1.2.4](docs/CTPUSHTEMPLATESCHANGELOG.md).
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ We publish the SDK to `mavenCentral` as an `AAR` file. Just declare it as depend

```groovy
dependencies {
implementation "com.clevertap.android:clevertap-android-sdk:7.0.0"
implementation "com.clevertap.android:clevertap-android-sdk:7.0.1"
}
```

Alternatively, you can download and add the AAR file included in this repo in your Module libs directory and tell gradle to install it like this:

```groovy
dependencies {
implementation (name: "clevertap-android-sdk-7.0.0", ext: 'aar')
implementation (name: "clevertap-android-sdk-7.0.1", ext: 'aar')
}
```

Expand All @@ -46,7 +46,7 @@ Add the Firebase Messaging library and Android Support Library v4 as dependencie

```groovy
dependencies {
implementation "com.clevertap.android:clevertap-android-sdk:7.0.0"
implementation "com.clevertap.android:clevertap-android-sdk:7.0.1"
implementation "androidx.core:core:1.9.0"
implementation "com.google.firebase:firebase-messaging:23.0.6"
implementation "com.google.android.gms:play-services-ads:22.3.0" // Required only if you enable Google ADID collection in the SDK (turned off by default).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.clevertap.android.sdk.variables.callbacks.FetchVariablesCallback;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@RestrictTo(Scope.LIBRARY)
Expand Down Expand Up @@ -66,7 +67,7 @@ public class CallbackManager extends BaseCallbackManager {

private FetchInAppsCallback fetchInAppsCallback;

private final List<ChangeUserCallback> changeUserCallbackList = new ArrayList<>();
private final List<ChangeUserCallback> changeUserCallbackList = Collections.synchronizedList(new ArrayList<>());

public CallbackManager(CleverTapInstanceConfig config, DeviceInfo deviceInfo) {
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.clevertap.android.sdk.inapp.customtemplates.TemplateProducer;
import com.clevertap.android.sdk.inapp.customtemplates.TemplatesManager;
import com.clevertap.android.sdk.inapp.data.CtCacheType;
import com.clevertap.android.sdk.inapp.evaluation.EvaluationManager;
import com.clevertap.android.sdk.inapp.images.repo.FileResourcesRepoFactory;
import com.clevertap.android.sdk.inapp.images.repo.FileResourcesRepoImpl;
import com.clevertap.android.sdk.inapp.store.preference.ImpressionStore;
Expand Down Expand Up @@ -2800,22 +2801,32 @@ void deviceIDCreated(String deviceId) {
StoreRegistry storeRegistry = coreState.getStoreRegistry();
CryptHandler cryptHandler = coreState.getCryptHandler();
StoreProvider storeProvider = StoreProvider.getInstance();
EvaluationManager evaluationManager = coreState.getEvaluationManager();

// Inflate the local profile here as deviceId is required
coreState.getLocalDataStore().inflateLocalProfileAsync(context);

if (storeRegistry.getInAppStore() == null) {
InAppStore inAppStore = storeProvider.provideInAppStore(context, cryptHandler, deviceId,
accountId);
storeRegistry.setInAppStore(inAppStore);
coreState.getCallbackManager().addChangeUserCallback(inAppStore);
}
if (storeRegistry.getImpressionStore() == null) {
ImpressionStore impStore = storeProvider.provideImpressionStore(context, deviceId,
accountId);
storeRegistry.setImpressionStore(impStore);
coreState.getCallbackManager().addChangeUserCallback(impStore);
}
// must move initStores task to async executor due to addChangeUserCallback synchronization
Task<Void> task = CTExecutorFactory.executors(getConfig()).ioTask();
task.execute("initStores", () -> {
if (storeRegistry.getInAppStore() == null) {
InAppStore inAppStore = storeProvider.provideInAppStore(context, cryptHandler, deviceId,
accountId);
storeRegistry.setInAppStore(inAppStore);
evaluationManager.loadSuppressedCSAndEvaluatedSSInAppsIds();
// can cause ANR if called from main thread
coreState.getCallbackManager().addChangeUserCallback(inAppStore);
}
if (storeRegistry.getImpressionStore() == null) {
ImpressionStore impStore = storeProvider.provideImpressionStore(context, deviceId,
accountId);
storeRegistry.setImpressionStore(impStore);
// can cause ANR if called from main thread
coreState.getCallbackManager().addChangeUserCallback(impStore);
}
return null;
});


/*
Reinitialising InAppFCManager with device id, if it's null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.os.Parcelable.Creator
import com.clevertap.android.sdk.Constants
import com.clevertap.android.sdk.Constants.KEY_FALLBACK_NOTIFICATION_SETTINGS
import com.clevertap.android.sdk.inapp.InAppActionType.OPEN_URL
import com.clevertap.android.sdk.inapp.InAppActionType.CLOSE
import com.clevertap.android.sdk.inapp.customtemplates.CustomTemplateInAppData
import com.clevertap.android.sdk.utils.getStringOrNull
import org.json.JSONObject
Expand Down Expand Up @@ -99,6 +100,13 @@ internal class CTInAppAction private constructor(parcel: Parcel?) : Parcelable {
actionUrl = url
}
}

@JvmStatic
fun createCloseAction(): CTInAppAction {
return CTInAppAction(null).apply {
type = CLOSE
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ public FileResourceProvider resourceProvider() {
}

private Bundle didClick(CTInAppNotificationButton button) {
return notifyActionTriggered(button.getAction(), button.getText(), null);
CTInAppAction action = button.getAction();
if (action == null) {
action = CTInAppAction.createCloseAction();
}
return notifyActionTriggered(action, button.getText(), null);
}

private Bundle notifyActionTriggered(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class CTLocalInApp private constructor() {
val positiveButtonObject = JSONObject().apply {
put(Constants.KEY_TEXT, positiveBtnText)
put(Constants.KEY_RADIUS, "2")
put(Constants.KEY_ACTIONS, JSONObject().apply {
put(Constants.KEY_TYPE, InAppActionType.CLOSE)
})
}
put(Constants.KEY_BUTTONS, JSONArray().put(0, positiveButtonObject))
Builder5(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.clevertap.android.sdk.login;

import android.content.Context;

import androidx.annotation.RestrictTo;

import com.clevertap.android.sdk.AnalyticsManager;
import com.clevertap.android.sdk.BaseCallbackManager;
import com.clevertap.android.sdk.CTLockManager;
Expand Down Expand Up @@ -29,6 +32,7 @@
import java.util.Map;
import java.util.concurrent.Callable;

@RestrictTo(RestrictTo.Scope.LIBRARY)
public class LoginController {

private String cachedGUID = null;
Expand Down Expand Up @@ -144,11 +148,8 @@ public Void call() {
recordDeviceIDErrors();
resetDisplayUnits();

final List<ChangeUserCallback> changeUserCallbackList
= callbackManager.getChangeUserCallbackList();
for (ChangeUserCallback callback : changeUserCallbackList) {
callback.onChangeUser(deviceInfo.getDeviceID(), config.getAccountId());
}
notifyChangeUserCallback();

controllerManager.getInAppFCManager().changeUser(deviceInfo.getDeviceID());
} catch (Throwable t) {
config.getLogger().verbose(config.getAccountId(), "Reset Profile error", t);
Expand All @@ -158,6 +159,18 @@ public Void call() {
});
}

public void notifyChangeUserCallback() {
final List<ChangeUserCallback> changeUserCallbackList
= callbackManager.getChangeUserCallbackList();
synchronized (changeUserCallbackList) {
for (ChangeUserCallback callback : changeUserCallbackList) {
if (callback != null) {
callback.onChangeUser(deviceInfo.getDeviceID(), config.getAccountId());
}
}
}
}

@SuppressWarnings({"unused", "WeakerAccess"})
public void onUserLogin(final Map<String, Object> profile, final String cleverTapID) {
if (config.getEnableCustomCleverTapId()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.clevertap.android.sdk.inapp

import com.clevertap.android.sdk.inapp.CTLocalInApp.InAppType.ALERT
import com.clevertap.android.shared.test.BaseTestCase
import org.json.JSONArray
import org.json.JSONObject
import org.junit.*
import org.skyscreamer.jsonassert.JSONAssert
import org.junit.Assert.assertEquals

class CTLocalInAppTest : BaseTestCase() {

Expand All @@ -18,18 +19,58 @@ class CTLocalInAppTest : BaseTestCase() {
.setTitleTextColor("#F0F000").setMessageTextColor("#F000F0").setImageUrl("https://abc.com/xyz.jpg")
.build()

val expectedJsonObject =
JSONObject(
"{\"type\":\"alert-template\",\"isLocalInApp\":true,\"close\":true,\"title\":" +
"{\"text\":\"titleText\",\"color\":\"#F0F000\"},\"message\":{\"text\":\"messageText\"," +
"\"color\":\"#F000F0\"},\"hasPortrait\":true,\"hasLandscape\":true,\"buttons\":" +
"[{\"text\":\"Agree\",\"radius\":\"#FFFFFF\",\"bg\":\"#00FF00\",\"border\":\"#000000\"," +
"\"color\":\"#FFFF00\"},{\"text\":\"Decline\",\"radius\":\"#FFFFFF\",\"bg\":\"#00FF00\"," +
"\"border\":\"#000000\",\"color\":\"#FFFF00\"}],\"bg\":\"#FF0000\"," +
"\"fallbackToNotificationSettings\":true,\"media\":{\"url\":\"https:\\/\\/abc.com\\/xyz.jpg\"," +
"\"content_type\":\"image\"},\"mediaLandscape\":{\"url\":\"https:\\/\\/abc.com\\/xyz.jpg\"," +
"\"content_type\":\"image\"}}"
)
JSONAssert.assertEquals(expectedJsonObject, actualJsonObject, true)
// Arrange: Create the expected JSON object
val expectedJsonObject = JSONObject().apply {
put("type", "alert-template")
put("isLocalInApp", true)
put("close", true)

put("title", JSONObject().apply {
put("text", "titleText")
put("color", "#F0F000")
})

put("message", JSONObject().apply {
put("text", "messageText")
put("color", "#F000F0")
})

put("hasPortrait", true)
put("hasLandscape", true)

put("buttons", JSONArray().apply {
put(JSONObject().apply {
put("text", "Agree")
put("radius", "#FFFFFF")
put("actions", JSONObject().apply {
put("type", "close")
})
put("bg", "#00FF00")
put("border", "#000000")
put("color", "#FFFF00")
})
put(JSONObject().apply {
put("text", "Decline")
put("radius", "#FFFFFF")
put("bg", "#00FF00")
put("border", "#000000")
put("color", "#FFFF00")
})
})

put("bg", "#FF0000")
put("fallbackToNotificationSettings", true)

val mediaObject = JSONObject().apply {
put("url", "https://abc.com/xyz.jpg")
put("content_type", "image")
}

put("media", mediaObject)
put("mediaLandscape", mediaObject)
}

// Assert: Check if the actual JSON object matches the expected JSON object
assertEquals(expectedJsonObject.toString(), actualJsonObject.toString())
}
}
Loading

0 comments on commit 4b1ea75

Please sign in to comment.