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);
}
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);
}
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());
}
}
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();
}
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);
}
}
Aggregations