Search in sources :

Example 31 with Message

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));
}
Also used : Message(org.infobip.mobile.messaging.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 32 with 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));
}
Also used : Message(org.infobip.mobile.messaging.Message) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 33 with Message

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[] {}));
    }
}
Also used : Geo(org.infobip.mobile.messaging.geo.Geo) Area(org.infobip.mobile.messaging.geo.Area) Message(org.infobip.mobile.messaging.Message) ArrayList(java.util.ArrayList) GeoSQLiteMessageStore(org.infobip.mobile.messaging.geo.storage.GeoSQLiteMessageStore) Date(java.util.Date)

Example 34 with Message

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));
}
Also used : Message(org.infobip.mobile.messaging.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) Geo(org.infobip.mobile.messaging.geo.Geo) Area(org.infobip.mobile.messaging.geo.Area) Geofence(com.google.android.gms.location.Geofence) Pair(android.util.Pair)

Example 35 with Message

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;
}
Also used : Message(org.infobip.mobile.messaging.Message) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView)

Aggregations

Message (org.infobip.mobile.messaging.Message)87 Test (org.junit.Test)44 Intent (android.content.Intent)13 Bundle (android.os.Bundle)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 GeoReportingResult (org.infobip.mobile.messaging.geo.report.GeoReportingResult)10 Context (android.content.Context)7 GeoReport (org.infobip.mobile.messaging.geo.report.GeoReport)7 GeoTransition (org.infobip.mobile.messaging.geo.transition.GeoTransition)7 JSONObject (org.json.JSONObject)7 List (java.util.List)6 EventReportResponse (org.infobip.mobile.messaging.api.geo.EventReportResponse)6 Geo (org.infobip.mobile.messaging.geo.Geo)6 Map (java.util.Map)5 MoMessage (org.infobip.mobile.messaging.api.messages.MoMessage)5 Area (org.infobip.mobile.messaging.geo.Area)5 NotificationAction (org.infobip.mobile.messaging.interactive.NotificationAction)5 NotificationCategory (org.infobip.mobile.messaging.interactive.NotificationCategory)5 Date (java.util.Date)4