Search in sources :

Example 1 with NotificationCategory

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

the class InteractiveNotificationHandler method getNotificationBuilder.

private NotificationCompat.Builder getNotificationBuilder(Message message, CoreNotificationHandler notificationHandler, int notificationId) {
    NotificationCompat.Builder builder = notificationHandler.notificationCompatBuilder(message);
    if (builder == null)
        return null;
    String category = message.getCategory();
    NotificationCategory triggeredNotificationCategory = MobileInteractiveImpl.getInstance(context).getNotificationCategory(category);
    setNotificationActions(builder, message, triggeredNotificationCategory, notificationId);
    return builder;
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory)

Example 2 with NotificationCategory

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

the class NotificationActionTapReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Bundle actionBundle = intent.getBundleExtra(EXTRA_TAPPED_ACTION);
    Bundle categoryBundle = intent.getBundleExtra(EXTRA_TAPPED_CATEGORY);
    int notificationId = intent.getIntExtra(BroadcastParameter.EXTRA_NOTIFICATION_ID, -1);
    Bundle messageBundle = intent.getBundleExtra(BroadcastParameter.EXTRA_MESSAGE);
    Message message = Message.createFrom(messageBundle);
    NotificationCategory notificationCategory = NotificationCategory.createFrom(categoryBundle);
    NotificationAction notificationAction = NotificationAction.createFrom(actionBundle);
    String inputText = getInputTextFromIntent(intent, notificationAction);
    cancelNotification(context, notificationId);
    if (message == null) {
        MobileMessagingLogger.e("Received no message in NotificationActionTapReceiver");
        return;
    }
    if (notificationAction == null) {
        MobileMessagingLogger.e("Received no action in NotificationActionTapReceiver");
        return;
    }
    if (notificationCategory == null) {
        MobileMessagingLogger.e("Received no notification category in NotificationActionTapReceiver");
        return;
    }
    if (inputText != null) {
        notificationAction.setInputText(inputText);
    }
    broadcaster(context).notificationActionTapped(message, notificationCategory, notificationAction);
    mobileInteractive(context).triggerSdkActionsFor(notificationCategory.getCategoryId(), notificationAction, message);
    startCallbackActivity(context, intent, messageBundle, actionBundle, categoryBundle);
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Bundle(android.os.Bundle) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory)

Example 3 with NotificationCategory

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

the class NotificationActionTapReceiverTest method test_should_send_notification_action_clicked_event.

@Test
public void test_should_send_notification_action_clicked_event() throws Exception {
    // Given
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    int givenNotificationId = 1234;
    NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").build();
    NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
    Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, givenNotificationId, notificationSettings.getIntentFlags());
    // When
    notificationActionTapReceiver.onReceive(contextMock, givenIntent);
    // Then
    Mockito.verify(notificationManagerMock, Mockito.times(1)).cancel(givenNotificationId);
    Mockito.verify(broadcastSender, Mockito.times(1)).notificationActionTapped(messageArgumentCaptor.capture(), notificationCategoryArgumentCaptor.capture(), notificationActionArgumentCaptor.capture());
    NotificationAction actualAction = notificationActionArgumentCaptor.getValue();
    NotificationCategory actualCategory = notificationCategoryArgumentCaptor.getValue();
    Message actualMessage = messageArgumentCaptor.getValue();
    assertJEquals(givenTappedNotificationAction, actualAction);
    assertJEquals(givenNotificationCategory, actualCategory);
    assertJEquals(givenMessage, actualMessage);
    Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
    Mockito.verify(contextMock, Mockito.never()).startActivity(any(Intent.class));
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Intent(android.content.Intent) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory) Test(org.junit.Test)

Example 4 with NotificationCategory

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

the class NotificationActionTapReceiverTest method test_should_send_action_clicked_event_and_open_activity.

@Test
public void test_should_send_action_clicked_event_and_open_activity() throws Exception {
    // Given
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    int givenNotificationId = 1234;
    NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").withBringingAppToForeground(true).build();
    NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
    Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, givenNotificationId, notificationSettings.getIntentFlags());
    // When
    notificationActionTapReceiver.onReceive(contextMock, givenIntent);
    // Then
    Mockito.verify(notificationManagerMock, Mockito.times(1)).cancel(givenNotificationId);
    Mockito.verify(broadcastSender, Mockito.times(1)).notificationActionTapped(messageArgumentCaptor.capture(), notificationCategoryArgumentCaptor.capture(), notificationActionArgumentCaptor.capture());
    Message actualMessage = messageArgumentCaptor.getValue();
    NotificationAction actualAction = notificationActionArgumentCaptor.getValue();
    NotificationCategory actualCategory = notificationCategoryArgumentCaptor.getValue();
    assertJEquals(givenNotificationCategory, actualCategory);
    assertJEquals(givenMessage, actualMessage);
    assertJEquals(givenTappedNotificationAction, actualAction);
    Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
    Mockito.verify(contextMock, Mockito.times(1)).startActivity(intentArgumentCaptor.capture());
    Intent actualIntent = intentArgumentCaptor.getValue();
    NotificationAction actualTappedAction = NotificationAction.createFrom(actualIntent.getExtras());
    NotificationCategory actualTappedCategory = NotificationCategory.createFrom(actualIntent.getExtras());
    Message actualTappedMessage = Message.createFrom(actualIntent.getExtras());
    assertEquals(givenIntent.getAction(), actualIntent.getAction());
    assertEquals(notificationSettings.getIntentFlags() | Intent.FLAG_ACTIVITY_NEW_TASK, actualIntent.getFlags());
    assertJEquals(givenTappedNotificationAction, actualTappedAction);
    assertJEquals(givenNotificationCategory, actualTappedCategory);
    assertJEquals(givenMessage, actualTappedMessage);
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Intent(android.content.Intent) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory) Test(org.junit.Test)

Example 5 with NotificationCategory

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

the class NotificationActionTapReceiverTest method test_should_trigger_sdk_actions_when_clicked_on_action_button.

@Test
public void test_should_trigger_sdk_actions_when_clicked_on_action_button() throws Exception {
    // Given
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").withMoMessage().build();
    NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
    Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, 1234, notificationSettings.getIntentFlags());
    // When
    notificationActionTapReceiver.onReceive(contextMock, givenIntent);
    // Then
    Mockito.verify(broadcastSender, Mockito.times(1)).notificationActionTapped(messageArgumentCaptor.capture(), notificationCategoryArgumentCaptor.capture(), notificationActionArgumentCaptor.capture());
    Message actualMessage = messageArgumentCaptor.getValue();
    NotificationAction actualAction = notificationActionArgumentCaptor.getValue();
    NotificationCategory actualCategory = notificationCategoryArgumentCaptor.getValue();
    Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Intent(android.content.Intent) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory) Test(org.junit.Test)

Aggregations

NotificationCategory (org.infobip.mobile.messaging.interactive.NotificationCategory)6 Message (org.infobip.mobile.messaging.Message)5 NotificationAction (org.infobip.mobile.messaging.interactive.NotificationAction)5 Intent (android.content.Intent)4 Test (org.junit.Test)4 Bundle (android.os.Bundle)1 NotificationCompat (android.support.v4.app.NotificationCompat)1