use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeoReportHelper method filterOverlappingAreas.
/**
* Filters out overlapping areas for each campaign and returns only the smallest area
*
* @param messagesAndAreas all triggered areas for each message
* @return filtered areas
*/
public static Map<Message, List<Area>> filterOverlappingAreas(Map<Message, List<Area>> messagesAndAreas) {
Map<Message, List<Area>> filteredMessagesAndAreas = new ArrayMap<>(messagesAndAreas.size());
for (Map.Entry<Message, List<Area>> entry : messagesAndAreas.entrySet()) {
Message message = entry.getKey();
List<Area> areasList = entry.getValue();
if (areasList != null) {
// using only area that has the smallest radius
Collections.sort(areasList, new GeoAreaRadiusComparator());
filteredMessagesAndAreas.put(message, Collections.singletonList(areasList.get(0)));
}
}
return filteredMessagesAndAreas;
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeoNotificationHelper method notifyAboutGeoTransitions.
/**
* Broadcasts geofencing events and displays appropriate notifications for geo events
*
* @param messages messages with geo to notify
*/
public void notifyAboutGeoTransitions(Map<Message, GeoEventType> messages) {
for (Message m : messages.keySet()) {
GeoEventType eventType = messages.get(m);
Geo geo = GeoDataMapper.geoFromInternalData(m.getInternalData());
if (geo == null)
continue;
setLastNotificationTimeForArea(context, geo.getCampaignId(), eventType, Time.now());
setNumberOfDisplayedNotificationsForArea(context, geo.getCampaignId(), eventType, getNumberOfDisplayedNotificationsForArea(context, geo.getCampaignId(), eventType) + 1);
notifyAboutTransition(geo, m, eventType);
}
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class NotificationActionTapReceiverTest method test_should_send_notification_action_clicked_event.
@Test
public void test_should_send_notification_action_clicked_event() throws Exception {
// Given
Message givenMessage = createMessage(context, "SomeMessageId", false);
int givenNotificationId = 1234;
NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").build();
NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, givenNotificationId, notificationSettings.getIntentFlags());
// When
notificationActionTapReceiver.onReceive(contextMock, givenIntent);
// Then
Mockito.verify(notificationManagerMock, Mockito.times(1)).cancel(givenNotificationId);
Mockito.verify(broadcastSender, Mockito.times(1)).notificationActionTapped(messageArgumentCaptor.capture(), notificationCategoryArgumentCaptor.capture(), notificationActionArgumentCaptor.capture());
NotificationAction actualAction = notificationActionArgumentCaptor.getValue();
NotificationCategory actualCategory = notificationCategoryArgumentCaptor.getValue();
Message actualMessage = messageArgumentCaptor.getValue();
assertJEquals(givenTappedNotificationAction, actualAction);
assertJEquals(givenNotificationCategory, actualCategory);
assertJEquals(givenMessage, actualMessage);
Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
Mockito.verify(contextMock, Mockito.never()).startActivity(any(Intent.class));
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class NotificationActionTapReceiverTest method test_should_send_action_clicked_event_and_open_activity.
@Test
public void test_should_send_action_clicked_event_and_open_activity() throws Exception {
// Given
Message givenMessage = createMessage(context, "SomeMessageId", false);
int givenNotificationId = 1234;
NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").withBringingAppToForeground(true).build();
NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, givenNotificationId, notificationSettings.getIntentFlags());
// When
notificationActionTapReceiver.onReceive(contextMock, givenIntent);
// Then
Mockito.verify(notificationManagerMock, Mockito.times(1)).cancel(givenNotificationId);
Mockito.verify(broadcastSender, Mockito.times(1)).notificationActionTapped(messageArgumentCaptor.capture(), notificationCategoryArgumentCaptor.capture(), notificationActionArgumentCaptor.capture());
Message actualMessage = messageArgumentCaptor.getValue();
NotificationAction actualAction = notificationActionArgumentCaptor.getValue();
NotificationCategory actualCategory = notificationCategoryArgumentCaptor.getValue();
assertJEquals(givenNotificationCategory, actualCategory);
assertJEquals(givenMessage, actualMessage);
assertJEquals(givenTappedNotificationAction, actualAction);
Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
Mockito.verify(contextMock, Mockito.times(1)).startActivity(intentArgumentCaptor.capture());
Intent actualIntent = intentArgumentCaptor.getValue();
NotificationAction actualTappedAction = NotificationAction.createFrom(actualIntent.getExtras());
NotificationCategory actualTappedCategory = NotificationCategory.createFrom(actualIntent.getExtras());
Message actualTappedMessage = Message.createFrom(actualIntent.getExtras());
assertEquals(givenIntent.getAction(), actualIntent.getAction());
assertEquals(notificationSettings.getIntentFlags() | Intent.FLAG_ACTIVITY_NEW_TASK, actualIntent.getFlags());
assertJEquals(givenTappedNotificationAction, actualTappedAction);
assertJEquals(givenNotificationCategory, actualTappedCategory);
assertJEquals(givenMessage, actualTappedMessage);
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeoNotificationHelperTest method test_should_broadcast_message_and_geo.
@Test
public void test_should_broadcast_message_and_geo() throws Exception {
// Given
Geo geo = createGeo(1.0, 2.0, "SomeCampaignId", null, createArea("SomeAreaId", "SomeAreaTitle", 3.0, 4.0, 5));
final Message message = createMessage(context, "SomeMessageId", false, geo);
Map<Message, GeoEventType> messages = new HashMap<>();
messages.put(message, GeoEventType.entry);
// When
geoNotificationHelper.notifyAboutGeoTransitions(messages);
// Then
Mockito.verify(geoBroadcaster, Mockito.times(1)).geoEvent(geoEventTypeArgumentCaptor.capture(), geoMessageArgumentCaptor.capture());
Mockito.verify(coreBroadcaster, Mockito.times(1)).messageReceived(messageArgumentCaptor.capture());
assertEquals(GeoEventType.entry, geoEventTypeArgumentCaptor.getValue());
assertJEquals(message, GeoMessage.toMessage(geoMessageArgumentCaptor.getValue()));
assertJEquals(geo, geoMessageArgumentCaptor.getValue().getGeo());
}
Aggregations