Skip to content

Commit

Permalink
refactor: push click behavior rename (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 authored Sep 28, 2023
1 parent 6138ed5 commit 03f66e2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
18 changes: 9 additions & 9 deletions messagingpush/api/messagingpush.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (ZLio/customer/messagingpush/data/communication/CustomerIOPushNotificationCallback;ZLio/customer/messagingpush/config/NotificationClickBehavior;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (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
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
* <p/>
* 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<MessagingPushModuleConfig> {
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
Expand Down Expand Up @@ -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

Check warning on line 75 in messagingpush/src/main/java/io/customer/messagingpush/MessagingPushModuleConfig.kt

View check run for this annotation

Codecov / codecov/patch

messagingpush/src/main/java/io/customer/messagingpush/MessagingPushModuleConfig.kt#L74-L75

Added lines #L74 - L75 were not covered by tests
}

Expand All @@ -84,7 +80,7 @@ class MessagingPushModuleConfig private constructor(
autoTrackPushEvents = autoTrackPushEvents,
notificationCallback = notificationCallback,
redirectDeepLinksToOtherApps = redirectDeepLinksToOtherApps,
notificationOnClickBehavior = notificationOnClickBehavior
pushClickBehavior = pushClickBehavior
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")

Check warning on line 116 in messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt

View check run for this annotation

Codecov / codecov/patch

messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt#L114-L116

Added lines #L114 - L116 were not covered by tests

when (moduleConfig.notificationOnClickBehavior) {
NotificationClickBehavior.RESET_TASK_STACK -> {
when (moduleConfig.pushClickBehavior) {
PushClickBehavior.RESET_TASK_STACK -> {
val taskStackBuilder = TaskStackBuilder.create(this).apply {
addNextIntentWithParentStack(deepLinkIntent)
}
taskStackBuilder.startActivities()

Check warning on line 123 in messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt

View check run for this annotation

Codecov / codecov/patch

messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt#L120-L123

Added lines #L120 - L123 were not covered by tests
}

NotificationClickBehavior.ACTIVITY_PREVENT_RESTART -> {
PushClickBehavior.ACTIVITY_PREVENT_RESTART -> {
deepLinkIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or

Check warning on line 127 in messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt

View check run for this annotation

Codecov / codecov/patch

messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt#L127

Added line #L127 was not covered by tests
Intent.FLAG_ACTIVITY_SINGLE_TOP
startActivity(deepLinkIntent)

Check warning on line 129 in messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt

View check run for this annotation

Codecov / codecov/patch

messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt#L129

Added line #L129 was not covered by tests
}

NotificationClickBehavior.ACTIVITY_NO_FLAGS -> {
PushClickBehavior.ACTIVITY_NO_FLAGS -> {
startActivity(deepLinkIntent)

Check warning on line 133 in messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt

View check run for this annotation

Codecov / codecov/patch

messagingpush/src/main/java/io/customer/messagingpush/activity/NotificationClickReceiverActivity.kt#L133

Added line #L133 was not covered by tests
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
1 change: 1 addition & 0 deletions sdk/api/sdk.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions sdk/src/main/java/io/customer/sdk/CustomerIOConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 03f66e2

Please sign in to comment.