Search in sources :

Example 1 with GCM

use of com.kickstarter.models.pushdata.GCM 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 2 with GCM

use of com.kickstarter.models.pushdata.GCM 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 3 with GCM

use of com.kickstarter.models.pushdata.GCM in project android-oss by kickstarter.

the class DebugPushNotificationsView method projectSuccessEnvelope.

@NonNull
private PushNotificationEnvelope projectSuccessEnvelope() {
    final GCM gcm = GCM.builder().title("Time to celebrate!").alert("SKULL GRAPHIC TEE has been successfully funded.").build();
    final Activity activity = Activity.builder().category(com.kickstarter.models.Activity.CATEGORY_SUCCESS).id(6).projectId(PROJECT_ID).projectPhoto(PROJECT_PHOTO).build();
    return PushNotificationEnvelope.builder().activity(activity).gcm(gcm).build();
}
Also used : GCM(com.kickstarter.models.pushdata.GCM) Activity(com.kickstarter.models.pushdata.Activity) NonNull(android.support.annotation.NonNull)

Example 4 with GCM

use of com.kickstarter.models.pushdata.GCM 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)

Example 5 with GCM

use of com.kickstarter.models.pushdata.GCM in project android-oss by kickstarter.

the class PushNotifications method displayNotificationFromProjectReminder.

private void displayNotificationFromProjectReminder(@NonNull final PushNotificationEnvelope envelope) {
    final GCM gcm = envelope.gcm();
    final PushNotificationEnvelope.Project project = envelope.project();
    if (project == null) {
        return;
    }
    final Intent projectIntent = projectIntent(envelope, ObjectUtils.toString(project.id()));
    final Notification notification = notificationBuilder(gcm.title(), gcm.alert(), CHANNEL_PROJECT_REMINDER).setContentIntent(projectContentIntent(envelope, projectIntent)).setLargeIcon(fetchBitmap(project.photo(), false)).build();
    notificationManager().notify(envelope.signature(), notification);
}
Also used : GCM(com.kickstarter.models.pushdata.GCM) PushNotificationEnvelope(com.kickstarter.services.apiresponses.PushNotificationEnvelope) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Aggregations

GCM (com.kickstarter.models.pushdata.GCM)17 PushNotificationEnvelope (com.kickstarter.services.apiresponses.PushNotificationEnvelope)13 Activity (com.kickstarter.models.pushdata.Activity)11 OnClick (butterknife.OnClick)8 Notification (android.app.Notification)7 ActivityFeedActivity (com.kickstarter.ui.activities.ActivityFeedActivity)3 MessagesActivity (com.kickstarter.ui.activities.MessagesActivity)3 ProjectPageActivity (com.kickstarter.ui.activities.ProjectPageActivity)3 SurveyResponseActivity (com.kickstarter.ui.activities.SurveyResponseActivity)3 UpdateActivity (com.kickstarter.ui.activities.UpdateActivity)3 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 NonNull (android.support.annotation.NonNull)1 NotificationCompat (androidx.core.app.NotificationCompat)1