Search in sources :

Example 76 with Message

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

the class ExpandableListAdapter method getFullMessageText.

private String getFullMessageText(int groupPosition) throws JSONException {
    Message m = messages.get(groupPosition);
    if (m == null) {
        return null;
    }
    String text = "messageId: " + m.getMessageId();
    text += "\ntitle: " + m.getTitle();
    text += "\nbody: " + m.getBody();
    text += "\nsound: " + m.getSound();
    text += "\nvibrate: " + m.isVibrate();
    text += "\nicon: " + m.getIcon();
    text += "\nsilent: " + m.isSilent();
    text += "\ncategory: " + m.getCategory();
    text += "\nfrom: " + m.getFrom();
    text += "\nreceivedTimestamp: " + m.getReceivedTimestamp();
    text += "\nseenTimestamp: " + m.getSeenTimestamp();
    if (m.getInternalData() != null) {
        text += "\ninternalData: " + new JSONObject(m.getInternalData()).toString(4);
    }
    if (m.getCustomPayload() != null) {
        try {
            text += "\ncustomPayload: " + m.getCustomPayload().toString(4);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    text += "\ndestination: " + m.getDestination();
    text += "\nstatus: " + m.getStatus();
    text += "\nstatusMessage: " + m.getStatusMessage();
    text += "\ncontentUrl: " + m.getContentUrl();
    return text;
}
Also used : Message(org.infobip.mobile.messaging.Message) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 77 with Message

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

the class ColoredScreenActivity method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_colored_screen);
    View layout = findViewById(R.id.rl_screen);
    layout.setBackgroundColor(getBackgroundColor());
    Message message = Message.createFrom(getIntent().getExtras());
    TextView tv = findViewById(R.id.tv_text);
    if (message != null) {
        tv.setText(message.getBody());
    } else {
        tv.setText(R.string.no_message_provided);
    }
}
Also used : Message(org.infobip.mobile.messaging.Message) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

Example 78 with Message

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

the class GeoAreasHandlerTests method test_should_notify_messages_only_for_active_campaigns.

@Test
public void test_should_notify_messages_only_for_active_campaigns() throws InterruptedException {
    // Given
    Area area = createArea("areaId1");
    Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Arrays.asList(createMessage(context, "signalingMessageId1", "campaignId1", true, area), createMessage(context, "signalingMessageId2", "campaignId2", true, area), createMessage(context, "signalingMessageId3", "campaignId3", true, area)));
    EventReportResponse response = new EventReportResponse();
    response.setSuspendedCampaignIds(Sets.newSet("campaignId1"));
    response.setFinishedCampaignIds(Sets.newSet("campaignId2"));
    Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(response));
    GeoTransition transition = GeoHelper.createTransition("areaId1");
    // When
    geoAreasHandler.handleTransition(transition);
    // Then
    Mockito.verify(geoNotificationHelper, Mockito.times(1)).notifyAboutGeoTransitions(geoNotificationCaptor.capture());
    assertEquals(1, geoNotificationCaptor.getValue().size());
    Map.Entry<Message, GeoEventType> notification = geoNotificationCaptor.getValue().entrySet().iterator().next();
    assertEquals(GeoEventType.entry, notification.getValue());
    Message message = notification.getKey();
    Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());
    assertNotNull(geo);
    assertNotSame("signalingMessageId3", message.getMessageId());
    assertTrue(StringUtils.isNotBlank(message.getMessageId()));
    assertEquals("campaignId3", geo.getCampaignId());
    assertEquals("areaId1", geo.getAreasList().get(0).getId());
}
Also used : Context(android.content.Context) EventReportResponse(org.infobip.mobile.messaging.api.geo.EventReportResponse) Message(org.infobip.mobile.messaging.Message) GeoTransition(org.infobip.mobile.messaging.geo.transition.GeoTransition) GeoReportingResult(org.infobip.mobile.messaging.geo.report.GeoReportingResult) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 79 with Message

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

the class GeoAreasHandlerTests method test_should_report_transition.

@Test
public void test_should_report_transition() {
    // Given
    Message m = createMessage(context, "SomeSignalingMessageId", "SomeCampaignId", true, createArea("SomeAreaId"));
    Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Collections.singletonList(m));
    Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(new Exception()));
    GeoTransition transition = GeoHelper.createTransition(123.0, 456.0, "SomeAreaId");
    time.set(789);
    // When
    geoAreasHandler.handleTransition(transition);
    // Then
    Mockito.verify(geoReporter, Mockito.times(1)).reportSync(geoReportCaptor.capture());
    GeoReport report = geoReportCaptor.getValue()[0];
    assertEquals("SomeAreaId", report.getArea().getId());
    assertEquals("SomeCampaignId", report.getCampaignId());
    assertEquals("SomeSignalingMessageId", report.getSignalingMessageId());
    assertNotSame("SomeSignalingMessageId", report.getMessageId());
    assertTrue(StringUtils.isNotBlank(report.getMessageId()));
    assertEquals(789, report.getTimestampOccurred().longValue());
    assertEquals(123.0, report.getTriggeringLocation().getLat());
    assertEquals(456.0, report.getTriggeringLocation().getLng());
}
Also used : Context(android.content.Context) GeoReport(org.infobip.mobile.messaging.geo.report.GeoReport) Message(org.infobip.mobile.messaging.Message) GeoTransition(org.infobip.mobile.messaging.geo.transition.GeoTransition) GeoReportingResult(org.infobip.mobile.messaging.geo.report.GeoReportingResult) Test(org.junit.Test)

Example 80 with Message

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

the class GeoAreasHandlerTests method test_should_save_messages_with_generated_ids_if_report_unsuccessful.

@Test
public void test_should_save_messages_with_generated_ids_if_report_unsuccessful() {
    // Given
    Message m = createMessage(context, "SomeSignalingMessageId", "SomeCampaignId", true, createArea("SomeAreaId"));
    Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Collections.singletonList(m));
    Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(new Exception()));
    GeoTransition transition = GeoHelper.createTransition(123.0, 456.0, "SomeAreaId");
    time.set(789);
    // When
    geoAreasHandler.handleTransition(transition);
    // Then
    Message message = geoAreasHandler.getMobileMessagingCore().getMessageStore().findAll(context).get(0);
    Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());
    assertNotNull(geo);
    assertNotSame("SomeSignalingMessageId", message.getMessageId());
    assertTrue(StringUtils.isNotBlank(message.getMessageId()));
    assertEquals("SomeCampaignId", geo.getCampaignId());
    assertEquals(123.0, geo.getTriggeringLatitude());
    assertEquals(456.0, geo.getTriggeringLongitude());
    assertEquals("SomeAreaId", geo.getAreasList().get(0).getId());
}
Also used : Context(android.content.Context) Message(org.infobip.mobile.messaging.Message) GeoTransition(org.infobip.mobile.messaging.geo.transition.GeoTransition) GeoReportingResult(org.infobip.mobile.messaging.geo.report.GeoReportingResult) Test(org.junit.Test)

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