40
40
import com .clevertap .android .sdk .inapp .CTLocalInApp ;
41
41
import com .clevertap .android .sdk .inapp .callbacks .FetchInAppsCallback ;
42
42
import com .clevertap .android .sdk .inapp .customtemplates .CustomTemplateContext ;
43
+ import com .clevertap .android .sdk .inapp .customtemplates .FunctionPresenter ;
44
+ import com .clevertap .android .sdk .inapp .customtemplates .JsonTemplatesProducer ;
45
+ import com .clevertap .android .sdk .inapp .customtemplates .TemplatePresenter ;
43
46
import com .clevertap .android .sdk .inapp .customtemplates .TemplateProducer ;
44
47
import com .clevertap .android .sdk .inapp .customtemplates .TemplatesManager ;
45
48
import com .clevertap .android .sdk .inapp .data .CtCacheType ;
56
59
import com .clevertap .android .sdk .interfaces .NotificationRenderedListener ;
57
60
import com .clevertap .android .sdk .interfaces .OnInitCleverTapIDListener ;
58
61
import com .clevertap .android .sdk .interfaces .SCDomainListener ;
59
- import com .clevertap .android .sdk .network .BaseNetworkManager ;
60
62
import com .clevertap .android .sdk .network .NetworkManager ;
61
63
import com .clevertap .android .sdk .product_config .CTProductConfigController ;
62
64
import com .clevertap .android .sdk .product_config .CTProductConfigListener ;
@@ -205,7 +207,12 @@ public static void changeCredentials(String accountID, String token, String regi
205
207
* @param spikyProxyDomain CleverTap Spiky Proxy Domain
206
208
* @noinspection unused
207
209
*/
208
- public static void changeCredentials (String accountID , String token , String proxyDomain , String spikyProxyDomain ) {
210
+ public static void changeCredentials (
211
+ String accountID ,
212
+ String token ,
213
+ String proxyDomain ,
214
+ String spikyProxyDomain
215
+ ) {
209
216
if (defaultConfig != null ) {
210
217
Logger .i ("CleverTap SDK already initialized with accountID:" + defaultConfig .getAccountId ()
211
218
+ ", token:" + defaultConfig .getAccountToken () + ", proxyDomain: " + defaultConfig .getProxyDomain () +
@@ -218,6 +225,36 @@ public static void changeCredentials(String accountID, String token, String prox
218
225
ManifestInfo .changeCredentials (accountID , token , proxyDomain , spikyProxyDomain );
219
226
}
220
227
228
+ /**
229
+ * This method is used to change the credentials of CleverTap account Id, token, proxyDomain, spikyProxyDomain programmatically
230
+ *
231
+ * @param accountID CleverTap Account Id
232
+ * @param token CleverTap Account Token
233
+ * @param proxyDomain CleverTap Proxy Domain
234
+ * @param spikyProxyDomain CleverTap Spiky Proxy Domain
235
+ * @param customHandshakeDomain Custom handshake Domain
236
+ * @noinspection unused
237
+ */
238
+ public static void changeCredentials (
239
+ String accountID ,
240
+ String token ,
241
+ String proxyDomain ,
242
+ String spikyProxyDomain ,
243
+ String customHandshakeDomain
244
+ ) {
245
+ if (defaultConfig != null ) {
246
+ Logger .i ("CleverTap SDK already initialized with accountID:" + defaultConfig .getAccountId ()
247
+ + ", token:" + defaultConfig .getAccountToken () + ", proxyDomain: " + defaultConfig .getProxyDomain () +
248
+ ", spikyDomain: " + defaultConfig .getSpikyProxyDomain () + ", handshakeDomain: " + defaultConfig .getCustomHandshakeDomain ()
249
+ + ". Cannot change credentials to accountID: " + accountID +
250
+ ", token: " + token + ", proxyDomain: " + proxyDomain + ", spikyProxyDomain: " + spikyProxyDomain
251
+ + "and customHandshakeDomain: " + customHandshakeDomain );
252
+ return ;
253
+ }
254
+
255
+ ManifestInfo .changeCredentials (accountID , token , proxyDomain , spikyProxyDomain , customHandshakeDomain );
256
+ }
257
+
221
258
/**
222
259
* Launches an asynchronous task to download the notification icon from CleverTap,
223
260
* and create the Android notification.
@@ -1027,7 +1064,7 @@ public static void tokenRefresh(Context context, String token, PushType pushType
1027
1064
* {@link TemplateProducer}. See {@link com.clevertap.android.sdk.inapp.customtemplates.CustomTemplate.Builder
1028
1065
* CustomTemplate.Builder}. Templates must be registered before the {@link CleverTapAPI} instance, that would use
1029
1066
* them, is created. A common place for this initialization is in {@link Application#onCreate()}. If your
1030
- * application uses multiple {@link CleverTapAPI} instance , use the {@link CleverTapInstanceConfig} within the
1067
+ * application uses multiple {@link CleverTapAPI} instances , use the {@link CleverTapInstanceConfig} within the
1031
1068
* TemplateProducer to differentiate which templates should be registered to which {@link CleverTapAPI}
1032
1069
* instances.This method can be called multiple times with different TemplateProducers, however all of the
1033
1070
* produced templates must have unique names.
@@ -1061,6 +1098,32 @@ public static synchronized void registerCustomInAppTemplates(TemplateProducer pr
1061
1098
TemplatesManager .register (producer );
1062
1099
}
1063
1100
1101
+ /**
1102
+ * Register {@link com.clevertap.android.sdk.inapp.customtemplates.CustomTemplate CustomTemplates} through a
1103
+ * json definition. Templates must be registered before the {@link CleverTapAPI} instance, that would use
1104
+ * them, is created. A common place for this initialization is in {@link Application#onCreate()}. If your
1105
+ * application uses multiple {@link CleverTapAPI} instances, extend {@link JsonTemplatesProducer}
1106
+ * with definitions for each instance and register using {@link #registerCustomInAppTemplates(TemplateProducer)}.
1107
+ * Use the {@link CleverTapInstanceConfig} in {@link JsonTemplatesProducer#defineTemplates} to control
1108
+ * for which instance the templates should be registered.
1109
+ * </br>
1110
+ * This method can be called multiple times with different json definitions and presenters,
1111
+ * however all of the templates must have unique names.
1112
+ *
1113
+ * @param templatesJson A string with the json definitions of templates. See
1114
+ * {@link JsonTemplatesProducer} for the json format.
1115
+ * @param templatesPresenter A presenter for all templates in the json definitions.
1116
+ * Required if there is at least one template with type "template".
1117
+ * @param functionsPresenter A presenter for all functions in the json definitions.
1118
+ * Required if there is at least one template with type "function".
1119
+ */
1120
+ public static synchronized void registerCustomInAppTemplates
1121
+ (@ NonNull String templatesJson ,
1122
+ @ Nullable TemplatePresenter templatesPresenter ,
1123
+ @ Nullable FunctionPresenter functionsPresenter ) {
1124
+ TemplatesManager .register (new JsonTemplatesProducer (templatesJson , templatesPresenter , functionsPresenter ));
1125
+ }
1126
+
1064
1127
/**
1065
1128
* Retrieve a {@link CustomTemplateContext} for a template that is currently displaying. If the provided template
1066
1129
* name is not of a currently active template this method returns <code>null</code>.
@@ -1104,7 +1167,7 @@ public void syncRegisteredInAppTemplates() {
1104
1167
}
1105
1168
1106
1169
TemplatesManager templatesManager = coreState .getTemplatesManager ();
1107
- BaseNetworkManager networkManager = coreState .getNetworkManager ();
1170
+ NetworkManager networkManager = coreState .getNetworkManager ();
1108
1171
1109
1172
getCleverTapID (x -> {
1110
1173
// getCleverTapID is executed on the main thread
@@ -1365,10 +1428,10 @@ public void flush() {
1365
1428
public void setSCDomainListener (SCDomainListener scDomainListener ) {
1366
1429
coreState .getCallbackManager ().setSCDomainListener (scDomainListener );
1367
1430
1368
- if (coreState .getNetworkManager () != null ) {
1369
- NetworkManager networkManager = ( NetworkManager ) coreState .getNetworkManager ();
1431
+ if (coreState .getNetworkManager () != null ) {
1432
+ NetworkManager networkManager = coreState .getNetworkManager ();
1370
1433
String domain = networkManager .getDomain (EventGroup .REGULAR );
1371
- if (domain != null ) {
1434
+ if (domain != null ) {
1372
1435
scDomainListener .onSCDomainAvailable (getSCDomain (domain ));
1373
1436
}
1374
1437
}
@@ -3039,6 +3102,7 @@ private static CleverTapInstanceConfig getDefaultConfig(Context context) {
3039
3102
String accountRegion = manifest .getAccountRegion ();
3040
3103
String proxyDomain = manifest .getProxyDomain ();
3041
3104
String spikyProxyDomain = manifest .getSpikeyProxyDomain ();
3105
+ String handshakeDomain = manifest .getHandshakeDomain ();
3042
3106
if (accountId == null || accountToken == null ) {
3043
3107
Logger .i (
3044
3108
"Account ID or Account token is missing from AndroidManifest.xml, unable to create default instance" );
@@ -3055,6 +3119,9 @@ private static CleverTapInstanceConfig getDefaultConfig(Context context) {
3055
3119
if (spikyProxyDomain != null && !spikyProxyDomain .trim ().isEmpty ()) {
3056
3120
defaultInstanceConfig .setSpikyProxyDomain (spikyProxyDomain );
3057
3121
}
3122
+ if (handshakeDomain != null && !handshakeDomain .trim ().isEmpty ()) {
3123
+ defaultInstanceConfig .setCustomHandshakeDomain (handshakeDomain );
3124
+ }
3058
3125
return defaultInstanceConfig ;
3059
3126
}
3060
3127
0 commit comments