Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Branch deep links to local calendar events #249

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ dependencies {
// 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'
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
implementation "com.android.installreferrer:installreferrer:2.2"

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
Expand Down
5 changes: 5 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ dependencies {

api "androidx.webkit:webkit:$webkit_version"

// Branch SDK Integration
api "io.branch.sdk.android:library:5.9.0"
api "com.google.android.gms:play-services-ads-identifier:18.0.1"
api "com.android.installreferrer:installreferrer:2.2"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ data class CalendarSyncUIState(
val isSynced: Boolean = false,
val checkForOutOfSync: AtomicReference<Boolean> = AtomicReference(false),
val uiMessage: AtomicReference<String> = AtomicReference(""),
)
) {
val isDialogVisible: Boolean
get() = dialogType != CalendarSyncDialogType.NONE
}
25 changes: 14 additions & 11 deletions core/src/main/java/org/openedx/core/system/CalendarManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import android.database.Cursor
import android.net.Uri
import android.provider.CalendarContract
import androidx.core.content.ContextCompat
import io.branch.indexing.BranchUniversalObject
import io.branch.referral.util.ContentMetadata
import io.branch.referral.util.LinkProperties
import org.openedx.core.R
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.domain.model.CourseDateBlock
Expand Down Expand Up @@ -94,7 +97,7 @@ class CalendarManager(
contentValues.put(CalendarContract.Calendars.VISIBLE, 1)
contentValues.put(
CalendarContract.Calendars.CALENDAR_COLOR,
ContextCompat.getColor(context, org.openedx.core.R.color.primary)
ContextCompat.getColor(context, R.color.primary)
)
val creationUri: Uri? = asSyncAdapter(
Uri.parse(CalendarContract.Calendars.CONTENT_URI.toString()),
Expand Down Expand Up @@ -191,27 +194,27 @@ class CalendarManager(
courseDateBlock: CourseDateBlock,
isDeeplinkEnabled: Boolean
): String {
val eventDescription = courseDateBlock.title
// The following code for branch and deep links will be enabled after implementation
/*
if (isDeeplinkEnabled && !TextUtils.isEmpty(courseDateBlock.blockId)) {
var eventDescription = courseDateBlock.title

if (isDeeplinkEnabled && courseDateBlock.blockId.isNotEmpty()) {
val metaData = ContentMetadata()
.addCustomMetadata(DeepLink.Keys.SCREEN_NAME, Screen.COURSE_COMPONENT)
.addCustomMetadata(DeepLink.Keys.COURSE_ID, courseId)
.addCustomMetadata(DeepLink.Keys.COMPONENT_ID, courseDateBlock.blockId)
.addCustomMetadata("screen_name", "course_component")
.addCustomMetadata("course_id", courseId)
.addCustomMetadata("component_id", courseDateBlock.blockId)

val branchUniversalObject = BranchUniversalObject()
.setCanonicalIdentifier("${Screen.COURSE_COMPONENT}\n${courseDateBlock.blockId}")
.setCanonicalIdentifier("course_component\n${courseDateBlock.blockId}")
.setTitle(courseDateBlock.title)
.setContentDescription(courseDateBlock.title)
.setContentMetadata(metaData)

val linkProperties = LinkProperties()
.addControlParameter("\$desktop_url", courseDateBlock.link)

eventDescription += "\n" + branchUniversalObject.getShortUrl(context, linkProperties)
val shortUrl = branchUniversalObject.getShortUrl(context, linkProperties)
eventDescription += "\n$shortUrl"
}
*/

return eventDescription
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class CourseContainerViewModel(
}

is CreateCalendarSyncEvent -> {
// Skip out-of-sync check if any calendar dialog is visible
if (event.checkOutOfSync && _calendarSyncUIState.value.isDialogVisible) {
return@collect
}
_calendarSyncUIState.update {
val dialogType = CalendarSyncDialogType.valueOf(event.dialogType)
it.copy(
Expand Down
Loading