Skip to content

Commit

Permalink
Release of version 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Kurzawa committed Mar 28, 2023
1 parent 82aac8d commit e95fbb8
Show file tree
Hide file tree
Showing 73 changed files with 662 additions and 341 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All notable changes to this project will be documented in this file.

## [0.12.0] - 2023-03-27

### Fixed
- Voucher objects mapping.

### Changed
- `Token` object structure.
- Update of native SDK's dependencies.
- Improvements to stability.

### Added
- In-app messaging support.

### Removed
- `Injector.fetchBanners` method.
- `Injector.getBanners` method.
- `Injector.showBanner` method.

## [0.11.0] - 2023-02-07

### Fixed
Expand Down
14 changes: 7 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ apply plugin: 'com.android.library'

ext.versions = [
'minSdk' : 21,
'compileSdk' : 31,
'targetSdk' : 31,
'versionCode': 23,
'versionName': "0.11.0"
'compileSdk' : 33,
'targetSdk' : 33,
'versionCode': 24,
'versionName': "0.12.0"
]

buildscript {
Expand All @@ -23,11 +23,11 @@ buildscript {
}

android {
compileSdkVersion 31
compileSdkVersion 33

defaultConfig {
minSdkVersion 21
targetSdkVersion 31
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
Expand Down Expand Up @@ -57,7 +57,7 @@ repositories {
dependencies {
implementation 'com.facebook.react:react-native:+'
implementation "com.squareup.okhttp3:logging-interceptor:4.9.1"
api 'com.synerise.sdk:synerise-mobile-sdk:4.6.2'
api 'com.synerise.sdk:synerise-mobile-sdk:5.0.1'
}

//apply from: 'publish.gradle'
202 changes: 134 additions & 68 deletions android/src/main/java/com/synerise/sdk/react/RNInjector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.synerise.sdk.react;

import android.util.Log;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
Expand All @@ -15,9 +17,12 @@
import com.synerise.sdk.injector.callback.OnBannerListener;
import com.synerise.sdk.injector.callback.OnInjectorListener;
import com.synerise.sdk.injector.callback.OnWalkthroughListener;
import com.synerise.sdk.injector.inapp.InAppMessageData;
import com.synerise.sdk.injector.inapp.OnInAppListener;
import com.synerise.sdk.injector.net.model.inject.walkthrough.WalkthroughResponse;
import com.synerise.sdk.injector.net.model.push.banner.TemplateBanner;
import com.synerise.sdk.injector.ui.handler.InjectorActionHandler;
import com.synerise.sdk.react.utils.MapUtil;

import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -32,24 +37,34 @@
public class RNInjector extends RNBaseModule {

private static ReactApplicationContext reactApplicationContext;
private static String URL = "url";
private static String OPEN_URL_KEY = "URL_ACTION_LISTENER_KEY";
private static String DEEP_LINK_KEY = "DEEPLINK_ACTION_LISTENER_KEY";
private static String OPEN_URL_VALUE = "openUrl";
private static String DEEP_LINK = "deepLink";
private static String DEEP_LINK_VALUE = "deepLink";
private static String BANNER_PRESENTED_KEY = "BANNER_PRESENTED_LISTENER_KEY";
private static String BANNER_HIDDEN_KEY = "BANNER_HIDDEN_LISTENER_KEY";
private static String BANNER_PRESENTED_VALUE = "bannerPresented";
private static String BANNER_HIDDEN_VALUE = "bannerClosed";
private static String WALKTHROUGH_LOADING_ERROR_KEY = "WALKTHROUGH_LOADING_ERROR_LISTENER_KEY";
private static String WALKTHROUGH_LOADING_ERROR_VALUE = "walkthroughLoadingError";
private static String WALKTHROUGH_LOADED_KEY = "WALKTHROUGH_LOADED_LISTENER_KEY";
private static String WALKTHROUGH_LOADED_VALUE = "walkthroughLoaded";
private static String WALKTHROUGH_PRESENTED_KEY = "WALKTHROUGH_PRESENTED_LISTENER_KEY";
private static String WALKTHROUGH_PRESENTED_VALUE = "walkthroughPresented";
private static String WALKTHROUGH_HIDDEN_KEY = "WALKTHROUGH_HIDDEN_LISTENER_KEY";
private static String WALKTHROUGH_HIDDEN_VALUE = "walkthroughHidden";
private static final String URL = "url";
private static final String OPEN_URL_KEY = "URL_ACTION_LISTENER_KEY";
private static final String DEEP_LINK_KEY = "DEEPLINK_ACTION_LISTENER_KEY";
private static final String OPEN_URL_VALUE = "openUrl";
private static final String DEEP_LINK = "deepLink";
private static final String DEEP_LINK_VALUE = "deepLink";
private static final String BANNER_PRESENTED_KEY = "BANNER_PRESENTED_LISTENER_KEY";
private static final String BANNER_HIDDEN_KEY = "BANNER_HIDDEN_LISTENER_KEY";
private static final String BANNER_PRESENTED_VALUE = "bannerPresented";
private static final String BANNER_HIDDEN_VALUE = "bannerClosed";
private static final String WALKTHROUGH_LOADING_ERROR_KEY = "WALKTHROUGH_LOADING_ERROR_LISTENER_KEY";
private static final String WALKTHROUGH_LOADING_ERROR_VALUE = "walkthroughLoadingError";
private static final String WALKTHROUGH_LOADED_KEY = "WALKTHROUGH_LOADED_LISTENER_KEY";
private static final String WALKTHROUGH_LOADED_VALUE = "walkthroughLoaded";
private static final String WALKTHROUGH_PRESENTED_KEY = "WALKTHROUGH_PRESENTED_LISTENER_KEY";
private static final String WALKTHROUGH_PRESENTED_VALUE = "walkthroughPresented";
private static final String WALKTHROUGH_HIDDEN_KEY = "WALKTHROUGH_HIDDEN_LISTENER_KEY";
private static final String WALKTHROUGH_HIDDEN_VALUE = "walkthroughHidden";
private static final String IN_APP_MESSAGE_PRESENTED_LISTENER_KEY = "IN_APP_MESSAGE_PRESENTED_LISTENER_KEY";
private static final String IN_APP_MESSAGE_HIDDEN_LISTENER_KEY = "IN_APP_MESSAGE_HIDDEN_LISTENER_KEY";
private static final String IN_APP_MESSAGE_URL_ACTION_LISTENER_KEY = "IN_APP_MESSAGE_URL_ACTION_LISTENER_KEY";
private static final String IN_APP_MESSAGE_DEEPLINK_ACTION_LISTENER_KEY = "IN_APP_MESSAGE_DEEPLINK_ACTION_LISTENER_KEY";
private static final String IN_APP_MESSAGE_CUSTOM_ACTION_LISTENER_KEY = "IN_APP_MESSAGE_CUSTOM_ACTION_LISTENER_KEY";
private static final String IN_APP_MESSAGE_PRESENTED_LISTENER_VALUE = "inAppPresented";
private static final String IN_APP_MESSAGE_HIDDEN_LISTENER_VALUE = "inAppHidden";
private static final String IN_APP_MESSAGE_URL_ACTION_LISTENER_VALUE = "inAppUrlAction";
private static final String IN_APP_MESSAGE_DEEPLINK_ACTION_LISTENER_VALUE = "inAppDeepLinkAction";
private static final String IN_APP_MESSAGE_CUSTOM_ACTION_LISTENER_VALUE = "inAppCustomAction";
private static Boolean shouldBannerPresentFlag = false;
private Gson gson = new Gson();

Expand Down Expand Up @@ -79,56 +94,8 @@ public boolean isLoadedWalkthroughUnique() {
}

@ReactMethod
public void setShouldBannerPresentFlag(Boolean shouldBannerPresentFlag) {
this.shouldBannerPresentFlag = shouldBannerPresentFlag;
}

@ReactMethod
public void fetchBanners(Callback callback) {
Injector.fetchBanners(new DataActionListener<List<TemplateBanner>>() {
@Override
public void onDataAction(List<TemplateBanner> templateBanners) {
WritableArray array = Arguments.createArray();
for (TemplateBanner banner : templateBanners) {
try {
String jsonObject = gson.toJson(banner);
WritableMap objectMap = convertJsonToMap(new JSONObject(jsonObject));
array.pushMap(objectMap);
} catch (JSONException e) {
e.printStackTrace();
}
}
executeSuccessCallbackResponse(callback, array, null);
}
}, new DataActionListener<ApiError>() {
@Override
public void onDataAction(ApiError apiError) {
executeFailureCallbackResponse(callback, null, apiError);
}
});
}

@ReactMethod(isBlockingSynchronousMethod = true)
public WritableArray getBanners() {
List<TemplateBanner> bannerList = Injector.getBanners();
WritableArray array = Arguments.createArray();
for (TemplateBanner banner : bannerList) {
try {
String jsonObject = gson.toJson(banner);
WritableMap objectMap = convertJsonToMap(new JSONObject(jsonObject));
array.pushMap(objectMap);
} catch (JSONException e) {
e.printStackTrace();
}
}
return array;
}

@ReactMethod
public void showBanner(ReadableMap bannerObject, Boolean markPresented) {
String bannerJson = readableMapToJson(bannerObject);
TemplateBanner banner = TemplateBanner.fromJson(bannerJson, new Gson());
Injector.showBanner(banner, markPresented);
public void setBannerShouldPresentFlag(boolean flag) {
shouldBannerPresentFlag = flag;
}

@Nullable
Expand All @@ -143,6 +110,11 @@ public Map<String, Object> getConstants() {
constants.put(WALKTHROUGH_PRESENTED_KEY, WALKTHROUGH_PRESENTED_VALUE);
constants.put(WALKTHROUGH_LOADED_KEY, WALKTHROUGH_LOADED_VALUE);
constants.put(WALKTHROUGH_HIDDEN_KEY, WALKTHROUGH_HIDDEN_VALUE);
constants.put(IN_APP_MESSAGE_PRESENTED_LISTENER_KEY, IN_APP_MESSAGE_PRESENTED_LISTENER_VALUE);
constants.put(IN_APP_MESSAGE_HIDDEN_LISTENER_KEY, IN_APP_MESSAGE_HIDDEN_LISTENER_VALUE);
constants.put(IN_APP_MESSAGE_URL_ACTION_LISTENER_KEY, IN_APP_MESSAGE_URL_ACTION_LISTENER_VALUE);
constants.put(IN_APP_MESSAGE_DEEPLINK_ACTION_LISTENER_KEY, IN_APP_MESSAGE_DEEPLINK_ACTION_LISTENER_VALUE);
constants.put(IN_APP_MESSAGE_CUSTOM_ACTION_LISTENER_KEY, IN_APP_MESSAGE_CUSTOM_ACTION_LISTENER_VALUE);
return constants;
}

Expand All @@ -153,6 +125,7 @@ public String getName() {
}

protected static void initializeInjector() {
initializeInAppListener();
initializeActionInjectorListener();
initializeBannerListener();
initializeWalkthroughListener();
Expand Down Expand Up @@ -186,6 +159,99 @@ public boolean onDeepLink(InjectorSource injectorSource, String deepLink) {
});
}

private static void initializeInAppListener() {
Injector.setOnInAppListener(new OnInAppListener() {
@Override
public boolean shouldShow(InAppMessageData inAppMessageData) {
return true;
}

@Override
public void onShown(InAppMessageData inAppMessageData) {
onInAppPresented(inAppMessageData);
}

@Override
public void onDismissed(InAppMessageData inAppMessageData) {
onInAppHidden(inAppMessageData);
}

@Override
public void onHandledOpenUrl(InAppMessageData inAppMessageData) {
onInAppMessageOpenUrl(inAppMessageData);
}

@Override
public void onHandledOpenDeepLink(InAppMessageData inAppMessageData) {
onInAppMessageDeepLink(inAppMessageData);
}

@Override
public HashMap<String, Object> onContextFromAppRequired(InAppMessageData inAppMessageData) {
return null;
}

@Override
public void onCustomAction(String identifier, HashMap<String, Object> params, InAppMessageData inAppMessageData) {
onInAppCustomAction(identifier, params, inAppMessageData);
}
});
}

private static void onInAppPresented(InAppMessageData inAppMessageData) {
WritableMap objectToJs = Arguments.createMap();
WritableMap data = Arguments.createMap();
data.putString("campaignHash", inAppMessageData.getCampaignHash());
data.putString("variantIdentifier", inAppMessageData.getVariantId());
data.putMap("additionalParameters", MapUtil.toWritableMap(inAppMessageData.getAdditionalParameters()));
objectToJs.putMap("data", data);
sendEventToJs(IN_APP_MESSAGE_PRESENTED_LISTENER_VALUE, objectToJs, reactApplicationContext);
}

private static void onInAppHidden(InAppMessageData inAppMessageData) {
WritableMap objectToJs = Arguments.createMap();
WritableMap data = Arguments.createMap();
data.putString("campaignHash", inAppMessageData.getCampaignHash());
data.putString("variantIdentifier", inAppMessageData.getVariantId());
data.putMap("additionalParameters", MapUtil.toWritableMap(inAppMessageData.getAdditionalParameters()));
objectToJs.putMap("data", data);
sendEventToJs(IN_APP_MESSAGE_HIDDEN_LISTENER_VALUE, objectToJs, reactApplicationContext);
}

private static void onInAppMessageOpenUrl(InAppMessageData inAppMessageData) {
WritableMap objectToJs = Arguments.createMap();
WritableMap data = Arguments.createMap();
data.putString("campaignHash", inAppMessageData.getCampaignHash());
data.putString("variantIdentifier", inAppMessageData.getVariantId());
data.putMap("additionalParameters", MapUtil.toWritableMap(inAppMessageData.getAdditionalParameters()));
objectToJs.putMap("data", data);
objectToJs.putString("url", inAppMessageData.getUrl());
sendEventToJs(IN_APP_MESSAGE_URL_ACTION_LISTENER_VALUE, objectToJs, reactApplicationContext);
}

private static void onInAppMessageDeepLink(InAppMessageData inAppMessageData) {
WritableMap objectToJs = Arguments.createMap();
WritableMap data = Arguments.createMap();
data.putString("campaignHash", inAppMessageData.getCampaignHash());
data.putString("variantIdentifier", inAppMessageData.getVariantId());
data.putMap("additionalParameters", MapUtil.toWritableMap(inAppMessageData.getAdditionalParameters()));
objectToJs.putMap("data", data);
objectToJs.putString("deepLink", inAppMessageData.getDeepLink());
sendEventToJs(IN_APP_MESSAGE_DEEPLINK_ACTION_LISTENER_VALUE, objectToJs, reactApplicationContext);
}

private static void onInAppCustomAction(String identifier, HashMap<String, Object> params, InAppMessageData inAppMessageData) {
WritableMap objectToJs = Arguments.createMap();
WritableMap data = Arguments.createMap();
data.putString("campaignHash", inAppMessageData.getCampaignHash());
data.putString("variantIdentifier", inAppMessageData.getVariantId());
data.putMap("additionalParameters", MapUtil.toWritableMap(inAppMessageData.getAdditionalParameters()));
objectToJs.putMap("data", objectToJs);
objectToJs.putString("name", identifier);
objectToJs.putMap("parameters", MapUtil.toWritableMap(params));
sendEventToJs(IN_APP_MESSAGE_CUSTOM_ACTION_LISTENER_VALUE, objectToJs, reactApplicationContext);
}

private static void initializeBannerListener() {
Injector.setOnBannerListener(new OnBannerListener() {

Expand Down
21 changes: 19 additions & 2 deletions android/src/main/java/com/synerise/sdk/react/RNSettings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.synerise.sdk.react;

import android.util.Log;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
Expand Down Expand Up @@ -28,6 +30,8 @@ public class RNSettings extends RNBaseModule {
public static final String RN_SETTINGS_NOTIFICATIONS_ENABLED = "NOTIFICATIONS_ENABLED";
public static final String RN_SETTINGS_NOTIFICATIONS_ENCRYPTION = "NOTIFICATIONS_ENCRYPTION";
public static final String RN_SETTINGS_INJECTOR_AUTOMATIC = "INJECTOR_AUTOMATIC";
public static final String RN_SETTINGS_IN_APP_MAX_DEFINITION_UPDATE_INTERVAL_LIMIT = "IN_APP_MAX_DEFINITION_UPDATE_INTERVAL_LIMIT";
public static final String RN_SETTINGS_IN_APP_MESSAGING_RENDERING_TIMEOUT = "IN_APP_MESSAGING_RENDERING_TIMEOUT";

public RNSettings(ReactApplicationContext reactApplicationContext) {
super(reactApplicationContext);
Expand All @@ -53,6 +57,8 @@ public Map<String, Object> getConstants() {
constants.put(RN_SETTINGS_NOTIFICATIONS_ENABLED, RN_SETTINGS_NOTIFICATIONS_ENABLED);
constants.put(RN_SETTINGS_NOTIFICATIONS_ENCRYPTION, RN_SETTINGS_NOTIFICATIONS_ENCRYPTION);
constants.put(RN_SETTINGS_SHOULD_DESTROY_SESSION_ON_API_KEY_CHANGE, RN_SETTINGS_SHOULD_DESTROY_SESSION_ON_API_KEY_CHANGE);
constants.put(RN_SETTINGS_IN_APP_MAX_DEFINITION_UPDATE_INTERVAL_LIMIT, RN_SETTINGS_IN_APP_MAX_DEFINITION_UPDATE_INTERVAL_LIMIT);
constants.put(RN_SETTINGS_IN_APP_MESSAGING_RENDERING_TIMEOUT, RN_SETTINGS_IN_APP_MESSAGING_RENDERING_TIMEOUT);
return constants;
}

Expand Down Expand Up @@ -123,7 +129,7 @@ private void matchSetting(String key, Object value) {
}
case RN_SETTINGS_TRACKER_AUTO_FLUSH_TIMEOUT:
if (value instanceof Integer) {
Settings.getInstance().tracker.setAutoFlushTimeout((int) value);
Settings.getInstance().tracker.setAutoFlushTimeout(((int) value) * 1000);
}
break;
case RN_SETTINGS_TRACKER_MAX_BATCH_SIZE:
Expand Down Expand Up @@ -156,6 +162,15 @@ private void matchSetting(String key, Object value) {
Settings.getInstance().sdk.shouldDestroySessionOnApiKeyChange = (Boolean) value;
}
break;
case RN_SETTINGS_IN_APP_MAX_DEFINITION_UPDATE_INTERVAL_LIMIT:
if (value instanceof Integer) {
Settings.getInstance().inAppMessaging.setMaxDefinitionUpdateIntervalLimit((int) value);
}

case RN_SETTINGS_IN_APP_MESSAGING_RENDERING_TIMEOUT:
if (value instanceof Integer) {
Settings.getInstance().inAppMessaging.renderingTimeout = ((int) value) * 1000;
}
}
}

Expand All @@ -166,11 +181,13 @@ private Map<String, Object> settingsDictionary() {
settings.put(RN_SETTINGS_TRACKER_IS_BACKEND_TIME_SYNC_REQUIRED, Synerise.settings.tracker.isBackendTimeSyncRequired);
settings.put(RN_SETTINGS_TRACKER_MIN_BATCH_SIZE, Synerise.settings.tracker.minBatchSize);
settings.put(RN_SETTINGS_TRACKER_MAX_BATCH_SIZE, Synerise.settings.tracker.maxBatchSize);
settings.put(RN_SETTINGS_TRACKER_AUTO_FLUSH_TIMEOUT, Synerise.settings.tracker.autoFlushTimeout);
settings.put(RN_SETTINGS_TRACKER_AUTO_FLUSH_TIMEOUT, Synerise.settings.tracker.autoFlushTimeout / 1000);
settings.put(RN_SETTINGS_INJECTOR_AUTOMATIC, Synerise.settings.injector.automatic);
settings.put(RN_SETTINGS_NOTIFICATIONS_ENABLED, Synerise.settings.notifications.enabled);
settings.put(RN_SETTINGS_NOTIFICATIONS_ENCRYPTION, Synerise.settings.notifications.getEncryption());
settings.put(RN_SETTINGS_SHOULD_DESTROY_SESSION_ON_API_KEY_CHANGE, Synerise.settings.sdk.shouldDestroySessionOnApiKeyChange);
settings.put(RN_SETTINGS_IN_APP_MESSAGING_RENDERING_TIMEOUT, Synerise.settings.inAppMessaging.renderingTimeout / 1000);
settings.put(RN_SETTINGS_IN_APP_MAX_DEFINITION_UPDATE_INTERVAL_LIMIT, Synerise.settings.inAppMessaging.getMaxDefinitionUpdateIntervalLimit());
return settings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;

import com.synerise.sdk.core.Synerise;
import com.synerise.sdk.core.types.enums.HostApplicationType;

Expand All @@ -26,6 +27,7 @@ public void initialize(Application app) {
.hostApplicationType(HostApplicationType.REACT_NATIVE)
.build();

// Client.registerForPushCallback(RNNotifications.getNativePushListener());
isInitialized = true;
}
}
Expand Down
Loading

0 comments on commit e95fbb8

Please sign in to comment.