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();
}
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());
}
Aggregations