diff --git a/personalization-sdk/src/main/AndroidManifest.xml b/personalization-sdk/src/main/AndroidManifest.xml
index 0d8732bb..4b3202d5 100644
--- a/personalization-sdk/src/main/AndroidManifest.xml
+++ b/personalization-sdk/src/main/AndroidManifest.xml
@@ -17,7 +17,7 @@
-
+
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/OnMessageListener.kt b/personalization-sdk/src/main/kotlin/com/personalization/OnMessageListener.kt
index a7fb38a6..924bc976 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/OnMessageListener.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/OnMessageListener.kt
@@ -1,6 +1,6 @@
package com.personalization
-import com.personalization.features.notification.domain.model.NotificationData
+import com.personalization.sdk.data.models.dto.notification.NotificationData
fun interface OnMessageListener {
fun onMessage(data: NotificationData)
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/RegisterManager.kt b/personalization-sdk/src/main/kotlin/com/personalization/RegisterManager.kt
index c84fd47c..60b017ed 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/RegisterManager.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/RegisterManager.kt
@@ -93,6 +93,7 @@ class RegisterManager @Inject constructor(
}
private fun processFirebaseToken(token: String) {
+
val savedToken = getPreferencesValueUseCase.getToken()
val lastUpdate = getPreferencesValueUseCase.getLastPushTokenDate()
val currentDate = Date().time
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/SDK.kt b/personalization-sdk/src/main/kotlin/com/personalization/SDK.kt
index 5a3b28f3..15f97882 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/SDK.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/SDK.kt
@@ -766,13 +766,11 @@ open class SDK {
}
private fun receiveMessage(remoteMessage: RemoteMessage) {
- notificationReceived(remoteMessage.data)
+ notificationReceived(data = remoteMessage.data)
- onMessageListener?.let { listener ->
- listener.onMessage(
- data = remoteMessage.toNotificationData()
- )
- }
+ onMessageListener?.onMessage(
+ data = remoteMessage.toNotificationData()
+ )
}
companion object {
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/di/SdkComponent.kt b/personalization-sdk/src/main/kotlin/com/personalization/di/SdkComponent.kt
index 24612908..09b6d80e 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/di/SdkComponent.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/di/SdkComponent.kt
@@ -1,7 +1,7 @@
package com.personalization.di
import com.personalization.SDK
-import com.personalization.features.notification.data.service.NotificationService
+import com.personalization.features.notification.service.NotificationService
import com.personalization.sdk.data.di.DataSourcesModule
import com.personalization.sdk.data.di.ModelsModule
import com.personalization.sdk.data.di.RepositoriesModule
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/errors/response.error.kt.kt b/personalization-sdk/src/main/kotlin/com/personalization/errors/response.error.kt.kt
index d2d6a896..baffc528 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/errors/response.error.kt.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/errors/response.error.kt.kt
@@ -9,6 +9,7 @@ import org.json.JSONObject
class JsonResponseErrorHandler(
private val tag: String,
private val response: JSONObject?,
+ private val message: String? = "Response is null or incorrect"
) {
/**
@@ -44,7 +45,10 @@ class JsonResponseErrorHandler(
* Logs the error message with the associated tag
* @param message The error message to log
*/
- fun logError(message: String, exception: Exception? = null) {
+ fun logError(
+ message: String? = this.message,
+ exception: Exception? = null
+ ) {
Log.e(tag, message, exception)
}
}
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/actions/mapper/ActionUrls.mapper.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/actions/mapper/ActionUrls.mapper.kt
new file mode 100644
index 00000000..68c1f2f2
--- /dev/null
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/actions/mapper/ActionUrls.mapper.kt
@@ -0,0 +1,19 @@
+package com.personalization.features.notification.actions.mapper
+
+import com.personalization.errors.JsonResponseErrorHandler
+import org.json.JSONArray
+
+fun parseActionUrls(actionUrlsJson: String?): List {
+ return try {
+ actionUrlsJson?.let {
+ val jsonArray = JSONArray(it)
+ List(jsonArray.length()) { index -> jsonArray.getString(index) }
+ } ?: emptyList()
+ } catch (exception: Exception) {
+ JsonResponseErrorHandler(
+ tag = "parseNotificationActions",
+ response = null
+ ).logError(exception = exception)
+ emptyList()
+ }
+}
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/actions/mapper/ActionsName.mapper.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/actions/mapper/ActionsName.mapper.kt
new file mode 100644
index 00000000..573ca9dd
--- /dev/null
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/actions/mapper/ActionsName.mapper.kt
@@ -0,0 +1,29 @@
+package com.personalization.features.notification.actions.mapper
+
+import com.personalization.errors.JsonResponseErrorHandler
+import com.personalization.features.notification.actions.model.NotificationAction
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ACTION
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_TITLE
+import org.json.JSONArray
+
+fun parseNotificationActions(actionsJson: String?): List {
+ return try {
+ actionsJson?.let {
+ val jsonArray = JSONArray(it)
+ List(jsonArray.length()) { index ->
+ val jsonObject = jsonArray.getJSONObject(index)
+ NotificationAction(
+ action = jsonObject.getString(NOTIFICATION_ACTION),
+ title = jsonObject.getString(NOTIFICATION_TITLE)
+ )
+ }
+ } ?: emptyList()
+ } catch (exception: Exception) {
+ JsonResponseErrorHandler(
+ tag = "parseNotificationActions",
+ response = null
+ ).logError(exception = exception)
+
+ emptyList()
+ }
+}
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/actions/model/notification.action.kt.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/actions/model/notification.action.kt.kt
new file mode 100644
index 00000000..1a914f32
--- /dev/null
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/actions/model/notification.action.kt.kt
@@ -0,0 +1,6 @@
+package com.personalization.features.notification.actions.model
+
+data class NotificationAction(
+ val action: String,
+ val title: String
+)
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/data/mapper/NotificationData.mapper.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/data/mapper/NotificationData.mapper.kt
new file mode 100644
index 00000000..24c7f6c4
--- /dev/null
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/data/mapper/NotificationData.mapper.kt
@@ -0,0 +1,28 @@
+package com.personalization.features.notification.data.mapper
+
+import com.google.firebase.messaging.RemoteMessage
+import com.personalization.features.notification.actions.mapper.parseActionUrls
+import com.personalization.features.notification.actions.mapper.parseNotificationActions
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ACTIONS
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ACTION_URLS
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_BODY
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_EVENT
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ICON
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_IMAGE
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_PARAM_ID
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_TITLE
+import com.personalization.features.notification.domain.model.NotificationConstants.TYPE_PARAM
+import com.personalization.features.notification.event.mapper.parseNotificationEvent
+import com.personalization.sdk.data.models.dto.notification.NotificationData
+
+fun RemoteMessage.toNotificationData(): NotificationData = NotificationData(
+ id = this.data[NOTIFICATION_PARAM_ID],
+ title = this.data[NOTIFICATION_TITLE],
+ body = this.data[NOTIFICATION_BODY],
+ icon = this.data[NOTIFICATION_ICON],
+ type = this.data[TYPE_PARAM],
+ actions = parseNotificationActions(this.data[NOTIFICATION_ACTIONS]),
+ actionUrls = parseActionUrls(this.data[NOTIFICATION_ACTION_URLS]),
+ image = this.data[NOTIFICATION_IMAGE],
+ event = parseNotificationEvent(this.data[NOTIFICATION_EVENT])
+)
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/data/mapper/NotificationDataMapper.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/data/mapper/NotificationDataMapper.kt
deleted file mode 100644
index d42090b6..00000000
--- a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/data/mapper/NotificationDataMapper.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.personalization.features.notification.data.mapper
-
-import com.google.firebase.messaging.RemoteMessage
-import com.personalization.features.notification.domain.model.NotificationConstants
-import com.personalization.features.notification.domain.model.NotificationData
-
-fun RemoteMessage.toNotificationData(): NotificationData {
- var title: String? = null
- var body: String? = null
- var imageUrl: String? = null
-
- this.notification?.let { notification ->
- title = notification.title?.takeIf { it.isNotEmpty() }
- body = notification.body?.takeIf { it.isNotEmpty() }
- imageUrl = notification.imageUrl?.toString()
- }
-
- val analyticsLabel: String? =
- this.data[NotificationConstants.ANALYTICS_LABEL_FIELD]?.takeIf { it.isNotEmpty() }
-
- return NotificationData(
- title = title,
- body = body,
- images = imageUrl,
- analyticsLabel = analyticsLabel
- )
-}
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/domain/model/NotificationConstants.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/domain/model/NotificationConstants.kt
index c9b2d34f..1ffdc602 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/domain/model/NotificationConstants.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/domain/model/NotificationConstants.kt
@@ -8,9 +8,17 @@ object NotificationConstants {
const val ACTION_NEXT_IMAGE = "ACTION_NEXT_IMAGE"
const val NOTIFICATION_TYPE = "NOTIFICATION_TYPE"
const val TRACK_CLICKED = "track/clicked"
- const val NOTIFICATION_IMAGES = "images"
+ const val NOTIFICATION_IMAGE = "image"
+ const val NOTIFICATION_ICON = "icon"
const val NOTIFICATION_TITLE = "title"
const val NOTIFICATION_BODY = "body"
+ const val NOTIFICATION_ACTIONS = "actions"
+ const val NOTIFICATION_ACTION = "action"
+ const val NOTIFICATION_ACTION_URLS = "action_urls"
+ const val NOTIFICATION_PARAM_ID = "id"
+ const val NOTIFICATION_PAYLOAD = "payload"
+ const val NOTIFICATION_EVENT = "event"
+ const val NOTIFICATION_URI = "uri"
const val TYPE_PARAM = "type"
const val CODE_PARAM = "code"
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/domain/model/NotificationData.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/domain/model/NotificationData.kt
deleted file mode 100644
index 593007bd..00000000
--- a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/domain/model/NotificationData.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.personalization.features.notification.domain.model
-
-data class NotificationData(
- val title: String?,
- val body: String?,
- val images: String?,
- val analyticsLabel: String? = null
-)
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/event/mapper/EventType.mapper.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/event/mapper/EventType.mapper.kt
new file mode 100644
index 00000000..f7218d94
--- /dev/null
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/event/mapper/EventType.mapper.kt
@@ -0,0 +1,38 @@
+package com.personalization.features.notification.event.mapper
+
+import com.personalization.errors.JsonResponseErrorHandler
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_PAYLOAD
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_URI
+import com.personalization.features.notification.domain.model.NotificationConstants.TYPE_PARAM
+import com.personalization.features.notification.event.model.NotificationEvent
+import org.json.JSONObject
+
+fun parseNotificationEvent(eventJson: String?): NotificationEvent {
+ val emptyData = NotificationEvent(
+ type = "",
+ uri = "",
+ payload = emptyMap()
+ )
+ return try {
+ eventJson?.let {
+ val jsonObject = JSONObject(it)
+
+ NotificationEvent(
+ type = jsonObject.optString(TYPE_PARAM, ""),
+ uri = jsonObject.optString(NOTIFICATION_URI, ""),
+ payload = jsonObject.optJSONObject(NOTIFICATION_PAYLOAD)?.let { payloadObj ->
+ payloadObj.keys().asSequence().associateWith { key -> payloadObj[key] }
+ } ?: emptyMap()
+ )
+
+ } ?: emptyData
+
+ } catch (exception: Exception) {
+ JsonResponseErrorHandler(
+ tag = "parseNotificationEvent",
+ response = null
+ ).logError(exception = exception)
+
+ emptyData
+ }
+}
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/event/model/notification.event.kt.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/event/model/notification.event.kt.kt
new file mode 100644
index 00000000..f33171f2
--- /dev/null
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/event/model/notification.event.kt.kt
@@ -0,0 +1,7 @@
+package com.personalization.features.notification.event.model
+
+data class NotificationEvent(
+ val type: String?,
+ val uri: String?,
+ val payload: Map? = null
+)
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationHelper.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationHelper.kt
index 9bd3b301..cd823c0b 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationHelper.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationHelper.kt
@@ -6,8 +6,8 @@ import android.graphics.Bitmap
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_CHANNEL
-import com.personalization.features.notification.domain.model.NotificationData
import com.personalization.resources.NotificationResources
+import com.personalization.sdk.data.models.dto.notification.NotificationData
import javax.inject.Inject
class NotificationHelper @Inject constructor(
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationNavigationHelper.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationNavigationHelper.kt
index 2cb0bca8..a4f356a5 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationNavigationHelper.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationNavigationHelper.kt
@@ -3,12 +3,12 @@ package com.personalization.features.notification.presentation.helpers
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
-import com.personalization.features.notification.data.service.NotificationService
import com.personalization.features.notification.domain.model.NotificationConstants.CURRENT_IMAGE_INDEX
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_BODY
-import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_IMAGES
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_IMAGE
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_TITLE
-import com.personalization.features.notification.domain.model.NotificationData
+import com.personalization.features.notification.service.NotificationService
+import com.personalization.sdk.data.models.dto.notification.NotificationData
import java.util.concurrent.atomic.AtomicInteger
import kotlin.math.abs
@@ -27,7 +27,7 @@ object NotificationNavigationHelper {
putExtra(CURRENT_IMAGE_INDEX, newIndex)
putExtra(NOTIFICATION_TITLE, data.title)
putExtra(NOTIFICATION_BODY, data.body)
- putExtra(NOTIFICATION_IMAGES, data.images)
+ putExtra(NOTIFICATION_IMAGE, data.image)
}
return PendingIntent.getService(
@@ -44,7 +44,7 @@ object NotificationNavigationHelper {
): PendingIntent {
val retryIntent = Intent(context, NotificationService::class.java).apply {
putExtra(CURRENT_IMAGE_INDEX, 0)
- putExtra(NOTIFICATION_IMAGES, data.images)
+ putExtra(NOTIFICATION_IMAGE, data.image)
putExtra(NOTIFICATION_TITLE, data.title)
putExtra(NOTIFICATION_BODY, data.body)
}
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationTextHelper.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationTextHelper.kt
index 570cb0f2..07ae1c7a 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationTextHelper.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationTextHelper.kt
@@ -2,7 +2,7 @@ package com.personalization.features.notification.presentation.helpers
import android.widget.RemoteViews
import com.personalization.R
-import com.personalization.features.notification.domain.model.NotificationData
+import com.personalization.sdk.data.models.dto.notification.NotificationData
object NotificationTextHelper {
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationViewHelper.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationViewHelper.kt
index cbb7eedd..8caad17e 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationViewHelper.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/presentation/helpers/NotificationViewHelper.kt
@@ -6,7 +6,7 @@ import android.widget.RemoteViews
import com.personalization.R
import com.personalization.features.notification.domain.model.NotificationConstants.ACTION_NEXT_IMAGE
import com.personalization.features.notification.domain.model.NotificationConstants.ACTION_PREVIOUS_IMAGE
-import com.personalization.features.notification.domain.model.NotificationData
+import com.personalization.sdk.data.models.dto.notification.NotificationData
object NotificationViewHelper {
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/data/service/NotificationService.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/service/NotificationService.kt
similarity index 69%
rename from personalization-sdk/src/main/kotlin/com/personalization/features/notification/data/service/NotificationService.kt
rename to personalization-sdk/src/main/kotlin/com/personalization/features/notification/service/NotificationService.kt
index 28f3f00d..ac5838a4 100644
--- a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/data/service/NotificationService.kt
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/service/NotificationService.kt
@@ -1,4 +1,4 @@
-package com.personalization.features.notification.data.service
+package com.personalization.features.notification.service
import android.app.Service
import android.content.Intent
@@ -7,14 +7,12 @@ import android.widget.Toast
import com.personalization.di.AppModule
import com.personalization.di.DaggerSdkComponent
import com.personalization.features.notification.domain.model.NotificationConstants.CURRENT_IMAGE_INDEX
-import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_BODY
-import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_IMAGES
-import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_TITLE
-import com.personalization.features.notification.domain.model.NotificationData
import com.personalization.features.notification.presentation.helpers.NotificationHelper
import com.personalization.features.notification.presentation.helpers.NotificationImageHelper
+import com.personalization.features.notification.service.mapper.toNotificationData
import com.personalization.resources.NotificationResources.NOTIFICATION_LOADING_DATA_ERROR
import com.personalization.resources.NotificationResources.NOTIFICATION_LOADING_IMAGE_ERROR
+import com.personalization.sdk.data.models.dto.notification.NotificationData
import java.io.IOException
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
@@ -47,33 +45,37 @@ class NotificationService : Service() {
startId: Int
): Int {
val currentIndex = intent?.getIntExtra(CURRENT_IMAGE_INDEX, -1) ?: -1
- val images = intent?.getStringExtra(NOTIFICATION_IMAGES)
- val title = intent?.getStringExtra(NOTIFICATION_TITLE)
- val body = intent?.getStringExtra(NOTIFICATION_BODY)
-
- if (!isValidNotificationData(images, title, body, currentIndex)) {
- showToast(
- message = applicationContext.getString(
- /* resId = */ NOTIFICATION_LOADING_DATA_ERROR
- )
- )
- stopSelf(startId)
- return START_NOT_STICKY
+ val data: NotificationData? = intent?.toNotificationData()
+
+ if (!isValidNotificationData(data?.image, data?.title, data?.body, currentIndex)) {
+ return onStopService(startId = startId)
}
- updateNotification(
- images = images,
- title = title,
- body = body,
- currentIndex = currentIndex,
- startId = startId
- )
+ when {
+ data != null -> updateNotification(
+ data,
+ currentIndex = currentIndex,
+ startId = startId
+ )
+
+ else -> onStopService(startId)
+ }
return START_NOT_STICKY
}
override fun onBind(intent: Intent?): IBinder? = null
+ private fun onStopService(startId: Int): Int {
+ showToast(
+ message = applicationContext.getString(
+ /* resId = */ NOTIFICATION_LOADING_DATA_ERROR
+ )
+ )
+ stopSelf(startId)
+ return START_NOT_STICKY
+ }
+
override fun onDestroy() {
super.onDestroy()
serviceJob.cancel()
@@ -89,21 +91,25 @@ class NotificationService : Service() {
}
private fun updateNotification(
- images: String?,
- title: String?,
- body: String?,
+ data: NotificationData,
currentIndex: Int,
startId: Int
) {
serviceScope.launch {
try {
- val (loadedImages, hasError) = NotificationImageHelper.loadBitmaps(urls = images)
+ val (loadedImages, hasError) = NotificationImageHelper.loadBitmaps(urls = data.image)
notificationHelper.createNotification(
context = this@NotificationService,
data = NotificationData(
- title = title,
- body = body,
- images = images
+ id = data.id,
+ title = data.title,
+ body = data.body,
+ icon = data.icon,
+ type = data.type,
+ actions = data.actions,
+ actionUrls = data.actionUrls,
+ image = data.image,
+ event = data.event,
),
images = loadedImages,
currentImageIndex = currentIndex,
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/notification/service/mapper/IntentData.mapper.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/service/mapper/IntentData.mapper.kt
new file mode 100644
index 00000000..532e5d07
--- /dev/null
+++ b/personalization-sdk/src/main/kotlin/com/personalization/features/notification/service/mapper/IntentData.mapper.kt
@@ -0,0 +1,28 @@
+package com.personalization.features.notification.service.mapper
+
+import android.content.Intent
+import com.personalization.features.notification.actions.mapper.parseActionUrls
+import com.personalization.features.notification.actions.mapper.parseNotificationActions
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ACTIONS
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ACTION_URLS
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_BODY
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_EVENT
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ICON
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_IMAGE
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_PARAM_ID
+import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_TITLE
+import com.personalization.features.notification.domain.model.NotificationConstants.TYPE_PARAM
+import com.personalization.features.notification.event.mapper.parseNotificationEvent
+import com.personalization.sdk.data.models.dto.notification.NotificationData
+
+fun Intent.toNotificationData(): NotificationData = NotificationData(
+ id = getStringExtra(NOTIFICATION_PARAM_ID),
+ title = getStringExtra(NOTIFICATION_TITLE),
+ body = getStringExtra(NOTIFICATION_BODY),
+ icon = getStringExtra(NOTIFICATION_ICON),
+ type = getStringExtra(TYPE_PARAM),
+ actions = parseNotificationActions(getStringExtra(NOTIFICATION_ACTIONS)),
+ actionUrls = parseActionUrls(getStringExtra(NOTIFICATION_ACTION_URLS)),
+ image = getStringExtra(NOTIFICATION_IMAGE),
+ event = parseNotificationEvent(getStringExtra(NOTIFICATION_EVENT))
+)
diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/data/models/dto/notification/NotificationData.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/data/models/dto/notification/NotificationData.kt
new file mode 100644
index 00000000..18972820
--- /dev/null
+++ b/personalization-sdk/src/main/kotlin/com/personalization/sdk/data/models/dto/notification/NotificationData.kt
@@ -0,0 +1,16 @@
+package com.personalization.sdk.data.models.dto.notification
+
+import com.personalization.features.notification.actions.model.NotificationAction
+import com.personalization.features.notification.event.model.NotificationEvent
+
+data class NotificationData(
+ val id: String?,
+ val title: String?,
+ val body: String?,
+ val icon: String?,
+ val type: String?,
+ val actions: List?,
+ val actionUrls: List?,
+ val image: String?,
+ val event: NotificationEvent?
+)
diff --git a/personalization-sdk/src/rees46/kotlin/com/rees46/sdk/REES46.kt b/personalization-sdk/src/rees46/kotlin/com/rees46/sdk/REES46.kt
index 4d47ea3b..733925a6 100644
--- a/personalization-sdk/src/rees46/kotlin/com/rees46/sdk/REES46.kt
+++ b/personalization-sdk/src/rees46/kotlin/com/rees46/sdk/REES46.kt
@@ -3,8 +3,8 @@ package com.rees46.sdk
import android.content.Context
import com.personalization.BuildConfig
import com.personalization.SDK
-import com.personalization.features.notification.domain.model.NotificationData
import com.personalization.features.notification.presentation.helpers.NotificationImageHelper
+import com.personalization.sdk.data.models.dto.notification.NotificationData
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -64,14 +64,20 @@ class REES46 private constructor() : SDK() {
sdk.setOnMessageListener { data ->
coroutineScope.launch {
val (images, hasError) = withContext(Dispatchers.IO) {
- NotificationImageHelper.loadBitmaps(urls = data.images)
+ NotificationImageHelper.loadBitmaps(urls = data.image)
}
sdk.notificationHelper.createNotification(
context = context,
data = NotificationData(
+ id = data.id,
title = data.title,
body = data.body,
- images = data.images
+ icon = data.icon,
+ type = data.type,
+ actions = data.actions,
+ actionUrls = data.actionUrls,
+ image = data.image,
+ event = data.event,
),
images = images,
hasError = hasError
diff --git a/sample/src/main/kotlin/com/personalization/sample/AbstractMainActivity.kt b/sample/src/main/kotlin/com/personalization/sample/AbstractMainActivity.kt
index 7fac1a29..463e1b16 100644
--- a/sample/src/main/kotlin/com/personalization/sample/AbstractMainActivity.kt
+++ b/sample/src/main/kotlin/com/personalization/sample/AbstractMainActivity.kt
@@ -16,15 +16,7 @@ import androidx.core.app.ActivityCompat
import com.personalization.OnClickListener
import com.personalization.Product
import com.personalization.SDK
-import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_BODY
-import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_IMAGES
-import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_TITLE
-import com.personalization.features.notification.domain.model.NotificationData
-import com.personalization.features.notification.presentation.helpers.NotificationImageHelper.loadBitmaps
import com.personalization.stories.views.StoriesView
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
abstract class AbstractMainActivity internal constructor(
private val sdk: SDK
@@ -43,7 +35,6 @@ abstract class AbstractMainActivity internal constructor(
initializingStoriesView()
initializingFragmentManager()
handleInAppNotifications()
- handlePushNotification()
}
private fun handlePermissions() {
@@ -123,29 +114,4 @@ abstract class AbstractMainActivity internal constructor(
)
}
}
-
- private fun handlePushNotification() {
- findViewById