From 03f66e29ec551c332b2ecbbd0272895c56d89e5c Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Thu, 28 Sep 2023 16:27:53 +0500 Subject: [PATCH] refactor: push click behavior rename (#265) --- messagingpush/api/messagingpush.api | 18 +++++++------- .../MessagingPushModuleConfig.kt | 24 ++++++++----------- .../NotificationClickReceiverActivity.kt | 12 +++++----- ...nClickBehavior.kt => PushClickBehavior.kt} | 8 +++---- sdk/api/sdk.api | 1 + .../java/io/customer/sdk/CustomerIOConfig.kt | 1 + 6 files changed, 31 insertions(+), 33 deletions(-) rename messagingpush/src/main/java/io/customer/messagingpush/config/{NotificationClickBehavior.kt => PushClickBehavior.kt} (81%) diff --git a/messagingpush/api/messagingpush.api b/messagingpush/api/messagingpush.api index 572869d75..47b10ccb4 100644 --- a/messagingpush/api/messagingpush.api +++ b/messagingpush/api/messagingpush.api @@ -26,10 +26,10 @@ public final class io/customer/messagingpush/CustomerIOFirebaseMessagingService$ public final class io/customer/messagingpush/MessagingPushModuleConfig : io/customer/sdk/module/CustomerIOModuleConfig { public static final field Companion Lio/customer/messagingpush/MessagingPushModuleConfig$Companion; - public synthetic fun (ZLio/customer/messagingpush/data/communication/CustomerIOPushNotificationCallback;ZLio/customer/messagingpush/config/NotificationClickBehavior;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (ZLio/customer/messagingpush/data/communication/CustomerIOPushNotificationCallback;ZLio/customer/messagingpush/config/PushClickBehavior;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun getAutoTrackPushEvents ()Z public final fun getNotificationCallback ()Lio/customer/messagingpush/data/communication/CustomerIOPushNotificationCallback; - public final fun getNotificationOnClickBehavior ()Lio/customer/messagingpush/config/NotificationClickBehavior; + public final fun getPushClickBehavior ()Lio/customer/messagingpush/config/PushClickBehavior; public final fun getRedirectDeepLinksToOtherApps ()Z } @@ -39,7 +39,7 @@ public final class io/customer/messagingpush/MessagingPushModuleConfig$Builder : public synthetic fun build ()Lio/customer/sdk/module/CustomerIOModuleConfig; public final fun setAutoTrackPushEvents (Z)Lio/customer/messagingpush/MessagingPushModuleConfig$Builder; public final fun setNotificationCallback (Lio/customer/messagingpush/data/communication/CustomerIOPushNotificationCallback;)Lio/customer/messagingpush/MessagingPushModuleConfig$Builder; - public final fun setNotificationClickBehavior (Lio/customer/messagingpush/config/NotificationClickBehavior;)Lio/customer/messagingpush/MessagingPushModuleConfig$Builder; + public final fun setPushClickBehavior (Lio/customer/messagingpush/config/PushClickBehavior;)Lio/customer/messagingpush/MessagingPushModuleConfig$Builder; public final fun setRedirectDeepLinksToOtherApps (Z)Lio/customer/messagingpush/MessagingPushModuleConfig$Builder; } @@ -71,12 +71,12 @@ public final class io/customer/messagingpush/activity/NotificationClickReceiverA public final class io/customer/messagingpush/activity/NotificationClickReceiverActivity$Companion { } -public final class io/customer/messagingpush/config/NotificationClickBehavior : java/lang/Enum { - public static final field ACTIVITY_NO_FLAGS Lio/customer/messagingpush/config/NotificationClickBehavior; - public static final field ACTIVITY_PREVENT_RESTART Lio/customer/messagingpush/config/NotificationClickBehavior; - public static final field RESET_TASK_STACK Lio/customer/messagingpush/config/NotificationClickBehavior; - public static fun valueOf (Ljava/lang/String;)Lio/customer/messagingpush/config/NotificationClickBehavior; - public static fun values ()[Lio/customer/messagingpush/config/NotificationClickBehavior; +public final class io/customer/messagingpush/config/PushClickBehavior : java/lang/Enum { + public static final field ACTIVITY_NO_FLAGS Lio/customer/messagingpush/config/PushClickBehavior; + public static final field ACTIVITY_PREVENT_RESTART Lio/customer/messagingpush/config/PushClickBehavior; + public static final field RESET_TASK_STACK Lio/customer/messagingpush/config/PushClickBehavior; + public static fun valueOf (Ljava/lang/String;)Lio/customer/messagingpush/config/PushClickBehavior; + public static fun values ()[Lio/customer/messagingpush/config/PushClickBehavior; } public abstract interface class io/customer/messagingpush/data/communication/CustomerIOPushNotificationCallback { diff --git a/messagingpush/src/main/java/io/customer/messagingpush/MessagingPushModuleConfig.kt b/messagingpush/src/main/java/io/customer/messagingpush/MessagingPushModuleConfig.kt index a16cf7029..8d7d13240 100644 --- a/messagingpush/src/main/java/io/customer/messagingpush/MessagingPushModuleConfig.kt +++ b/messagingpush/src/main/java/io/customer/messagingpush/MessagingPushModuleConfig.kt @@ -1,35 +1,31 @@ package io.customer.messagingpush -import io.customer.messagingpush.config.NotificationClickBehavior -import io.customer.messagingpush.config.NotificationClickBehavior.ACTIVITY_NO_FLAGS +import io.customer.messagingpush.config.PushClickBehavior +import io.customer.messagingpush.config.PushClickBehavior.ACTIVITY_NO_FLAGS import io.customer.messagingpush.data.communication.CustomerIOPushNotificationCallback import io.customer.sdk.module.CustomerIOModuleConfig /** * Push messaging module configurations - *

- * Please note for apps targeting Android 12 or greater, all other apps and - * browser intents will be opened over host app so that notification metrics - * are not affected * * @property notificationCallback callback to override default sdk behaviour for * notifications * @property redirectDeepLinksToOtherApps flag to support opening urls from * notification to other native apps or browsers; default true - * @property notificationOnClickBehavior defines the behavior when a notification + * @property pushClickBehavior defines the behavior when a push notification * is clicked */ class MessagingPushModuleConfig private constructor( val autoTrackPushEvents: Boolean, val notificationCallback: CustomerIOPushNotificationCallback?, val redirectDeepLinksToOtherApps: Boolean, - val notificationOnClickBehavior: NotificationClickBehavior + val pushClickBehavior: PushClickBehavior ) : CustomerIOModuleConfig { class Builder : CustomerIOModuleConfig.Builder { private var autoTrackPushEvents: Boolean = true private var notificationCallback: CustomerIOPushNotificationCallback? = null private var redirectDeepLinksToOtherApps: Boolean = true - private var notificationOnClickBehavior: NotificationClickBehavior = ACTIVITY_NO_FLAGS + private var pushClickBehavior: PushClickBehavior = ACTIVITY_NO_FLAGS /** * Allows to enable/disable automatic tracking of push events. Auto tracking will generate @@ -71,11 +67,11 @@ class MessagingPushModuleConfig private constructor( /** * Defines the behavior when a notification is clicked. * - * @param notificationOnClickBehavior the behavior when a notification is clicked; default [NotificationClickBehavior.ACTIVITY_PREVENT_RESTART]. - * @see NotificationClickBehavior for more details. + * @param pushClickBehavior the behavior when a notification is clicked; default [PushClickBehavior.ACTIVITY_PREVENT_RESTART]. + * @see PushClickBehavior for more details. */ - fun setNotificationClickBehavior(notificationOnClickBehavior: NotificationClickBehavior): Builder { - this.notificationOnClickBehavior = notificationOnClickBehavior + fun setPushClickBehavior(pushClickBehavior: PushClickBehavior): Builder { + this.pushClickBehavior = pushClickBehavior return this } @@ -84,7 +80,7 @@ class MessagingPushModuleConfig private constructor( autoTrackPushEvents = autoTrackPushEvents, notificationCallback = notificationCallback, redirectDeepLinksToOtherApps = redirectDeepLinksToOtherApps, - notificationOnClickBehavior = notificationOnClickBehavior + pushClickBehavior = pushClickBehavior ) } } diff --git a/messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt b/messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt index 87391b292..8fb42e27a 100644 --- a/messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt +++ b/messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt @@ -5,7 +5,7 @@ import android.content.Intent import android.os.Bundle import androidx.core.app.TaskStackBuilder import io.customer.messagingpush.MessagingPushModuleConfig -import io.customer.messagingpush.config.NotificationClickBehavior +import io.customer.messagingpush.config.PushClickBehavior import io.customer.messagingpush.data.model.CustomerIOParsedPushPayload import io.customer.messagingpush.di.deepLinkUtil import io.customer.messagingpush.di.moduleConfig @@ -113,23 +113,23 @@ class NotificationClickReceiverActivity : Activity(), TrackableScreen { ?: defaultHostAppIntent ?: return deepLinkIntent.putExtra(NOTIFICATION_PAYLOAD_EXTRA, payload) - logger.info("Dispatching notification with link $deepLink to intent: $deepLinkIntent with behavior: ${moduleConfig.notificationOnClickBehavior}") + logger.info("Dispatching notification with link $deepLink to intent: $deepLinkIntent with behavior: ${moduleConfig.pushClickBehavior}") - when (moduleConfig.notificationOnClickBehavior) { - NotificationClickBehavior.RESET_TASK_STACK -> { + when (moduleConfig.pushClickBehavior) { + PushClickBehavior.RESET_TASK_STACK -> { val taskStackBuilder = TaskStackBuilder.create(this).apply { addNextIntentWithParentStack(deepLinkIntent) } taskStackBuilder.startActivities() } - NotificationClickBehavior.ACTIVITY_PREVENT_RESTART -> { + PushClickBehavior.ACTIVITY_PREVENT_RESTART -> { deepLinkIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP startActivity(deepLinkIntent) } - NotificationClickBehavior.ACTIVITY_NO_FLAGS -> { + PushClickBehavior.ACTIVITY_NO_FLAGS -> { startActivity(deepLinkIntent) } } diff --git a/messagingpush/src/main/java/io/customer/messagingpush/config/NotificationClickBehavior.kt b/messagingpush/src/main/java/io/customer/messagingpush/config/PushClickBehavior.kt similarity index 81% rename from messagingpush/src/main/java/io/customer/messagingpush/config/NotificationClickBehavior.kt rename to messagingpush/src/main/java/io/customer/messagingpush/config/PushClickBehavior.kt index 493b037dc..e3f62fd1c 100644 --- a/messagingpush/src/main/java/io/customer/messagingpush/config/NotificationClickBehavior.kt +++ b/messagingpush/src/main/java/io/customer/messagingpush/config/PushClickBehavior.kt @@ -1,14 +1,14 @@ package io.customer.messagingpush.config /** - * Defines the behaviors for what happens when a notification is clicked. + * Defines the behaviors for what happens when a push notification is clicked. */ -enum class NotificationClickBehavior { +enum class PushClickBehavior { /** * Resets the task stack to include the deep-linked activity 'D'. - * - Example 1: Stack (A -> B -> C) becomes (D) if D is the deep-linked activity. - * - Example 2: Stack (A -> B -> C) changes to (A -> D) if D is the deep-linked activity and A is the root of the task stack provided by callback. + * - Example: Stack (A -> B -> C) becomes (D) if D is the deep-linked activity. + * - Example: Stack (A -> B -> C) changes to (A -> D) if D is the deep-linked activity and A is the root of the task stack provided by callback. * * This is similar to Android's "Set up a regular activity PendingIntent." * For more info, see [Android Documentation](https://developer.android.com/develop/ui/views/notifications/navigation#DirectEntry). diff --git a/sdk/api/sdk.api b/sdk/api/sdk.api index 7c872ab31..a8f08194e 100644 --- a/sdk/api/sdk.api +++ b/sdk/api/sdk.api @@ -115,6 +115,7 @@ public final class io/customer/sdk/CustomerIOConfig$Companion$Keys { public static final field BACKGROUND_QUEUE_SECONDS_DELAY Ljava/lang/String; public static final field INSTANCE Lio/customer/sdk/CustomerIOConfig$Companion$Keys; public static final field LOG_LEVEL Ljava/lang/String; + public static final field PUSH_CLICK_BEHAVIOR_ANDROID Ljava/lang/String; public static final field SOURCE_SDK_SOURCE Ljava/lang/String; public static final field SOURCE_SDK_VERSION Ljava/lang/String; public static final field TRACKING_API_URL Ljava/lang/String; diff --git a/sdk/src/main/java/io/customer/sdk/CustomerIOConfig.kt b/sdk/src/main/java/io/customer/sdk/CustomerIOConfig.kt index 24c4990dc..e6177d0e5 100644 --- a/sdk/src/main/java/io/customer/sdk/CustomerIOConfig.kt +++ b/sdk/src/main/java/io/customer/sdk/CustomerIOConfig.kt @@ -71,6 +71,7 @@ data class CustomerIOConfig( const val LOG_LEVEL = "logLevel" const val BACKGROUND_QUEUE_MIN_NUMBER_OF_TASKS = "backgroundQueueMinNumberOfTasks" const val BACKGROUND_QUEUE_SECONDS_DELAY = "backgroundQueueSecondsDelay" + const val PUSH_CLICK_BEHAVIOR_ANDROID = "pushClickBehaviorAndroid" const val SOURCE_SDK_VERSION = "version" const val SOURCE_SDK_SOURCE = "source" }