Skip to content

Commit

Permalink
Pull request #77: mtokar-MCA-4126_customize_PN_title_and_body
Browse files Browse the repository at this point in the history
Merge in MML/infobip-mobile-messaging-huawei from mtokar-MCA-4126_customize_PN_title_and_body to master

Squashed commit of the following:

commit d8f46c8db60de2716209fbe98788e00feedc93ce
Author: Matuš Tokar <Matus.Tokar@infobip.com>
Date:   Tue Sep 3 17:13:37 2024 +0200

    cleanup

commit 3a46aff1713fe41268c37856da087af76f898e98
Author: Matuš Tokar <Matus.Tokar@infobip.com>
Date:   Tue Sep 3 15:19:05 2024 +0200

    copied from android repo

commit 98bd9b5f0efe729466bc82241494ece55ff05846
Author: Matuš Tokar <Matus.Tokar@infobip.com>
Date:   Tue Sep 3 13:08:30 2024 +0200

    copied from android repo
  • Loading branch information
Matuš Tokar authored and Matuš Tokar committed Sep 4, 2024
1 parent 7a60861 commit eafde00
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,41 @@ 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);

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;
}
Expand All @@ -143,7 +155,7 @@ private void setNotificationStyle(NotificationCompat.Builder notificationBuilder
.bigPicture(notificationPicture)
.bigLargeIcon(null)
.setBigContentTitle(title)
.setSummaryText(message.getBody()));
.setSummaryText(body));
}

@Nullable
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -371,4 +383,4 @@ private ContentIntentWrapper activityStarterWrapper(Context context) {
}
return contentIntentWrapper;
}
}
}

0 comments on commit eafde00

Please sign in to comment.