Search in sources :

Example 1 with PushNotificationEnvelope

use of com.kickstarter.services.apiresponses.PushNotificationEnvelope in project android-oss by kickstarter.

the class MessageService method onMessageReceived.

/**
   * Called when a message is received from GCM.
   *
   * @param from SenderID of the sender.
   * @param data Data bundle containing message data as key/value pairs.
   */
@Override
public void onMessageReceived(@NonNull final String from, @NonNull final Bundle data) {
    final String senderId = getString(R.string.gcm_defaultSenderId);
    if (!from.equals(senderId)) {
        Timber.e("Received a message from %s, expecting %s", from, senderId);
        return;
    }
    final PushNotificationEnvelope envelope = PushNotificationEnvelope.builder().activity(gson.fromJson(data.getString("activity"), Activity.class)).gcm(gson.fromJson(data.getString("gcm"), GCM.class)).build();
    if (envelope == null) {
        Timber.e("Cannot parse message, malformed or unexpected data: %s", data.toString());
        return;
    }
    Timber.d("Received message: %s", envelope.toString());
    pushNotifications.add(envelope);
}
Also used : PushNotificationEnvelope(com.kickstarter.services.apiresponses.PushNotificationEnvelope) Activity(com.kickstarter.models.pushdata.Activity)

Example 2 with PushNotificationEnvelope

use of com.kickstarter.services.apiresponses.PushNotificationEnvelope in project android-oss by kickstarter.

the class DebugPushNotificationsView method simulateProjectLaunchButtonClick.

@OnClick(R.id.simulate_project_launch_button)
public void simulateProjectLaunchButtonClick() {
    final GCM gcm = GCM.builder().title("Want to be the first backer?").alert("Taylor Moore just launched a project!").build();
    final Activity activity = Activity.builder().category(com.kickstarter.models.Activity.CATEGORY_LAUNCH).id(5).projectId(PROJECT_ID).build();
    final PushNotificationEnvelope envelope = PushNotificationEnvelope.builder().activity(activity).gcm(gcm).build();
    pushNotifications.add(envelope);
}
Also used : GCM(com.kickstarter.models.pushdata.GCM) PushNotificationEnvelope(com.kickstarter.services.apiresponses.PushNotificationEnvelope) Activity(com.kickstarter.models.pushdata.Activity) OnClick(butterknife.OnClick)

Example 3 with PushNotificationEnvelope

use of com.kickstarter.services.apiresponses.PushNotificationEnvelope in project android-oss by kickstarter.

the class DebugPushNotificationsView method simulateBurstClick.

@OnClick(R.id.simulate_burst_button)
public void simulateBurstClick() {
    final PushNotificationEnvelope baseEnvelope = projectSuccessEnvelope();
    for (int i = 0; i < 100; i++) {
        // Create a different signature for each push notification
        final GCM gcm = baseEnvelope.gcm().toBuilder().alert(Integer.toString(i)).build();
        pushNotifications.add(baseEnvelope.toBuilder().gcm(gcm).build());
    }
}
Also used : GCM(com.kickstarter.models.pushdata.GCM) PushNotificationEnvelope(com.kickstarter.services.apiresponses.PushNotificationEnvelope) OnClick(butterknife.OnClick)

Example 4 with PushNotificationEnvelope

use of com.kickstarter.services.apiresponses.PushNotificationEnvelope in project android-oss by kickstarter.

the class ProjectIntentMapperTest method testPushNotificationEnvelope_doesNotEmitWithoutEnvelope.

@Test
public void testPushNotificationEnvelope_doesNotEmitWithoutEnvelope() {
    final PushNotificationEnvelope envelope = PushNotificationEnvelopeFactory.envelope();
    final Intent intent = new Intent();
    final TestSubscriber<PushNotificationEnvelope> resultTest = TestSubscriber.create();
    ProjectIntentMapper.pushNotificationEnvelope(intent).subscribe(resultTest);
    resultTest.assertNoValues();
}
Also used : PushNotificationEnvelope(com.kickstarter.services.apiresponses.PushNotificationEnvelope) Intent(android.content.Intent) Test(org.junit.Test)

Example 5 with PushNotificationEnvelope

use of com.kickstarter.services.apiresponses.PushNotificationEnvelope in project android-oss by kickstarter.

the class MessageService method onMessageReceived.

/**
 * Called when a message is received from Firebase.
 * - If the message comes from braze it will be handle on:
 * - @see RemotePushClientType#handleRemoteMessages(android.content.Context, com.google.firebase.messaging.RemoteMessage)
 * - If the message is from Kickstarter it will be process here
 *
 * @param remoteMessage Object containing message information.
 */
@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    final Boolean isBrazeMessage = this.remotePushClientType.handleRemoteMessages(this, remoteMessage);
    if (!isBrazeMessage) {
        final String senderId = getString(R.string.gcm_defaultSenderId);
        final String from = remoteMessage.getFrom();
        if (!TextUtils.equals(from, senderId)) {
            Timber.e("Received a message from %s, expecting %s", from, senderId);
            return;
        }
        final Map<String, String> data = remoteMessage.getData();
        final PushNotificationEnvelope envelope = PushNotificationEnvelope.builder().activity(this.gson.fromJson(data.get("activity"), Activity.class)).erroredPledge(this.gson.fromJson(data.get("errored_pledge"), PushNotificationEnvelope.ErroredPledge.class)).gcm(this.gson.fromJson(data.get("gcm"), GCM.class)).message(this.gson.fromJson(data.get("message"), PushNotificationEnvelope.Message.class)).project(this.gson.fromJson(data.get("project"), PushNotificationEnvelope.Project.class)).survey(this.gson.fromJson(data.get("survey"), PushNotificationEnvelope.Survey.class)).build();
        if (envelope == null) {
            Timber.e("Cannot parse message, malformed or unexpected data: %s", data.toString());
            return;
        }
        Timber.d("Received message: %s", envelope.toString());
        this.pushNotifications.add(envelope);
    }
}
Also used : GCM(com.kickstarter.models.pushdata.GCM) PushNotificationEnvelope(com.kickstarter.services.apiresponses.PushNotificationEnvelope) Activity(com.kickstarter.models.pushdata.Activity)

Aggregations

PushNotificationEnvelope (com.kickstarter.services.apiresponses.PushNotificationEnvelope)16 GCM (com.kickstarter.models.pushdata.GCM)13 OnClick (butterknife.OnClick)8 Activity (com.kickstarter.models.pushdata.Activity)8 Notification (android.app.Notification)4 Intent (android.content.Intent)4 PendingIntent (android.app.PendingIntent)2 Test (org.junit.Test)2