Search in sources :

Example 1 with GeoEventSettings

use of org.infobip.mobile.messaging.geo.GeoEventSettings in project mobile-messaging-sdk-android by infobip.

the class GeoNotificationHelper method shouldReportTransition.

/**
 * Determines if transition should be reported to server
 *
 * @param geo   from original push signaling message with areas
 * @param event transition type
 * @return returns true if transition could be reported now
 */
public static boolean shouldReportTransition(Context context, Geo geo, GeoEventType event) {
    int numberOfDisplayedNotifications = getNumberOfDisplayedNotificationsForArea(context, geo.getCampaignId(), event);
    long lastNotificationTimeForArea = getLastNotificationTimeForArea(context, geo.getCampaignId(), event);
    GeoEventSettings settings = getNotificationSettingsForTransition(geo.getEvents(), event);
    boolean isInDeliveryWindow = checkIsAreaInDeliveryWindow(geo.getDeliveryTime());
    return settings != null && isInDeliveryWindow && (settings.getLimit() > numberOfDisplayedNotifications || settings.getLimit() == GeoEventSettings.UNLIMITED_RECURRING) && TimeUnit.MINUTES.toMillis(settings.getTimeoutInMinutes()) < Time.now() - lastNotificationTimeForArea && geoEventMatchesTransition(settings, event) && !geo.isExpired();
}
Also used : GeoEventSettings(org.infobip.mobile.messaging.geo.GeoEventSettings)

Example 2 with GeoEventSettings

use of org.infobip.mobile.messaging.geo.GeoEventSettings in project mobile-messaging-sdk-android by infobip.

the class AndroidGeoBroadcasterTest method test_should_send_geo_event.

@Test
public void test_should_send_geo_event() {
    // Given
    Geo geo = new Geo(0.0, 0.0, null, null, null, "SomeCampaignId", Collections.singletonList(createArea("areaId1")), new ArrayList<GeoEventSettings>(), 0, null);
    Message message = createMessage(context, "SomeMessageId", false, geo);
    // When
    broadcastSender.geoEvent(GeoEventType.entry, GeoMessage.createFrom(message, geo));
    // Then
    Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
    Intent intent = intentArgumentCaptor.getValue();
    assertEquals(GeoEvent.GEOFENCE_AREA_ENTERED.getKey(), intent.getAction());
    GeoMessage geoMessage = GeoMessage.createFrom(intent.getExtras());
    assertNotSame(message, geoMessage);
    assertEquals("SomeMessageId", geoMessage.getMessageId());
}
Also used : Geo(org.infobip.mobile.messaging.geo.Geo) GeoMessage(org.infobip.mobile.messaging.geo.GeoMessage) GeoMessage(org.infobip.mobile.messaging.geo.GeoMessage) Message(org.infobip.mobile.messaging.Message) GeoEventSettings(org.infobip.mobile.messaging.geo.GeoEventSettings) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

GeoEventSettings (org.infobip.mobile.messaging.geo.GeoEventSettings)2 Intent (android.content.Intent)1 Message (org.infobip.mobile.messaging.Message)1 Geo (org.infobip.mobile.messaging.geo.Geo)1 GeoMessage (org.infobip.mobile.messaging.geo.GeoMessage)1 Test (org.junit.Test)1