Search in sources :

Example 21 with Message

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;
}
Also used : Area(org.infobip.mobile.messaging.geo.Area) Message(org.infobip.mobile.messaging.Message) ArrayMap(android.support.v4.util.ArrayMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map)

Example 22 with Message

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);
    }
}
Also used : Geo(org.infobip.mobile.messaging.geo.Geo) GeoMessage(org.infobip.mobile.messaging.geo.GeoMessage) Message(org.infobip.mobile.messaging.Message) GeoEventType(org.infobip.mobile.messaging.geo.GeoEventType)

Example 23 with Message

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));
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Intent(android.content.Intent) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory) Test(org.junit.Test)

Example 24 with Message

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);
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Intent(android.content.Intent) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory) Test(org.junit.Test)

Example 25 with Message

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());
}
Also used : Message(org.infobip.mobile.messaging.Message) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Message (org.infobip.mobile.messaging.Message)87 Test (org.junit.Test)44 Intent (android.content.Intent)13 Bundle (android.os.Bundle)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 GeoReportingResult (org.infobip.mobile.messaging.geo.report.GeoReportingResult)10 Context (android.content.Context)7 GeoReport (org.infobip.mobile.messaging.geo.report.GeoReport)7 GeoTransition (org.infobip.mobile.messaging.geo.transition.GeoTransition)7 JSONObject (org.json.JSONObject)7 List (java.util.List)6 EventReportResponse (org.infobip.mobile.messaging.api.geo.EventReportResponse)6 Geo (org.infobip.mobile.messaging.geo.Geo)6 Map (java.util.Map)5 MoMessage (org.infobip.mobile.messaging.api.messages.MoMessage)5 Area (org.infobip.mobile.messaging.geo.Area)5 NotificationAction (org.infobip.mobile.messaging.interactive.NotificationAction)5 NotificationCategory (org.infobip.mobile.messaging.interactive.NotificationCategory)5 Date (java.util.Date)4