forked from openedx/openedx-app-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sync Course Dates to Calendar (openedx#228)
Calendar Sync Integration: - Integrated "Sync to Calendar" switch on Course Dates tab. - Dynamically show/hide switch based on Remote config. - Added user permission prompt for calendar access. - Added confirmation alert for initial course additions. - Included course dates as events in the local app calendar. - Added AlertDialog Loader for event creation/update. - Implemented Calendar preference for streamlined alert management. - Added user prompt for updating or removing the calendar. - Added a prompt for out-of-sync calendar situations. - Update calendar events on 'Shift Due Dates' CTA. Remote Config for Calendar Feature: - Retrieve remote config from LMS within the enrollments API. Store the configuration in CorePreferences, ensuring it is updated with each enrollments API call. - The CalendarSync Config now manages specific values pertinent to the Calendar Sync integration on both the Course Home and Dates tab. Fixes: LEARNER-9801
- Loading branch information
1 parent
fc5c648
commit 92d697f
Showing
31 changed files
with
1,731 additions
and
144 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
15 changes: 15 additions & 0 deletions
15
core/src/main/java/org/openedx/core/data/model/AppConfig.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.domain.model.AppConfig as DomainAppConfig | ||
|
||
data class AppConfig( | ||
@SerializedName("course_dates_calendar_sync") | ||
val calendarSyncConfig: CalendarSyncConfig = CalendarSyncConfig(), | ||
) { | ||
fun mapToDomain(): DomainAppConfig { | ||
return DomainAppConfig( | ||
courseDatesCalendarSync = calendarSyncConfig.mapToDomain(), | ||
) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
core/src/main/java/org/openedx/core/data/model/CalendarSyncConfig.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.domain.model.CourseDatesCalendarSync | ||
|
||
data class CalendarSyncConfig( | ||
@SerializedName("android") | ||
val platformConfig: CalendarSyncPlatform = CalendarSyncPlatform(), | ||
) { | ||
fun mapToDomain(): CourseDatesCalendarSync { | ||
return CourseDatesCalendarSync( | ||
isEnabled = platformConfig.enabled, | ||
isSelfPacedEnabled = platformConfig.selfPacedEnabled, | ||
isInstructorPacedEnabled = platformConfig.instructorPacedEnabled, | ||
isDeepLinkEnabled = platformConfig.deepLinksEnabled, | ||
) | ||
} | ||
} | ||
|
||
data class CalendarSyncPlatform( | ||
@SerializedName("enabled") | ||
val enabled: Boolean = false, | ||
@SerializedName("self_paced_enabled") | ||
val selfPacedEnabled: Boolean = false, | ||
@SerializedName("instructor_paced_enabled") | ||
val instructorPacedEnabled: Boolean = false, | ||
@SerializedName("deep_links_enabled") | ||
val deepLinksEnabled: Boolean = false, | ||
) |
65 changes: 63 additions & 2 deletions
65
core/src/main/java/org/openedx/core/data/model/CourseEnrollments.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,8 +1,69 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonDeserializer | ||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonObject | ||
import com.google.gson.annotations.SerializedName | ||
import java.lang.reflect.Type | ||
|
||
data class CourseEnrollments( | ||
@SerializedName("enrollments") | ||
val enrollments: DashboardCourseList | ||
) | ||
val enrollments: DashboardCourseList, | ||
|
||
@SerializedName("config") | ||
val configs: AppConfig, | ||
) { | ||
class Deserializer : JsonDeserializer<CourseEnrollments> { | ||
override fun deserialize( | ||
json: JsonElement?, | ||
typeOfT: Type?, | ||
context: JsonDeserializationContext? | ||
): CourseEnrollments { | ||
val enrollments = deserializeEnrollments(json) | ||
val appConfig = deserializeAppConfig(json) | ||
|
||
return CourseEnrollments(enrollments, appConfig) | ||
} | ||
|
||
private fun deserializeEnrollments(json: JsonElement?): DashboardCourseList { | ||
return try { | ||
Gson().fromJson( | ||
(json as JsonObject).get("enrollments"), | ||
DashboardCourseList::class.java | ||
) | ||
} catch (ex: Exception) { | ||
DashboardCourseList( | ||
next = null, | ||
previous = null, | ||
count = 0, | ||
numPages = 0, | ||
currentPage = 0, | ||
results = listOf() | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* To remove dependency on the backend, all the data related to Remote Config | ||
* will be received under the `configs` key. The `config` is the key under | ||
* 'configs` which defines the data that is related to the configuration of the | ||
* app. | ||
*/ | ||
private fun deserializeAppConfig(json: JsonElement?): AppConfig { | ||
return try { | ||
val config = (json as JsonObject) | ||
.getAsJsonObject("configs") | ||
.getAsJsonPrimitive("config") | ||
|
||
Gson().fromJson( | ||
config.asString, | ||
AppConfig::class.java | ||
) | ||
} catch (ex: Exception) { | ||
AppConfig() | ||
} | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
core/src/main/java/org/openedx/core/domain/model/AppConfig.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.openedx.core.domain.model | ||
|
||
import java.io.Serializable | ||
|
||
data class AppConfig( | ||
val courseDatesCalendarSync: CourseDatesCalendarSync, | ||
) : Serializable | ||
|
||
data class CourseDatesCalendarSync( | ||
val isEnabled: Boolean, | ||
val isSelfPacedEnabled: Boolean, | ||
val isInstructorPacedEnabled: Boolean, | ||
val isDeepLinkEnabled: Boolean, | ||
) : Serializable |
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
13 changes: 13 additions & 0 deletions
13
core/src/main/java/org/openedx/core/system/notifier/CalendarSyncEvent.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.openedx.core.system.notifier | ||
|
||
import org.openedx.core.domain.model.CourseDateBlock | ||
|
||
sealed class CalendarSyncEvent : CourseEvent { | ||
class CreateCalendarSyncEvent( | ||
val courseDates: List<CourseDateBlock>, | ||
val dialogType: String, | ||
val checkOutOfSync: Boolean, | ||
) : CalendarSyncEvent() | ||
|
||
class CheckCalendarSyncEvent(val isSynced: Boolean) : CalendarSyncEvent() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.READ_CALENDAR" /> | ||
<uses-permission android:name="android.permission.WRITE_CALENDAR" /> | ||
</manifest> |
6 changes: 6 additions & 0 deletions
6
course/src/main/java/org/openedx/course/data/storage/CoursePreferences.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.openedx.course.data.storage | ||
|
||
interface CoursePreferences { | ||
fun setCalendarSyncEventsDialogShown(courseName: String) | ||
fun isCalendarSyncEventsDialogShown(courseName: String): Boolean | ||
} |
Oops, something went wrong.