-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More FCM infra: wire up token registration, analytics, toasts, primer… (
#226) … dialog. i haven't had a chance to test this end to end yet.
- Loading branch information
1 parent
3e9bfab
commit 50aceb7
Showing
16 changed files
with
226 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 43 additions & 16 deletions
59
v4/integration/fcm/src/main/java/exchange/dydx/trading/integration/fcm/DydxFCMService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,73 @@ | ||
package exchange.dydx.trading.integration.fcm | ||
|
||
import android.Manifest | ||
import android.app.Application | ||
import android.content.pm.PackageManager | ||
import android.util.Log | ||
import androidx.core.content.ContextCompat | ||
import com.google.android.gms.tasks.OnCompleteListener | ||
import com.google.firebase.messaging.FirebaseMessaging | ||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import exchange.dydx.dydxstatemanager.AbacusStateManager | ||
import exchange.dydx.dydxstatemanager.protocolImplementations.AbacusLocalizerImp | ||
import exchange.dydx.platformui.components.container.PlatformInfo | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class DydxFCMService : FirebaseMessagingService() { | ||
|
||
@Inject | ||
internal lateinit var fcmRegistrar: FCMRegistrar | ||
@Inject internal lateinit var fcmRegistrar: FCMRegistrar | ||
|
||
@Inject internal lateinit var platformInfo: PlatformInfo | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
fcmRegistrar.registerToken() | ||
} | ||
|
||
override fun onNewToken(token: String) { | ||
super.onNewToken(token) | ||
fcmRegistrar.registerToken(token) | ||
} | ||
|
||
override fun onMessageReceived(message: RemoteMessage) { | ||
super.onMessageReceived(message) | ||
message.notification?.let { notification -> | ||
platformInfo.show( | ||
title = notification.title, | ||
message = notification.body, | ||
) | ||
} | ||
} | ||
} | ||
|
||
class FCMRegistrar @Inject constructor( | ||
private val application: Application, | ||
private val abacusStateManager: AbacusStateManager, | ||
private val abacusLocalizerImp: AbacusLocalizerImp, | ||
) { | ||
|
||
fun registerToken() { | ||
FirebaseMessaging.getInstance().token.addOnCompleteListener( | ||
OnCompleteListener { task -> | ||
if (!task.isSuccessful) { | ||
return@OnCompleteListener | ||
} | ||
|
||
// Get new FCM registration token | ||
val token = task.result | ||
fcmRegistrar.registerToken(token) | ||
registerToken(task.result) | ||
}, | ||
) | ||
} | ||
|
||
override fun onNewToken(token: String) { | ||
super.onNewToken(token) | ||
fcmRegistrar.registerToken(token) | ||
} | ||
} | ||
|
||
internal class FCMRegistrar @Inject constructor( | ||
private val abacusStateManager: AbacusStateManager | ||
) { | ||
fun registerToken(token: String) { | ||
Log.d("FCMRegistrar", "registering token: $token") | ||
// call abacus method to register token | ||
// Only register token if permission has been granted. | ||
if (ContextCompat.checkSelfPermission(application, Manifest.permission.POST_NOTIFICATIONS) == | ||
PackageManager.PERMISSION_GRANTED | ||
) { | ||
Log.d("FCMRegistrar", "registering token: $token") | ||
abacusStateManager.registerPushToken(token, abacusLocalizerImp.language ?: "en") | ||
} | ||
} | ||
} |
Oops, something went wrong.