diff --git a/build.gradle b/build.gradle index 4f161ff3..74e5dcbf 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ ext { mm_compileSdkVersion = 33 mm_targetSdkVersion = 33 mm_buildToolsVersion = "33.0.0" - mm_androidSdkVersion = "12.9.0" + mm_androidSdkVersion = "12.10.0" mm_constraintLayoutVersion = "2.1.4" mm_appCompatVersion = "1.6.1" mm_materialVersion = "1.9.0" diff --git a/infobip-mobile-messaging-huawei-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/InAppChat.java b/infobip-mobile-messaging-huawei-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/InAppChat.java index bca51bfb..55979a33 100644 --- a/infobip-mobile-messaging-huawei-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/InAppChat.java +++ b/infobip-mobile-messaging-huawei-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/InAppChat.java @@ -238,4 +238,17 @@ public synchronized static InAppChat getInstance(Context context) { @Nullable public abstract String getDomain(); + /** + * Set custom title for in-app chat notifications + * + * @param title custom title to be set for notifications + */ + public abstract void setChatPushTitle(@Nullable String title); + + /** + * Set custom body for in-app chat notifications + * + * @param body custom body to be set for notifications + */ + public abstract void setChatPushBody(@Nullable String body); } diff --git a/infobip-mobile-messaging-huawei-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/InAppChatImpl.java b/infobip-mobile-messaging-huawei-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/InAppChatImpl.java index cd1a69d0..ff143810 100644 --- a/infobip-mobile-messaging-huawei-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/InAppChatImpl.java +++ b/infobip-mobile-messaging-huawei-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/InAppChatImpl.java @@ -15,6 +15,7 @@ import org.infobip.mobile.messaging.MessageHandlerModule; import org.infobip.mobile.messaging.MobileMessaging; import org.infobip.mobile.messaging.MobileMessagingCore; +import org.infobip.mobile.messaging.MobileMessagingProperty; import org.infobip.mobile.messaging.NotificationSettings; import org.infobip.mobile.messaging.api.chat.WidgetInfo; import org.infobip.mobile.messaging.app.ActivityLifecycleMonitor; @@ -37,6 +38,7 @@ import org.infobip.mobile.messaging.mobileapi.MobileMessagingError; import org.infobip.mobile.messaging.mobileapi.Result; import org.infobip.mobile.messaging.platform.AndroidBroadcaster; +import org.infobip.mobile.messaging.util.PreferenceHelper; import java.util.Locale; @@ -267,6 +269,8 @@ public void cleanup() { propertyHelper().remove(MobileMessagingChatProperty.IN_APP_CHAT_WIDGET_CALLS_ENABLED); propertyHelper().remove(MobileMessagingChatProperty.IN_APP_CHAT_ACTIVATED); propertyHelper().remove(MobileMessagingChatProperty.IN_APP_CHAT_LANGUAGE); + PreferenceHelper.remove(context, MobileMessagingProperty.DEFAULT_IN_APP_CHAT_PUSH_TITLE); + PreferenceHelper.remove(context, MobileMessagingProperty.DEFAULT_IN_APP_CHAT_PUSH_BODY); resetMessageCounter(); } @@ -463,6 +467,16 @@ public String getDomain() { public void setDomain(String domain) { sessionStorage().setDomain(domain); } + + @Override + public void setChatPushTitle(@Nullable String title) { + PreferenceHelper.saveString(context, MobileMessagingProperty.DEFAULT_IN_APP_CHAT_PUSH_TITLE, title); + } + + @Override + public void setChatPushBody(@Nullable String body) { + PreferenceHelper.saveString(context, MobileMessagingProperty.DEFAULT_IN_APP_CHAT_PUSH_BODY, body); + } //endregion // region private functions diff --git a/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/MobileMessagingProperty.java b/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/MobileMessagingProperty.java index 02e5076b..cf78aa84 100644 --- a/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/MobileMessagingProperty.java +++ b/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/MobileMessagingProperty.java @@ -55,6 +55,8 @@ public enum MobileMessagingProperty { DEFAULT_ICON("org.infobip.mobile.messaging.notification.DEFAULT_ICON", 0), DEFAULT_COLOR("org.infobip.mobile.messaging.notification.DEFAULT_COLOR", 0), DEFAULT_TITLE("org.infobip.mobile.messaging.notification.DEFAULT_TITLE", "Message"), + DEFAULT_IN_APP_CHAT_PUSH_TITLE("org.infobip.mobile.messaging.notification.DEFAULT_INN_APP_CHAT_TITLE", ""), + DEFAULT_IN_APP_CHAT_PUSH_BODY("org.infobip.mobile.messaging.notification.DEFAULT_INN_APP_CHAT_BODY", ""), INTENT_FLAGS("org.infobip.mobile.messaging.notification.INTENT_FLAGS", Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP), PENDING_INTENT_FLAGS("org.infobip.mobile.messaging.notification.PENDING_INTENT_FLAGS", (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_CANCEL_CURRENT), NOTIFICATION_AUTO_CANCEL("org.infobip.mobile.messaging.notification.NOTIFICATION_AUTO_CANCEL", true), diff --git a/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/NotificationSettings.java b/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/NotificationSettings.java index 0eca107b..4f0eb180 100644 --- a/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/NotificationSettings.java +++ b/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/NotificationSettings.java @@ -57,6 +57,14 @@ public boolean isDisplayNotificationEnabled() { return PreferenceHelper.findBoolean(context, MobileMessagingProperty.DISPLAY_NOTIFICATION_ENABLED); } + public String getChatDefaultTitle() { + return PreferenceHelper.findString(context, MobileMessagingProperty.DEFAULT_IN_APP_CHAT_PUSH_TITLE); + } + + public String getChatDefaultBody() { + return PreferenceHelper.findString(context, MobileMessagingProperty.DEFAULT_IN_APP_CHAT_PUSH_BODY); + } + public String getDefaultTitle() { return PreferenceHelper.findString(context, MobileMessagingProperty.DEFAULT_TITLE); } diff --git a/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/notification/BaseNotificationHandler.java b/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/notification/BaseNotificationHandler.java index 7582c301..f69e31d9 100644 --- a/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/notification/BaseNotificationHandler.java +++ b/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/notification/BaseNotificationHandler.java @@ -109,15 +109,27 @@ public NotificationCompat.Builder createNotificationCompatBuilder(Message messag if (notificationSettings == null) return null; String title = StringUtils.isNotBlank(message.getTitle()) ? message.getTitle() : notificationSettings.getDefaultTitle(); + String body = message.getBody(); + if (message.isChatMessage()) { + String chatDefaultTitle = notificationSettings.getChatDefaultTitle(); + String chatDefaultBody = notificationSettings.getChatDefaultBody(); + if (StringUtils.isNotBlank(chatDefaultTitle)) { + title = chatDefaultTitle; + } + if (StringUtils.isNotBlank(chatDefaultBody)) { + body = chatDefaultBody; + } + } + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, getChannelIdForNotification(notificationSettings, message)) .setContentTitle(title) - .setContentText(message.getBody()) + .setContentText(body) .setColor(notificationSettings.getColor()) .setAutoCancel(notificationSettings.isNotificationAutoCancel()) .setContentIntent(createTapPendingIntent(notificationSettings, message)) .setWhen(message.getReceivedTimestamp()); - setNotificationStyle(notificationBuilder, message, title); + setNotificationStyle(notificationBuilder, message, title, body); setNotificationSoundAndVibrate(notificationBuilder, message); setNotificationIcon(notificationBuilder, message); setNotificationPriority(notificationBuilder, notificationSettings, message); @@ -125,13 +137,13 @@ public NotificationCompat.Builder createNotificationCompatBuilder(Message messag return notificationBuilder; } - private void setNotificationStyle(NotificationCompat.Builder notificationBuilder, Message message, String title) { + private void setNotificationStyle(NotificationCompat.Builder notificationBuilder, Message message, String title, String body) { String contentUrl = message.getContentUrl(); Bitmap notificationPicture = fetchNotificationPicture(contentUrl); if (notificationPicture == null) { notificationBuilder.setStyle(new NotificationCompat.BigTextStyle() - .bigText(message.getBody()) + .bigText(body) .setBigContentTitle(title)); return; } @@ -143,7 +155,7 @@ private void setNotificationStyle(NotificationCompat.Builder notificationBuilder .bigPicture(notificationPicture) .bigLargeIcon(null) .setBigContentTitle(title) - .setSummaryText(message.getBody())); + .setSummaryText(body)); } @Nullable @@ -262,7 +274,7 @@ private NotificationSettings notificationSettings(Message message) { return null; } - if (StringUtils.isBlank(message.getBody())) { + if (StringUtils.isBlank(message.getBody()) && StringUtils.isBlank(notificationSettings.getChatDefaultBody())) { return null; } @@ -371,4 +383,4 @@ private ContentIntentWrapper activityStarterWrapper(Context context) { } return contentIntentWrapper; } -} +} \ No newline at end of file