Skip to content

Commit

Permalink
Merge pull request #279 from CleverTap/develop
Browse files Browse the repository at this point in the history
Update master with release 3.0.0
  • Loading branch information
CTLalit authored Dec 19, 2024
2 parents aa5530c + e9010f7 commit 1cd0fd8
Show file tree
Hide file tree
Showing 40 changed files with 4,279 additions and 2,054 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
## CHANGE LOG

Version 3.0.0 *(19 December 2024)*
-------------------------------------------
**What's new**
* **[Android Platform]**
* Supports [CleverTap Android SDK v7.0.3](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTCORECHANGELOG.md#version-703-november-29-2024).
* Adds support for custom handshake domain configuration in android manifest.

* **[iOS Platform]**
* Supports [CleverTap iOS SDK v7.0.3](https://github.com/CleverTap/clevertap-ios-sdk/blob/master/CHANGELOG.md#version-703-november-29-2024).
* Adds support for custom handshake domains.

* **[Android and iOS Platform]**
* Adds support for File Type Variables in Remote Config. Please refer to the [Remote Config Variables](https://github.com/CleverTap/clevertap-ios-sdk/blob/master/docs/Variables.md) doc to read more on how to integrate this in your app.
* Adds support for Custom Code Templates. Please refer to the [CustomCodeTemplates.md](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CustomCodeTemplates.md) doc to read more on how to integrate this in your app.
* Adds support for custom code in-app templates definitions through a json scheme.

**Bug Fixes**
* **[Android Platform]**
* Fixes [#275](https://github.com/CleverTap/clevertap-flutter/issues/275) - Fixes NPE when casting object to string for PN clicked event.

### Version 2.5.0 *(17th October 2024)*
-------------------------------------------
**What's new**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To get started, sign up [here](https://clevertap.com/live-product-demo/).

```yaml
dependencies:
clevertap_plugin: 2.5.0
clevertap_plugin: 3.0.0
```
- Run `flutter packages get` to install the SDK
Expand Down
65 changes: 44 additions & 21 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
plugins {
id "com.android.library"
}
group = 'com.clevertap.clevertap_plugin'
version = '3.0.0'

group 'com.clevertap.clevertap_plugin'
version '2.5.0'
buildscript {
ext.kotlin_version = "1.8.22"
repositories {
google()
mavenCentral()
}

dependencies {
classpath("com.android.tools.build:gradle:8.1.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
}

rootProject.allprojects {
repositories {
Expand All @@ -15,28 +24,42 @@ rootProject.allprojects {
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"

android {
compileSdkVersion 34
if (project.android.hasProperty("namespace")) {
namespace 'com.clevertap.clevertap_plugin'
namespace = "com.clevertap.clevertap_plugin"
}

defaultConfig {
minSdkVersion 19
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
compileSdk = 34

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
lintOptions {
disable 'InvalidPackage'

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8

sourceSets {
main.java.srcDirs += "src/main/kotlin"
test.java.srcDirs += "src/test/kotlin"
}
}

dependencies {
testImplementation 'junit:junit:4.13.2'
api 'com.clevertap.android:clevertap-android-sdk:7.0.1'
compileOnly 'androidx.fragment:fragment:1.3.6'
compileOnly 'androidx.core:core:1.9.0'
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
testImplementation 'junit:junit:4.13.2'
api 'com.clevertap.android:clevertap-android-sdk:7.0.3'
compileOnly 'androidx.fragment:fragment:1.3.6'
compileOnly 'androidx.core:core:1.9.0'
}
}
11 changes: 0 additions & 11 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
pluginManagement {
repositories {
google()
mavenCentral()
}
}

plugins {
id("com.android.library").version("8.3.0").apply(false)
}

rootProject.name = 'clevertap_plugin'
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class CleverTapApplication extends FlutterApplication implements CTPushNo
@Override
public void onCreate() {
super.onCreate();

CleverTapAPI cleverTapAPI = CleverTapAPI.getDefaultInstance(this);
if (cleverTapAPI != null) {
cleverTapAPI.setCTPushNotificationListener(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.clevertap.clevertap_plugin

enum class CleverTapEvent(
val eventName: String,
val bufferable: Boolean = false
) {

CLEVERTAP_PROFILE_DID_INITIALIZE("CleverTapProfileDidInitialize", bufferable = true),
CLEVERTAP_PROFILE_SYNC("CleverTapProfileSync"),
CLEVERTAP_IN_APP_NOTIFICATION_DISMISSED("CleverTapInAppNotificationDismissed", bufferable = true),
CLEVERTAP_IN_APP_NOTIFICATION_BEFORE_SHOW("CleverTapInAppNotificationBeforeShow", bufferable = true),
CLEVERTAP_IN_APP_NOTIFICATION_SHOWED("CleverTapInAppNotificationShowed", bufferable = true),
CLEVERTAP_INBOX_DID_INITIALIZE("CleverTapInboxDidInitialize", bufferable = true),
CLEVERTAP_INBOX_MESSAGES_DID_UPDATE("CleverTapInboxMessagesDidUpdate"),
CLEVERTAP_ON_INBOX_BUTTON_CLICK("CleverTapInboxMessageButtonTapped"),
CLEVERTAP_ON_INBOX_MESSAGE_CLICK("CleverTapInboxMessageTapped"),
CLEVERTAP_ON_INAPP_BUTTON_CLICK("CleverTapInAppNotificationButtonTapped", bufferable = true),
CLEVERTAP_ON_DISPLAY_UNITS_LOADED("CleverTapDisplayUnitsLoaded", bufferable = true),
CLEVERTAP_FEATURE_FLAGS_DID_UPDATE("CleverTapFeatureFlagsDidUpdate", bufferable = true),
CLEVERTAP_PRODUCT_CONFIG_DID_INITIALIZE("CleverTapProductConfigDidInitialize", bufferable = true),
CLEVERTAP_PRODUCT_CONFIG_DID_FETCH("CleverTapProductConfigDidFetch"),
CLEVERTAP_PRODUCT_CONFIG_DID_ACTIVATE("CleverTapProductConfigDidActivate"),
CLEVERTAP_PUSH_NOTIFICATION_CLICKED("CleverTapPushNotificationClicked", bufferable = true),
CLEVERTAP_ON_PUSH_PERMISSION_RESPONSE("CleverTapPushPermissionResponseReceived"),
CLEVERTAP_ON_PUSH_AMP_PAYLOAD_RECEIVED("CleverTapPushAmpPayloadReceived", bufferable = true),
CLEVERTAP_ON_VARIABLES_CHANGED("CleverTapOnVariablesChanged"),
CLEVERTAP_ON_ONE_TIME_VARIABLES_CHANGED("CleverTapOnOneTimeVariablesChanged"),
CLEVERTAP_ON_VALUE_CHANGED("CleverTapOnValueChanged"),
CLEVERTAP_CUSTOM_TEMPLATE_PRESENT("CleverTapCustomTemplatePresent", bufferable = true),
CLEVERTAP_CUSTOM_FUNCTION_PRESENT("CleverTapCustomFunctionPresent", bufferable = true),
CLEVERTAP_CUSTOM_TEMPLATE_CLOSE("CleverTapCustomTemplateClose"),
CLEVERTAP_ON_FILE_VALUE_CHANGED("CleverTapOnFileValueChanged"),
CLEVERTAP_ON_VARIABLES_CHANGED_AND_NO_DOWNLOADS_PENDING("CleverTapOnVariablesChangedAndNoDownloadsPending"),
CLEVERTAP_ONCE_VARIABLES_CHANGED_AND_NO_DOWNLOADS_PENDING("CleverTapOnceVariablesChangedAndNoDownloadsPending"),
CLEVERTAP_UNKNOWN("CleverTapUnknown");

override fun toString(): String {
return eventName
}

companion object {

@JvmStatic
fun fromName(eventName: String): CleverTapEvent {
return values().find { it.eventName == eventName } ?: CLEVERTAP_UNKNOWN
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.clevertap.clevertap_plugin

import android.util.Log
import com.clevertap.clevertap_plugin.CleverTapPlugin.invokeMethodOnUiThread
import java.util.LinkedList
import java.util.Queue

/**
* CleverTapEventEmitter is responsible for emitting events to the React Native JavaScript layer.
* It manages event buffers and allows events to be queued which is useful when needing to send an
* event while the ReactContext of the application is not yet initialized. Only events specified as
* [CleverTapEvent.bufferable] will be considered for buffering, all other events will be emitted
* immediately.
*/
object CleverTapEventEmitter {
private const val LOG_TAG = "CleverTapEventEmitter"

private var eventsBuffers: Map<CleverTapEvent, Buffer> = createBuffersMap(enableBuffers = true)

/**
* Enable buffering for the specified event. While enabled, all events which should be emitted
* will be added to the buffer. Only buffers for events specified as [CleverTapEvent.bufferable]
* can be enabled.
*
* @see [disableBuffer]
*/
@JvmStatic
fun enableBuffer(event: CleverTapEvent) {
eventsBuffers[event]?.enabled = true
}

/**
* Disable buffering for the specified event. This will only have effect for events specified as
* [CleverTapEvent.bufferable].
*
* @see [enableBuffer]
*/
@JvmStatic
fun disableBuffer(event: CleverTapEvent) {
eventsBuffers[event]?.enabled = false
}

/**
* Clear all the buffered events from all buffers and set whether all buffers should be enabled
* after that.
*
* @param enableBuffers enable/disable all buffers after they are cleared
*/
@JvmStatic
fun resetAllBuffers(enableBuffers: Boolean) {
eventsBuffers = createBuffersMap(enableBuffers)
Log.i(LOG_TAG, "Buffers reset and enabled: $enableBuffers")
}

/**
* Emit all currently buffered events for the specified event name.
*/
@JvmStatic
fun flushBuffer(event: CleverTapEvent) {
val buffer = eventsBuffers[event] ?: return
while (buffer.size() > 0) {
val params = buffer.remove()
sendEvent(event, params)
}
}

@JvmStatic
fun enableAll() {
eventsBuffers.forEach { pair ->
pair.value.enabled = true
}
}

@JvmStatic
fun disableAllAndFlush() {
eventsBuffers.forEach { pair ->
flushBuffer(pair.key)
pair.value.enabled = false
}
}

/**
* Emit an event with specified params. It will be buffered if buffering for the event is enabled or
* it will be send immediately otherwise.
*
* @param event The event to be emitted
* @param params Optional event parameters
*
* @see [enableBuffer]
* @see [disableBuffer]
*/
@JvmStatic
fun emit(event: CleverTapEvent, params: Any?) {
if (eventsBuffers[event]?.enabled == true) {
addToBuffer(event, params)
} else {
sendEvent(event, params)
}
}

/**
* Adds an event to the buffer for future emission.
* Events will remain in the buffer until [flushBuffer] for the same event name is called.
*
* @param event The event to be buffered.
* @param params Optional event parameters to be sent when the event is emitted.
*/
private fun addToBuffer(event: CleverTapEvent, params: Any?) {
val buffer = eventsBuffers[event] ?: return
buffer.add(params)
Log.i(LOG_TAG, "Event $event added to buffer.")
}

private fun sendEvent(
event: CleverTapEvent,
params: Any?
) {
try {
if (event == CleverTapEvent.CLEVERTAP_UNKNOWN) {
Log.i(LOG_TAG, "Not Sending event since its unknown")
return
}
invokeMethodOnUiThread(
EventNameMapper.fromCleverTapEvent(event),
params
)
Log.i(LOG_TAG, "Sending event $event")
} catch (t: Throwable) {
Log.e(LOG_TAG, "Sending event $event failed", t)
}
}

private fun createBuffersMap(enableBuffers: Boolean) =
CleverTapEvent.values().filter { it.bufferable }.associateWith {
Buffer(enabled = enableBuffers)
}
}

private class Buffer(var enabled: Boolean) {
private val items: Queue<Any?> by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { LinkedList() }

fun add(item: Any?) = items.add(item)
fun remove(): Any? = items.remove()
fun size(): Int = items.size
}
Loading

0 comments on commit 1cd0fd8

Please sign in to comment.