From 997f6c72d61376bf2be7fad508e7b01cc931ecd2 Mon Sep 17 00:00:00 2001 From: Jonathan Almeida Date: Tue, 14 Apr 2020 16:06:56 -0400 Subject: [PATCH] For #9409: Add app icon to Leanplum push notifications --- .../mozilla/fenix/push/FirebasePushService.kt | 6 ++++ .../push/LeanplumNotificationCustomizer.kt | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 app/src/main/java/org/mozilla/fenix/push/LeanplumNotificationCustomizer.kt diff --git a/app/src/main/java/org/mozilla/fenix/push/FirebasePushService.kt b/app/src/main/java/org/mozilla/fenix/push/FirebasePushService.kt index df990ad31..2c060a2b4 100644 --- a/app/src/main/java/org/mozilla/fenix/push/FirebasePushService.kt +++ b/app/src/main/java/org/mozilla/fenix/push/FirebasePushService.kt @@ -8,6 +8,7 @@ import android.annotation.SuppressLint import com.google.firebase.messaging.RemoteMessage import com.google.firebase.messaging.FirebaseMessagingService import com.leanplum.LeanplumPushFirebaseMessagingService +import com.leanplum.LeanplumPushService import mozilla.components.concept.push.PushService import mozilla.components.lib.push.firebase.AbstractFirebasePushService import mozilla.components.feature.push.AutoPushFeature @@ -43,6 +44,11 @@ import mozilla.components.feature.push.AutoPushFeature class FirebasePushService : LeanplumPushFirebaseMessagingService(), PushService by AutoPushService { + override fun onCreate() { + LeanplumPushService.setCustomizer(LeanplumNotificationCustomizer()) + super.onCreate() + } + override fun onNewToken(newToken: String) { AutoPushService.onNewToken(newToken) super.onNewToken(newToken) diff --git a/app/src/main/java/org/mozilla/fenix/push/LeanplumNotificationCustomizer.kt b/app/src/main/java/org/mozilla/fenix/push/LeanplumNotificationCustomizer.kt new file mode 100644 index 000000000..476595151 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/push/LeanplumNotificationCustomizer.kt @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.push + +import android.app.Notification +import android.os.Bundle +import androidx.core.app.NotificationCompat +import com.leanplum.LeanplumPushNotificationCustomizer +import org.mozilla.fenix.R + +/** + * Notification customizer for incoming Leanplum push messages. + */ +class LeanplumNotificationCustomizer : LeanplumPushNotificationCustomizer { + override fun customize( + builder: NotificationCompat.Builder, + notificationPayload: Bundle? + ) { + builder.setSmallIcon(R.drawable.ic_status_logo) + } + + // Do not implement if unless we want to support 2 lines of text in the BigPicture style. + // See: https://docs.leanplum.com/docs/customize-your-push-notifications-sample-android + override fun customize( + builder: Notification.Builder?, + notificationPayload: Bundle?, + notificationStyle: Notification.Style? + ) = Unit // no-op +}