Skip to content

Commit

Permalink
Merge pull request openedx#261 from HamzaIsrar12/hamza/LEARNER-9875
Browse files Browse the repository at this point in the history
feat: Braze Push Notifications Capabilities
  • Loading branch information
farhan-arshad-dev authored Mar 19, 2024
2 parents beedcb3 + 53fe954 commit 40185f4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ android {
prod {
dimension 'env'
setupBranchConfigFields(it)
setupFirebaseConfigFields(it)
}
develop {
dimension 'env'
setupBranchConfigFields(it)
setupFirebaseConfigFields(it)
}
stage {
dimension 'env'
setupBranchConfigFields(it)
setupFirebaseConfigFields(it)
}
}

Expand Down Expand Up @@ -132,6 +135,10 @@ dependencies {
implementation 'com.segment.analytics.kotlin.destinations:firebase:1.5.2'
// Braze SDK Integration
implementation "com.braze:braze-segment-kotlin:1.4.2"
implementation "com.braze:android-sdk-ui:30.2.0"

// Firebase Cloud Messaging Integration for Braze
implementation 'com.google.firebase:firebase-messaging-ktx:23.4.1'

// Branch SDK Integration
implementation 'io.branch.sdk.android:library:5.9.0'
Expand Down Expand Up @@ -174,3 +181,11 @@ private def setupBranchConfigFields(buildType) {
buildType.resValue "string", "branch_host", branchHost
buildType.resValue "string", "branch_alternate_host", branchAlternateHost
}

private def setupFirebaseConfigFields(buildType) {
def firebaseConfig = configHelper.fetchConfig().get('FIREBASE')
def firebaseEnabled = firebaseConfig?.getOrDefault('ENABLED', false)
def cloudMessagingEnabled = firebaseConfig?.getOrDefault('CLOUD_MESSAGING_ENABLED', false)

buildType.manifestPlaceholders = [fcmEnabled: firebaseEnabled && cloudMessagingEnabled]
}
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />

<!-- Braze init -->
<service
android:name="com.braze.push.BrazeFirebaseMessagingService"
android:enabled="${fcmEnabled}"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>

</manifest>
15 changes: 15 additions & 0 deletions app/src/main/java/org/openedx/app/OpenEdXApp.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.openedx.app

import android.app.Application
import com.braze.Braze
import com.braze.configuration.BrazeConfig
import com.google.firebase.ktx.Firebase
import com.google.firebase.ktx.initialize
import io.branch.referral.Branch
Expand Down Expand Up @@ -37,5 +39,18 @@ class OpenEdXApp : Application() {
}
Branch.getAutoInstance(this)
}

if (config.getBrazeConfig().isEnabled && config.getFirebaseConfig().enabled) {
val isCloudMessagingEnabled = config.getFirebaseConfig().isCloudMessagingEnabled &&
config.getBrazeConfig().isPushNotificationsEnabled

val brazeConfig = BrazeConfig.Builder()
.setIsFirebaseCloudMessagingRegistrationEnabled(isCloudMessagingEnabled)
.setFirebaseCloudMessagingSenderIdKey(config.getFirebaseConfig().projectNumber)
.setHandlePushDeepLinksAutomatically(true)
.setIsFirebaseMessagingServiceOnNewTokenRegistrationEnabled(true)
.build()
Braze.configure(this, brazeConfig)
}
}
}
3 changes: 3 additions & 0 deletions core/src/main/java/org/openedx/core/config/FirebaseConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ data class FirebaseConfig(
@SerializedName("ANALYTICS_SOURCE")
val analyticsSource: AnalyticsSource = AnalyticsSource.NONE,

@SerializedName("CLOUD_MESSAGING_ENABLED")
val isCloudMessagingEnabled: Boolean = false,

@SerializedName("PROJECT_NUMBER")
val projectNumber: String = "",

Expand Down
8 changes: 8 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url "http://appboy.github.io/appboy-android-sdk/sdk"
allowInsecureProtocol = true
}
maven {
url "https://appboy.github.io/appboy-segment-android/sdk"
allowInsecureProtocol = true
}
maven { url "https://pkgs.dev.azure.com/MicrosoftDeviceSDK/DuoSDK-Public/_packaging/Duo-SDK-Feed/maven/v1" }
}
}
Expand Down

0 comments on commit 40185f4

Please sign in to comment.