Skip to content

Blueprint Support #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 25 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1b39f27
Refactored for blueprint support.
simonbullen May 16, 2025
180ad68
Added BlueprintSharedInstance()
simonbullen May 16, 2025
2789742
Removed test code.
simonbullen May 16, 2025
f98fd4e
Removed test code.
simonbullen May 16, 2025
1924694
Restored old fallback instance behaviour
simonbullen May 18, 2025
43f9427
Dynamic multicast delegates for blueprint compatability
simonbullen May 19, 2025
c5ccc7a
CleverTapProperties blueprint support
simonbullen May 20, 2025
84a18b7
AndroidLocalCleverTapSdkAarPath
simonbullen May 23, 2025
78a3e29
Added rules for proguard/R8 minifaction support.
simonbullen May 26, 2025
999c9b7
Merge branch 'local-android-sdk' into blueprint-basics
simonbullen May 26, 2025
5052469
Better UCleverTapSubsystem DisplayName
simonbullen May 26, 2025
a188c20
FCleverTapProperties UObject methods now log invalid input
simonbullen May 26, 2025
1394753
FCleverTapProperties blueprint support; FCleverTapDate blueprint support
simonbullen May 27, 2025
4835724
blueprint api metadata tweak
simonbullen May 27, 2025
08c9656
UCleverTapSubsystemBlueprintLibrary::SharedCleverTapInstance() for co…
simonbullen May 27, 2025
2542f75
formatting
simonbullen May 27, 2025
64e9c06
UCleverTapPushPrimerAlertConfigAsset and UCleverTapPushPrimerHalfInte…
simonbullen May 27, 2025
f29ee6c
Merge branch 'dev' into blueprint-basics
simonbullen May 28, 2025
3d6048f
FCleverTapDate properties now BlueprintReadWrite
simonbullen May 28, 2025
3e6e3b5
Added FCleverTapPropertyValue::ToString()
simonbullen May 29, 2025
a7dd374
Removed JavaStringArrayToString()
simonbullen May 29, 2025
d310782
Warning logs for ApplyCleverTapPropertyValueToStruct() unsupported ty…
simonbullen May 29, 2025
7a6f9cf
BlueprintSharedInstance() will now return NullCleverTapInstance inste…
simonbullen May 29, 2025
4fcec40
cleanup
simonbullen May 29, 2025
8647ffb
For both FCleverTapInstance & FCleverTapProperties: -
simonbullen May 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright CleverTap All Rights Reserved.
#pragma once

#include "CleverTapInstance.h"

#include "Android/AndroidApplication.h"
#include "AndroidCleverTapInstance.generated.h"

/**
* The Android implementation of UCleverTapInstance
*/
UCLASS(NotBlueprintable)
class CLEVERTAP_API UAndroidCleverTapInstance : public UCleverTapInstance
{
GENERATED_BODY()

// Most execution happens on the main game thread, but JNI callbacks can come from arbitrary threads.
// This critical section is used to co-ordinate access to the set of instances and their InAppNotificationFilters.
static FCriticalSection CriticalSection;
static TSet<UAndroidCleverTapInstance*> Instances;

// per-instance data
jobject JavaCleverTapInstance;
bool bEnableOnPushNotificationClicked = false;
TOptional<FCleverTapProperties> BufferedPushNotificationPayload;
TUniqueFunction<bool(const FCleverTapProperties&)> InAppNotificationFilter = [](const FCleverTapProperties&) {
return true;
};

void Initialize(JNIEnv* Env, jobject JavaCleverTapInstanceIn);
~UAndroidCleverTapInstance();

public:
/* Creates a new UAndroidCleverTapInstance to wrap the provided Java CleverTapSDK instance
*/
static UAndroidCleverTapInstance* Create(JNIEnv* Env, jobject JavaCleverTapInstanceIn);

/** Converts a raw NativeInstancePtr to either a valid FAndroidCleverTapInstance* or a nullptr.
*/
static UAndroidCleverTapInstance* CheckedInstancePtr(jlong NativeInstancePtr);

/** Returns true if the given Instance currently exists. */
static bool IsValid(const UAndroidCleverTapInstance* Instance) { return Instances.Contains(Instance); }

// Notification Handlers
// =====================================
static void BroadcastOnPushPermissionResponse(jlong NativeInstancePtr, bool bGranted);
static void BroadcastOnPushNotificationClicked(
jlong NativeInstancePtr, const FCleverTapProperties& NotificationProperties);
void BroadcastOnPushNotificationClicked(const FCleverTapProperties& NotificationProperties);

static bool BeforeShowInAppNotification(jlong NativeInstancePtr, const FCleverTapProperties& Extras);
static void BroadcastOnInAppNotificationShown(jlong NativeInstancePtr, const FCleverTapProperties& Payload);
static void BroadcastOnInAppNotificationDismissed(
jlong NativeInstancePtr, const FCleverTapProperties& Extras, const FCleverTapProperties& ActionExtras);
static void BroadcastOnInAppNotificationButtonClicked(
jlong NativeInstancePtr, const FCleverTapProperties& ButtonProperties);

static void BroadcastOnOpenUrl(const FString& Url);

// UCleverTapInstance Methods
// =====================================
FString GetCleverTapId() override;

void OnUserLogin(const FCleverTapProperties& Profile) override;
void OnUserLoginWithCleverTapId(const FCleverTapProperties& Profile, const FString& CleverTapId) override;

void PushProfile(const FCleverTapProperties& Profile) override;

void PushEvent(const FString& EventName) override;
void PushEventWithProperties(const FString& EventName, const FCleverTapProperties& Actions) override;
void PushChargedEvent(
const FCleverTapProperties& ChargeDetails, const TArray<FCleverTapProperties>& Items) override;

TOptional<FCleverTapPropertyValue> GetProperty(const FString& Key) override;

void DecrementIntValue(const FString& Key, int Amount) override;
void DecrementFloatValue(const FString& Key, float Amount) override;

void IncrementIntValue(const FString& Key, int Amount) override;
void IncrementFloatValue(const FString& Key, float Amount) override;

void AddMultiValueForKey(const FString& Key, const FString& Value) override;
void AddMultiValuesForKey(const FString& Key, const TArray<FString>& Values) override;
void RemoveMultiValueForKey(const FString& Key, const FString& Value) override;
void RemoveMultiValuesForKey(const FString& Key, const TArray<FString>& Values) override;
void RemoveValueForKey(const FString& Key) override;
void SetMultiValuesForKey(const FString& Key, const TArray<FString> Values) override;

ECleverTapPushPermissionStatus GetPushPermissionStatus() override;
void PromptForPushPermission(bool bFallbackToSettings) override;
void PromptForPushPermissionWithAlertPrimer(const FCleverTapPushPrimerAlertConfig& PushPrimerAlertConfig) override;
void PromptForPushPermissionWithHalfInterstitialPrimer(
const FCleverTapPushPrimerHalfInterstitialConfig& PushPrimerHalfInterstitialConfig) override;

void EnableOnPushNotificationClicked() override;
void EnableOnOpenUrl() override;

bool LocalizeAndroidNotificationChannel(
const FString& ChannelID, const FText& ChannelName, const FText& ChannelDescription) override;

bool LocalizeAndroidNotificationChannelGroup(const FString& GroupID, const FText& GroupName) override;

void RegisterCleverTapUrlHandler(TUniqueFunction<bool(FString, ECleverTapChannel)> UrlHandler) override;

void RegisterInAppNotificationFilter(TUniqueFunction<bool(const FCleverTapProperties&)> Filter) override;

void DiscardInAppNotifications() override;
void ResumeInAppNotifications() override;
void SuspendInAppNotifications() override;

void SetOffline(bool bIsOffline) override;
void SetOptOut(bool bIsOptingOut) override;
void SetNetworkInformationRecording(bool bEnableCollection) override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -902,12 +902,12 @@ jobject CreatePushPrimerConfigJSON(JNIEnv* Env, const FCleverTapPushPrimerAlertC
}

FCleverTapProperties ConfigProperties;
ConfigProperties.Add(TEXT("TitleText"), PrimerConfig.TitleText.ToString());
ConfigProperties.Add(TEXT("MessageText"), PrimerConfig.MessageText.ToString());
ConfigProperties.Add(TEXT("PositiveButtonText"), PrimerConfig.PositiveButtonText.ToString());
ConfigProperties.Add(TEXT("NegativeButtonText"), PrimerConfig.NegativeButtonText.ToString());
ConfigProperties.Add(TEXT("FollowDeviceOrientation"), PrimerConfig.bFollowDeviceOrientation);
ConfigProperties.Add(TEXT("FallbackToSettings"), PrimerConfig.bFallbackToSettings);
ConfigProperties.Map.Add(TEXT("TitleText"), PrimerConfig.TitleText.ToString());
ConfigProperties.Map.Add(TEXT("MessageText"), PrimerConfig.MessageText.ToString());
ConfigProperties.Map.Add(TEXT("PositiveButtonText"), PrimerConfig.PositiveButtonText.ToString());
ConfigProperties.Map.Add(TEXT("NegativeButtonText"), PrimerConfig.NegativeButtonText.ToString());
ConfigProperties.Map.Add(TEXT("FollowDeviceOrientation"), PrimerConfig.bFollowDeviceOrientation);
ConfigProperties.Map.Add(TEXT("FallbackToSettings"), PrimerConfig.bFallbackToSettings);
jobject JavaMap = ConvertCleverTapPropertiesToJavaMap(Env, ConfigProperties);
if (!JavaMap)
{
Expand Down Expand Up @@ -935,23 +935,23 @@ jobject CreatePushPrimerConfigJSON(JNIEnv* Env, const FCleverTapPushPrimerHalfIn
}

FCleverTapProperties ConfigProperties;
ConfigProperties.Add(TEXT("TitleText"), PrimerConfig.TitleText.ToString());
ConfigProperties.Add(TEXT("MessageText"), PrimerConfig.MessageText.ToString());
ConfigProperties.Add(TEXT("PositiveButtonText"), PrimerConfig.PositiveButtonText.ToString());
ConfigProperties.Add(TEXT("NegativeButtonText"), PrimerConfig.NegativeButtonText.ToString());
ConfigProperties.Add(TEXT("FollowDeviceOrientation"), PrimerConfig.bFollowDeviceOrientation);
ConfigProperties.Add(TEXT("FallbackToSettings"), PrimerConfig.bFallbackToSettings);
ConfigProperties.Map.Add(TEXT("TitleText"), PrimerConfig.TitleText.ToString());
ConfigProperties.Map.Add(TEXT("MessageText"), PrimerConfig.MessageText.ToString());
ConfigProperties.Map.Add(TEXT("PositiveButtonText"), PrimerConfig.PositiveButtonText.ToString());
ConfigProperties.Map.Add(TEXT("NegativeButtonText"), PrimerConfig.NegativeButtonText.ToString());
ConfigProperties.Map.Add(TEXT("FollowDeviceOrientation"), PrimerConfig.bFollowDeviceOrientation);
ConfigProperties.Map.Add(TEXT("FallbackToSettings"), PrimerConfig.bFallbackToSettings);
if (PrimerConfig.ImageURL.IsEmpty() == false)
{
ConfigProperties.Add(TEXT("ImageURL"), PrimerConfig.ImageURL);
ConfigProperties.Map.Add(TEXT("ImageURL"), PrimerConfig.ImageURL);
}
ConfigProperties.Add(TEXT("BackgroundColor"), ColorToHexString(PrimerConfig.BackgroundColor));
ConfigProperties.Add(TEXT("ButtonBorderColor"), ColorToHexString(PrimerConfig.ButtonBorderColor));
ConfigProperties.Add(TEXT("TitleTextColor"), ColorToHexString(PrimerConfig.TitleTextColor));
ConfigProperties.Add(TEXT("MessageTextColor"), ColorToHexString(PrimerConfig.MessageTextColor));
ConfigProperties.Add(TEXT("ButtonTextColor"), ColorToHexString(PrimerConfig.ButtonTextColor));
ConfigProperties.Add(TEXT("ButtonBackgroundColor"), ColorToHexString(PrimerConfig.ButtonBackgroundColor));
ConfigProperties.Add(TEXT("ButtonBorderRadius"), PrimerConfig.ButtonBorderRadius);
ConfigProperties.Map.Add(TEXT("BackgroundColor"), ColorToHexString(PrimerConfig.BackgroundColor));
ConfigProperties.Map.Add(TEXT("ButtonBorderColor"), ColorToHexString(PrimerConfig.ButtonBorderColor));
ConfigProperties.Map.Add(TEXT("TitleTextColor"), ColorToHexString(PrimerConfig.TitleTextColor));
ConfigProperties.Map.Add(TEXT("MessageTextColor"), ColorToHexString(PrimerConfig.MessageTextColor));
ConfigProperties.Map.Add(TEXT("ButtonTextColor"), ColorToHexString(PrimerConfig.ButtonTextColor));
ConfigProperties.Map.Add(TEXT("ButtonBackgroundColor"), ColorToHexString(PrimerConfig.ButtonBackgroundColor));
ConfigProperties.Map.Add(TEXT("ButtonBorderRadius"), PrimerConfig.ButtonBorderRadius);

jobject JavaMap = ConvertCleverTapPropertiesToJavaMap(Env, ConfigProperties);
if (!JavaMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ jobject ConvertCleverTapPropertiesToJavaMap(JNIEnv* Env, const FCleverTapPropert
}

// Iterate through Unreal's profile Map
for (const auto& Property : Properties)
for (const auto& Property : Properties.Map)
{
const FString& Key = Property.Key;
const FCleverTapPropertyValue& Value = Property.Value;
Expand Down Expand Up @@ -544,9 +544,9 @@ FCleverTapProperties ConvertJavaMapToCleverTapProperties(JNIEnv* Env, jobject Ja
Env->DeleteLocalRef(JavaValue);

// Add to native Map if unique
if (!Properties.Contains(Key))
if (!Properties.Map.Contains(Key))
{
Properties.Add(Key, Value);
Properties.Map.Add(Key, Value);
}
else
{
Expand Down
Loading