use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeoReportHelperTest method test_should_filter_overlapping_triggered_areas.
@Test
public void test_should_filter_overlapping_triggered_areas() {
// given
HashMap<Message, List<Area>> messagesAndAreas = new HashMap<>();
Area area1 = createArea("areaId1", "", 1.0, 2.0, 700);
Area area2 = createArea("areaId2", "", 1.0, 2.0, 250);
Area area3 = createArea("areaId3", "", 1.0, 2.0, 1000);
Message message = createMessage(context, "messageId1", "campaignId1", true, area1, area2, area3);
List<Area> triggeredAreasList = Arrays.asList(area1, area3);
messagesAndAreas.put(message, triggeredAreasList);
// when
Map<Message, List<Area>> filteredOverlappingAreasForMessages = GeoReportHelper.filterOverlappingAreas(messagesAndAreas);
List<Area> filteredTriggeredAreasList = new ArrayList<>();
for (List<Area> areas : filteredOverlappingAreasForMessages.values()) {
filteredTriggeredAreasList.addAll(areas);
}
// then
assertEquals(1, filteredTriggeredAreasList.size());
assertEquals(area1.getRadius(), filteredTriggeredAreasList.get(0).getRadius());
assertEquals(area1, filteredTriggeredAreasList.get(0));
assertEquals(1, filteredOverlappingAreasForMessages.keySet().size());
assertEquals(true, filteredOverlappingAreasForMessages.containsKey(message));
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeoReportHelperTest method test_should_find_signaling_messages_and_areas_for_geofencing_request_ids_and_event_type.
@Test
public void test_should_find_signaling_messages_and_areas_for_geofencing_request_ids_and_event_type() throws Exception {
// Given
Area area = createArea("areaId1");
Message message = createMessage(context, "messageId1", "campaigId1", true, area);
// When
Map<Message, List<Area>> messageAreas = GeoReportHelper.findSignalingMessagesAndAreas(context, geoStore, Sets.newSet("areaId1"), GeoEventType.entry);
// Then
// internalData is String, so has to be compared as JSON separately
assertJEquals(message, messageAreas.keySet().iterator().next(), "internalData");
JSONAssert.assertEquals(message.getInternalData(), messageAreas.keySet().iterator().next().getInternalData(), true);
assertJEquals(area, messageAreas.values().iterator().next().get(0));
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeofencingImpl method removeExpiredAreasFromStorage.
void removeExpiredAreasFromStorage() {
GeoSQLiteMessageStore messageStoreForGeo = (GeoSQLiteMessageStore) geofencingHelper.getMessageStoreForGeo();
List<Message> messages = messageStoreForGeo.findAll(context);
List<String> messageIdsToDelete = new ArrayList<>(messages.size());
Date now = new Date();
for (Message message : messages) {
Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());
if (geo == null) {
continue;
}
List<Area> areasList = geo.getAreasList();
Date expiryDate = geo.getExpiryDate();
if (areasList == null || areasList.isEmpty()) {
continue;
}
for (Area area : areasList) {
if (!area.isValid() || expiryDate == null) {
continue;
}
if (expiryDate.before(now)) {
messageIdsToDelete.add(message.getMessageId());
}
}
}
if (!messageIdsToDelete.isEmpty()) {
messageStoreForGeo.deleteByIds(context, messageIdsToDelete.toArray(new String[] {}));
}
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeofencingImpl method calculateGeofencesToMonitorAndNextCheckDates.
@SuppressWarnings("WeakerAccess")
private Pair<List<Geofence>, Pair<Date, Date>> calculateGeofencesToMonitorAndNextCheckDates(MessageStore messageStore) {
Date nextCheckRefreshDate = null;
Date nextCheckExpireDate = null;
Map<String, Geofence> geofences = new HashMap<>();
Map<String, Date> expiryDates = new HashMap<>();
List<Message> messages = messageStore.findAll(context);
for (Message message : messages) {
Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());
if (geo == null || geo.getAreasList() == null || geo.getAreasList().isEmpty()) {
continue;
}
nextCheckExpireDate = calculateNextCheckDateForGeoExpiry(geo, nextCheckExpireDate);
final Set<String> finishedCampaignIds = GeofencingHelper.getFinishedCampaignIds(context);
if (finishedCampaignIds.contains(geo.getCampaignId())) {
continue;
}
if (geo.isEligibleForMonitoring()) {
List<Area> geoAreasList = geo.getAreasList();
for (Area area : geoAreasList) {
if (!area.isValid()) {
continue;
}
Date expiry = expiryDates.get(area.getId());
if (expiry != null && expiry.after(geo.getExpiryDate())) {
continue;
}
expiryDates.put(area.getId(), geo.getExpiryDate());
geofences.put(area.getId(), area.toGeofence(geo.getExpiryDate()));
}
}
nextCheckRefreshDate = calculateNextCheckDateForGeoStart(geo, nextCheckRefreshDate);
}
List<Geofence> geofenceList = new ArrayList<>(geofences.values());
return new Pair<>(geofenceList, new Pair<>(nextCheckRefreshDate, nextCheckExpireDate));
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class ExpandableListAdapter method getGroupView.
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
Message message = getGroup(groupPosition);
// TODO trim to some max char count
String headerTitle = message.getBody();
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = convertView.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
Aggregations