Updated on 2026-08-14
This commit is contained in:
parent
9cc6f26cf4
commit
4d3791a56b
5 changed files with 113 additions and 1 deletions
|
|
@ -171,6 +171,7 @@ dependencies {
|
||||||
implementation(platform(deps.firebase.bom))
|
implementation(platform(deps.firebase.bom))
|
||||||
implementation(deps.firebase.analytics)
|
implementation(deps.firebase.analytics)
|
||||||
implementation(deps.firebase.crashlytics)
|
implementation(deps.firebase.crashlytics)
|
||||||
|
implementation(deps.firebase.messaging)
|
||||||
|
|
||||||
/** Tangem libraries */
|
/** Tangem libraries */
|
||||||
implementation(deps.tangem.blockchain) {
|
implementation(deps.tangem.blockchain) {
|
||||||
|
|
|
||||||
|
|
@ -144,5 +144,12 @@
|
||||||
android:resource="@xml/provider_paths" />
|
android:resource="@xml/provider_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name="com.tangem.tap.common.pushes.TangemPushNotificationService"
|
||||||
|
android:exported="false">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,103 @@
|
||||||
|
package com.tangem.tap.common.pushes
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.content.Intent
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
|
import coil.executeBlocking
|
||||||
|
import coil.request.ImageRequest
|
||||||
|
import com.google.firebase.messaging.FirebaseMessagingService
|
||||||
|
import com.google.firebase.messaging.RemoteMessage
|
||||||
|
import com.tangem.domain.common.LogConfig
|
||||||
|
import com.tangem.tap.MainActivity
|
||||||
|
import com.tangem.tap.common.images.createCoilImageLoader
|
||||||
|
import com.tangem.wallet.R
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
@SuppressLint("MissingFirebaseInstanceTokenRefresh")
|
||||||
|
internal class TangemPushNotificationService : FirebaseMessagingService() {
|
||||||
|
|
||||||
|
override fun onNewToken(token: String) {
|
||||||
|
super.onNewToken(token)
|
||||||
|
Timber.d("New FCM token received: $token")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMessageReceived(message: RemoteMessage) {
|
||||||
|
super.onMessageReceived(message)
|
||||||
|
|
||||||
|
val notification = message.notification ?: return
|
||||||
|
val channelId = notification.channelId ?: TANGEM_CHANNEL_ID
|
||||||
|
|
||||||
|
// TODO refactoring: [REDACTED_JIRA]
|
||||||
|
val intent = Intent(applicationContext, MainActivity::class.java)
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
|
val pendingIntent = PendingIntent.getActivity(
|
||||||
|
/* context = */ this,
|
||||||
|
/* requestCode = */ PUSH_NOTIFICATION_REQUEST_CODE,
|
||||||
|
/* intent = */ intent,
|
||||||
|
/* flags = */ PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE,
|
||||||
|
)
|
||||||
|
|
||||||
|
val notificationBuilder =
|
||||||
|
NotificationCompat.Builder(applicationContext, channelId)
|
||||||
|
.setSmallIcon(R.drawable.ic_tangem_24)
|
||||||
|
.setContentTitle(notification.title)
|
||||||
|
.setContentText(notification.body)
|
||||||
|
.setPriority(message.priority)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.setContentIntent(pendingIntent)
|
||||||
|
.setVibrate(notification.vibrateTimings)
|
||||||
|
.apply {
|
||||||
|
notification.imageUrl?.let { uri ->
|
||||||
|
val bitmap = getBitmapImageFromUrl(uri)
|
||||||
|
setStyle(
|
||||||
|
NotificationCompat
|
||||||
|
.BigPictureStyle()
|
||||||
|
.bigPicture(bitmap),
|
||||||
|
).setLargeIcon(bitmap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val notificationManager = applicationContext.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
val notificationChannel = NotificationChannel(
|
||||||
|
channelId,
|
||||||
|
ContextCompat.getString(applicationContext, R.string.tangem_app_name),
|
||||||
|
NotificationManager.IMPORTANCE_HIGH,
|
||||||
|
)
|
||||||
|
notificationManager.createNotificationChannel(notificationChannel)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generating unique notification id
|
||||||
|
val uniqueId = (System.currentTimeMillis() % Integer.MAX_VALUE).toInt()
|
||||||
|
|
||||||
|
notificationManager.notify(
|
||||||
|
/* id = */ uniqueId,
|
||||||
|
/* notification = */ notificationBuilder.build(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getBitmapImageFromUrl(url: Uri): Bitmap? {
|
||||||
|
return createCoilImageLoader(
|
||||||
|
applicationContext,
|
||||||
|
logEnabled = LogConfig.imageLoader,
|
||||||
|
).executeBlocking(
|
||||||
|
ImageRequest.Builder(applicationContext)
|
||||||
|
.data(url)
|
||||||
|
.build(),
|
||||||
|
).drawable?.toBitmap()
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val TANGEM_CHANNEL_ID = "Tangem General" // General channel for notifications
|
||||||
|
const val PUSH_NOTIFICATION_REQUEST_CODE = 123
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,6 @@ object NetworkLogConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
object AnalyticsHandlersLogConfig {
|
object AnalyticsHandlersLogConfig {
|
||||||
const val firebase: Boolean = false
|
val firebase: Boolean = BuildConfig.LOG_ENABLED
|
||||||
val amplitude: Boolean = BuildConfig.LOG_ENABLED
|
val amplitude: Boolean = BuildConfig.LOG_ENABLED
|
||||||
}
|
}
|
||||||
|
|
@ -176,6 +176,7 @@ compose-reorderable = { module = "org.burnoutcrew.composereorderable:reorderable
|
||||||
firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebase" }
|
firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebase" }
|
||||||
firebase-analytics = { module = "com.google.firebase:firebase-analytics-ktx" }
|
firebase-analytics = { module = "com.google.firebase:firebase-analytics-ktx" }
|
||||||
firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics-ktx" }
|
firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics-ktx" }
|
||||||
|
firebase-messaging = { module = "com.google.firebase:firebase-messaging-ktx" }
|
||||||
# endregion Firebase
|
# endregion Firebase
|
||||||
|
|
||||||
# region Tangem
|
# region Tangem
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue