mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/373 - Integrate leanplum-fcm
This commit is contained in:
parent
c853454896
commit
d09494613a
@ -362,6 +362,7 @@ dependencies {
|
|||||||
|
|
||||||
implementation Deps.sentry
|
implementation Deps.sentry
|
||||||
implementation Deps.leanplum
|
implementation Deps.leanplum
|
||||||
|
implementation Deps.leanplumMessaging
|
||||||
implementation Deps.osslicenses_library
|
implementation Deps.osslicenses_library
|
||||||
|
|
||||||
implementation Deps.mozilla_concept_engine
|
implementation Deps.mozilla_concept_engine
|
||||||
|
13
app/proguard-rules.pro
vendored
13
app/proguard-rules.pro
vendored
@ -54,6 +54,18 @@
|
|||||||
|
|
||||||
-keep class org.mozilla.fenix.**ViewModel { *; }
|
-keep class org.mozilla.fenix.**ViewModel { *; }
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
# Leanplum
|
||||||
|
####################################################################################################
|
||||||
|
|
||||||
|
-keepclassmembers class * {
|
||||||
|
@com.leanplum.annotations.* <fields>;
|
||||||
|
}
|
||||||
|
|
||||||
|
-keep class com.leanplum.** { *; }
|
||||||
|
-dontwarn com.leanplum.**
|
||||||
|
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
# Adjust
|
# Adjust
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
@ -94,3 +106,4 @@
|
|||||||
# Keep motionlayout internal methods
|
# Keep motionlayout internal methods
|
||||||
# https://github.com/mozilla-mobile/fenix/issues/2094
|
# https://github.com/mozilla-mobile/fenix/issues/2094
|
||||||
-keep class androidx.constraintlayout.** { *; }
|
-keep class androidx.constraintlayout.** { *; }
|
||||||
|
|
||||||
|
@ -4,6 +4,40 @@
|
|||||||
|
|
||||||
package org.mozilla.fenix.components
|
package org.mozilla.fenix.components
|
||||||
|
|
||||||
|
import com.google.firebase.messaging.RemoteMessage
|
||||||
import mozilla.components.lib.push.firebase.AbstractFirebasePushService
|
import mozilla.components.lib.push.firebase.AbstractFirebasePushService
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.mozilla.fenix.ext.components
|
||||||
|
|
||||||
class FirebasePush : AbstractFirebasePushService()
|
class FirebasePush : AbstractFirebasePushService() {
|
||||||
|
|
||||||
|
// Helper function to help determine if the incoming message is from Leanplum
|
||||||
|
private fun RemoteMessage.isLeanplumChannel(): Boolean =
|
||||||
|
data[LEANPLUM_KEY]
|
||||||
|
?.let { JSONObject(it) }
|
||||||
|
?.getString(LEANPLUM_NAME_KEY) == LEANPLUM_CHANNEL_NAME
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides onMessageReceived to handle incoming Leanplum messages.
|
||||||
|
*/
|
||||||
|
override fun onMessageReceived(remoteMessage: RemoteMessage?) {
|
||||||
|
if (remoteMessage?.isLeanplumChannel() == true) {
|
||||||
|
val message = remoteMessage.data?.get(LEANPLUM_MESSAGE_KEY) ?: return
|
||||||
|
sendLeanplumMessage(message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onMessageReceived(remoteMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sendLeanplumMessage(message: String) {
|
||||||
|
applicationContext.components.backgroundServices.notificationManager.showMessage(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val LEANPLUM_KEY = "lp_channel"
|
||||||
|
private const val LEANPLUM_NAME_KEY = "name"
|
||||||
|
private const val LEANPLUM_CHANNEL_NAME = "leanplum"
|
||||||
|
private const val LEANPLUM_MESSAGE_KEY = "lp_message"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@ import androidx.core.app.NotificationManagerCompat
|
|||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import mozilla.components.concept.sync.DeviceEvent
|
import mozilla.components.concept.sync.DeviceEvent
|
||||||
import mozilla.components.concept.sync.TabData
|
import mozilla.components.concept.sync.TabData
|
||||||
|
import mozilla.components.support.base.ids.notify
|
||||||
import mozilla.components.support.base.log.logger.Logger
|
import mozilla.components.support.base.log.logger.Logger
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
|
||||||
@ -29,6 +30,8 @@ class NotificationManager(private val context: Context) {
|
|||||||
companion object {
|
companion object {
|
||||||
const val RECEIVE_TABS_TAG = "ReceivedTabs"
|
const val RECEIVE_TABS_TAG = "ReceivedTabs"
|
||||||
const val RECEIVE_TABS_CHANNEL_ID = "ReceivedTabsChannel"
|
const val RECEIVE_TABS_CHANNEL_ID = "ReceivedTabsChannel"
|
||||||
|
const val DEFAULT_CHANNEL_TAG = "Default"
|
||||||
|
const val DEFAULT_CHANEL_ID = "DefaultChannel"
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -44,6 +47,13 @@ class NotificationManager(private val context: Context) {
|
|||||||
context.getString(R.string.fxa_received_tab_channel_name),
|
context.getString(R.string.fxa_received_tab_channel_name),
|
||||||
context.getString(R.string.fxa_received_tab_channel_description)
|
context.getString(R.string.fxa_received_tab_channel_description)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
createNotificationChannel(
|
||||||
|
DEFAULT_CHANEL_ID,
|
||||||
|
NotificationManager.IMPORTANCE_DEFAULT,
|
||||||
|
context.getString(R.string.app_name),
|
||||||
|
""
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +98,21 @@ class NotificationManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showMessage(message: String) {
|
||||||
|
val builder = NotificationCompat.Builder(context, DEFAULT_CHANEL_ID)
|
||||||
|
.setSmallIcon(R.drawable.ic_status_logo)
|
||||||
|
.setContentTitle(context.getString(R.string.app_name))
|
||||||
|
.setContentText(message)
|
||||||
|
.setWhen(System.currentTimeMillis())
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
|
.setDefaults(Notification.DEFAULT_VIBRATE or Notification.DEFAULT_SOUND)
|
||||||
|
|
||||||
|
val notification = builder.build()
|
||||||
|
with(NotificationManagerCompat.from(context)) {
|
||||||
|
notify(context, DEFAULT_CHANNEL_TAG, notification)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.O)
|
@TargetApi(Build.VERSION_CODES.O)
|
||||||
private fun createNotificationChannel(
|
private fun createNotificationChannel(
|
||||||
channelId: String,
|
channelId: String,
|
||||||
|
@ -159,6 +159,8 @@ object Deps {
|
|||||||
const val leakcanary_noop = "com.squareup.leakcanary:leakcanary-android-no-op:${Versions.leakcanary}"
|
const val leakcanary_noop = "com.squareup.leakcanary:leakcanary-android-no-op:${Versions.leakcanary}"
|
||||||
|
|
||||||
const val leanplum = "com.leanplum:leanplum-core:${Versions.leanplum}"
|
const val leanplum = "com.leanplum:leanplum-core:${Versions.leanplum}"
|
||||||
|
const val leanplumMessaging = "com.leanplum:leanplum-fcm:${Versions.leanplum}"
|
||||||
|
|
||||||
|
|
||||||
const val androidx_annotation = "androidx.annotation:annotation:${Versions.androidx_annotation}"
|
const val androidx_annotation = "androidx.annotation:annotation:${Versions.androidx_annotation}"
|
||||||
const val androidx_fragment = "androidx.fragment:fragment-ktx:${Versions.androidx_fragment}"
|
const val androidx_fragment = "androidx.fragment:fragment-ktx:${Versions.androidx_fragment}"
|
||||||
|
Loading…
Reference in New Issue
Block a user