Search in sources :

Example 1 with GeofencingHelper

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);
    }
}
Also used : MessageStore(org.infobip.mobile.messaging.storage.MessageStore) GeofencingHelper(org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper)

Example 2 with GeofencingHelper

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);
}
Also used : GeofencingHelper(org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper) GeoSQLiteMessageStore(org.infobip.mobile.messaging.geo.storage.GeoSQLiteMessageStore) Test(org.junit.Test)

Example 3 with GeofencingHelper

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;
}
Also used : GeofencingHelper(org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper) Message(org.infobip.mobile.messaging.Message) ArrayMap(android.support.v4.util.ArrayMap) GeoEventType(org.infobip.mobile.messaging.geo.GeoEventType)

Example 4 with GeofencingHelper

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

Example 5 with GeofencingHelper

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();
}
Also used : Context(android.content.Context) MobileApiResourceProvider(org.infobip.mobile.messaging.mobile.MobileApiResourceProvider) GeofencingHelper(org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper) GeoBroadcaster(org.infobip.mobile.messaging.geo.platform.GeoBroadcaster) NotificationHandler(org.infobip.mobile.messaging.notification.NotificationHandler) Broadcaster(org.infobip.mobile.messaging.platform.Broadcaster) GeoBroadcaster(org.infobip.mobile.messaging.geo.platform.GeoBroadcaster) MobileApiMessages(org.infobip.mobile.messaging.api.messages.MobileApiMessages) MobileApiRegistration(org.infobip.mobile.messaging.api.registration.MobileApiRegistration) Before(org.junit.Before) SuppressLint(android.annotation.SuppressLint)

Aggregations

GeofencingHelper (org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper)8 Test (org.junit.Test)3 GeoSQLiteMessageStore (org.infobip.mobile.messaging.geo.storage.GeoSQLiteMessageStore)2 MessageStore (org.infobip.mobile.messaging.storage.MessageStore)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 ArrayMap (android.support.v4.util.ArrayMap)1 Date (java.util.Date)1 Message (org.infobip.mobile.messaging.Message)1 MobileApiMessages (org.infobip.mobile.messaging.api.messages.MobileApiMessages)1 MobileApiRegistration (org.infobip.mobile.messaging.api.registration.MobileApiRegistration)1 GeoEventType (org.infobip.mobile.messaging.geo.GeoEventType)1 GeoBroadcaster (org.infobip.mobile.messaging.geo.platform.GeoBroadcaster)1 GeoReporter (org.infobip.mobile.messaging.geo.report.GeoReporter)1 GeoAreasHandler (org.infobip.mobile.messaging.geo.transition.GeoAreasHandler)1 GeoNotificationHelper (org.infobip.mobile.messaging.geo.transition.GeoNotificationHelper)1 MobileApiResourceProvider (org.infobip.mobile.messaging.mobile.MobileApiResourceProvider)1 NotificationHandler (org.infobip.mobile.messaging.notification.NotificationHandler)1 Broadcaster (org.infobip.mobile.messaging.platform.Broadcaster)1 Before (org.junit.Before)1