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