use of org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper in project mobile-messaging-sdk-android by infobip.
the class PushMessageHandler method handleGeoMessage.
public void handleGeoMessage(Context context, Message message) {
GeofencingHelper geofencingHelper = new GeofencingHelper(context);
MessageStore messageStoreForGeo = geofencingHelper.getMessageStoreForGeo();
try {
messageStoreForGeo.save(context, message);
GeofencingHelper.setAllActiveGeoAreasMonitored(context, false);
geofencingHelper.startGeoMonitoringIfNecessary();
} catch (Exception e) {
MobileMessagingLogger.e(TAG, InternalSdkError.ERROR_SAVING_MESSAGE.get(), e);
}
}
use of org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper in project mobile-messaging-sdk-android by infobip.
the class MessageStoreTest method test_shouldUseGeoSqlStoreForGeo_whenConfiguredWithoutMessageStore.
@Test
public void test_shouldUseGeoSqlStoreForGeo_whenConfiguredWithoutMessageStore() {
MobileMessagingCore.setMessageStoreClass(context, null);
assertTrue(new GeofencingHelper(context).getMessageStoreForGeo() instanceof GeoSQLiteMessageStore);
}
use of org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper in project mobile-messaging-sdk-android by infobip.
the class GeoReportHelper method createMessagesToNotify.
/**
* Creates new geo notification messages based on reporting result
*
* @param reportedEvents events that were reported to server
* @param reportingResult response from the server
* @return map of messages and corresponding geo event types for each message
*/
public static Map<Message, GeoEventType> createMessagesToNotify(Context context, List<GeoReport> reportedEvents, @NonNull GeoReportingResult reportingResult) {
GeofencingHelper geofencingHelper = new GeofencingHelper(context);
List<Message> allMessages = geofencingHelper.getMessageStoreForGeo().findAll(context);
Map<Message, GeoEventType> messages = new ArrayMap<>();
for (GeoReport report : reportedEvents) {
Message signalingMessage = GeoReportHelper.getSignalingMessageForReport(allMessages, report);
if (signalingMessage == null) {
MobileMessagingLogger.e("Cannot find signaling message for id: " + report.getSignalingMessageId());
continue;
}
messages.put(createNewMessageForReport(report, reportingResult, signalingMessage), report.getEvent());
}
return messages;
}
use of org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper in project mobile-messaging-sdk-android by infobip.
the class MobileMessageHandlerTest method test_shouldDeleteExpiredAreas.
@Test
public void test_shouldDeleteExpiredAreas() throws Exception {
// Given
long now = Time.now();
Long millis30MinBeforeNow = now - 30 * 60 * 1000;
Long millis15MinBeforeNow = now - 15 * 60 * 1000;
Long millis15MinAfterNow = now + 15 * 60 * 1000;
String date30MinBeforeNow = DateTimeUtil.ISO8601DateToString(new Date(millis30MinBeforeNow));
String date15MinBeforeNow = DateTimeUtil.ISO8601DateToString(new Date(millis15MinBeforeNow));
String date15MinAfterNow = DateTimeUtil.ISO8601DateToString(new Date(millis15MinAfterNow));
String nonExpiredMessageId = "SomeMessageId5";
saveGeoMessageToDb("SomeMessageId1", null, date30MinBeforeNow);
saveGeoMessageToDb("SomeMessageId2", null, date30MinBeforeNow);
saveGeoMessageToDb("SomeMessageId3", null, date15MinBeforeNow);
saveGeoMessageToDb("SomeMessageId4", null, date15MinBeforeNow);
saveGeoMessageToDb(nonExpiredMessageId, null, date15MinAfterNow);
assertEquals(5, geoStore.countAll(context));
// When
GeofencingHelper geofencingHelper = new GeofencingHelper(context);
geofencingHelper.removeExpiredAreas();
// Then
assertEquals(1, geoStore.countAll(context));
assertEquals(nonExpiredMessageId, geoStore.findAll(context).get(0).getMessageId());
}
use of org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper in project mobile-messaging-sdk-android by infobip.
the class MobileMessagingTestCase method setUp.
@SuppressLint("ApplySharedPref")
@Before
public void setUp() throws Exception {
super.setUp();
PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit();
PreferenceHelper.saveString(context, MobileMessagingProperty.API_URI, "http://127.0.0.1:" + debugServer.getListeningPort() + "/");
PreferenceHelper.saveString(context, MobileMessagingProperty.APPLICATION_CODE, "TestApplicationCode");
PreferenceHelper.saveString(context, MobileMessagingProperty.INFOBIP_REGISTRATION_ID, "TestDeviceInstanceId");
PreferenceHelper.saveString(context, MobileMessagingProperty.GCM_REGISTRATION_ID, "TestRegistrationId");
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.GCM_REGISTRATION_ID_REPORTED, true);
MobileMessagingLogger.enforce();
time = new TestTimeProvider();
Time.reset(time);
notificationHandler = mock(NotificationHandler.class);
coreBroadcaster = mock(Broadcaster.class);
mobileApiMessages = mock(MobileApiMessages.class);
mobileApiRegistration = mock(MobileApiRegistration.class);
mobileApiResourceProvider = mock(MobileApiResourceProvider.class);
given(mobileApiResourceProvider.getMobileApiMessages(any(Context.class))).willReturn(mobileApiMessages);
given(mobileApiResourceProvider.getMobileApiRegistration(any(Context.class))).willReturn(mobileApiRegistration);
mobileMessagingCore = MobileMessagingTestable.create(context, coreBroadcaster, mobileApiResourceProvider);
mobileMessaging = mobileMessagingCore;
geofencingHelper = new GeofencingHelper(context);
geoBroadcaster = mock(GeoBroadcaster.class);
geofencingHelper.removeUnreportedGeoEvents();
databaseHelper = MobileMessagingCore.getDatabaseHelper(context);
databaseProvider = MobileMessagingCore.getDatabaseProvider(context);
geoStore = geofencingHelper.getMessageStoreForGeo();
}
Aggregations