Search in sources :

Example 1 with GeoEventType

use of org.infobip.mobile.messaging.geo.GeoEventType 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 2 with GeoEventType

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

the class GeoTransitionHelper method resolveTransitionFromIntent.

/**
 * Resolves transition information from geofencing intent
 *
 * @param intent geofencing intent
 * @return transition information
 * @throws RuntimeException if information cannot be resolved
 */
static GeoTransition resolveTransitionFromIntent(Intent intent) throws RuntimeException {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent == null) {
        throw new RuntimeException("Geofencing event is null, cannot process");
    }
    if (geofencingEvent.hasError()) {
        if (geofencingEvent.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) {
            throw new GeofenceNotAvailableException();
        }
        throw new RuntimeException("ERROR: " + GeofenceStatusCodes.getStatusCodeString(geofencingEvent.getErrorCode()));
    }
    GeoEventType event = supportedTransitionEvents.get(geofencingEvent.getGeofenceTransition());
    if (event == null) {
        throw new RuntimeException("Transition is not supported: " + geofencingEvent.getGeofenceTransition());
    }
    Set<String> triggeringRequestIds = new ArraySet<>();
    for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
        triggeringRequestIds.add(geofence.getRequestId());
    }
    Location location = geofencingEvent.getTriggeringLocation();
    return new GeoTransition(event, triggeringRequestIds, new GeoLatLng(location.getLatitude(), location.getLongitude()));
}
Also used : ArraySet(android.support.v4.util.ArraySet) GeoLatLng(org.infobip.mobile.messaging.geo.GeoLatLng) GeoEventType(org.infobip.mobile.messaging.geo.GeoEventType) GeofencingEvent(com.google.android.gms.location.GeofencingEvent) Geofence(com.google.android.gms.location.Geofence) Location(android.location.Location)

Example 3 with GeoEventType

use of org.infobip.mobile.messaging.geo.GeoEventType 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)

Aggregations

GeoEventType (org.infobip.mobile.messaging.geo.GeoEventType)3 Message (org.infobip.mobile.messaging.Message)2 Location (android.location.Location)1 ArrayMap (android.support.v4.util.ArrayMap)1 ArraySet (android.support.v4.util.ArraySet)1 Geofence (com.google.android.gms.location.Geofence)1 GeofencingEvent (com.google.android.gms.location.GeofencingEvent)1 Geo (org.infobip.mobile.messaging.geo.Geo)1 GeoLatLng (org.infobip.mobile.messaging.geo.GeoLatLng)1 GeoMessage (org.infobip.mobile.messaging.geo.GeoMessage)1 GeofencingHelper (org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper)1