From 62b9e615cbe0c145319d4a5ceb8ab44823b6adb6 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Tue, 14 Nov 2023 16:09:50 +0500 Subject: [PATCH] fix: improve android push click behavior (#89) --- android/build.gradle | 2 +- .../customer/customer_io/CustomerIoPlugin.kt | 11 ++++++++ lib/customer_io_config.dart | 3 +++ lib/customer_io_enums.dart | 26 +++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 515fea4..2b20a81 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -58,7 +58,7 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // Customer.io SDK - def cioVersion = "3.7.0" + def cioVersion = "3.8.0" implementation "io.customer.android:tracking:$cioVersion" implementation "io.customer.android:messaging-push-fcm:$cioVersion" implementation "io.customer.android:messaging-in-app:$cioVersion" diff --git a/android/src/main/kotlin/io/customer/customer_io/CustomerIoPlugin.kt b/android/src/main/kotlin/io/customer/customer_io/CustomerIoPlugin.kt index a6847ac..9d2f950 100644 --- a/android/src/main/kotlin/io/customer/customer_io/CustomerIoPlugin.kt +++ b/android/src/main/kotlin/io/customer/customer_io/CustomerIoPlugin.kt @@ -13,6 +13,7 @@ import io.customer.messaginginapp.type.InAppEventListener import io.customer.messaginginapp.type.InAppMessage import io.customer.messagingpush.MessagingPushModuleConfig import io.customer.messagingpush.ModuleMessagingPushFCM +import io.customer.messagingpush.config.PushClickBehavior import io.customer.sdk.CustomerIO import io.customer.sdk.CustomerIOConfig import io.customer.sdk.CustomerIOShared @@ -280,6 +281,16 @@ class CustomerIoPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { ?.let { value -> setAutoTrackPushEvents(autoTrackPushEvents = value) } + config?.getProperty(CustomerIOConfig.Companion.Keys.PUSH_CLICK_BEHAVIOR_ANDROID) + ?.takeIfNotBlank() + ?.let { value -> + val behavior = kotlin.runCatching { + enumValueOf(value) + }.getOrNull() + if (behavior != null) { + setPushClickBehavior(pushClickBehavior = behavior) + } + } }.build(), ) } diff --git a/lib/customer_io_config.dart b/lib/customer_io_config.dart index b4fcbf9..0f5457a 100644 --- a/lib/customer_io_config.dart +++ b/lib/customer_io_config.dart @@ -12,6 +12,7 @@ class CustomerIOConfig { bool autoTrackPushEvents; int backgroundQueueMinNumberOfTasks; double backgroundQueueSecondsDelay; + PushClickBehaviorAndroid pushClickBehaviorAndroid; bool enableInApp; @@ -29,6 +30,7 @@ class CustomerIOConfig { this.autoTrackPushEvents = true, this.backgroundQueueMinNumberOfTasks = 10, this.backgroundQueueSecondsDelay = 30.0, + this.pushClickBehaviorAndroid = PushClickBehaviorAndroid.activityPreventRestart, this.enableInApp = false, this.version = ""}); @@ -44,6 +46,7 @@ class CustomerIOConfig { 'autoTrackPushEvents': autoTrackPushEvents, 'backgroundQueueMinNumberOfTasks': backgroundQueueMinNumberOfTasks, 'backgroundQueueSecondsDelay': backgroundQueueSecondsDelay, + 'pushClickBehaviorAndroid': pushClickBehaviorAndroid.rawValue, 'enableInApp': enableInApp, 'version': version, 'source': "Flutter" diff --git a/lib/customer_io_enums.dart b/lib/customer_io_enums.dart index 91d73d0..3a62435 100644 --- a/lib/customer_io_enums.dart +++ b/lib/customer_io_enums.dart @@ -9,3 +9,29 @@ enum Region { us, eu } /// Enum to specify the type of metric for tracking enum MetricEvent { delivered, opened, converted, clicked } + +/// Enum to specify the click behavior of push notification for Android +enum PushClickBehaviorAndroid { + resetTaskStack(rawValue: 'RESET_TASK_STACK'), + activityPreventRestart(rawValue: 'ACTIVITY_PREVENT_RESTART'), + activityNoFlags(rawValue: 'ACTIVITY_NO_FLAGS'); + + factory PushClickBehaviorAndroid.fromValue(String value) { + switch (value) { + case 'RESET_TASK_STACK': + return PushClickBehaviorAndroid.resetTaskStack; + case 'ACTIVITY_PREVENT_RESTART': + return PushClickBehaviorAndroid.activityPreventRestart; + case 'ACTIVITY_NO_FLAGS': + return PushClickBehaviorAndroid.activityNoFlags; + default: + throw ArgumentError('Invalid value provided'); + } + } + + const PushClickBehaviorAndroid({ + required this.rawValue, + }); + + final String rawValue; +}