Skip to content

Commit a0c0c92

Browse files
feat: Google calendar sync (#470)
* feat: google calendar sync * fix: deleting not courses events * fix: switching between local and google calendars. Google calendars options.
1 parent 3db6518 commit a0c0c92

File tree

15 files changed

+851
-188
lines changed

15 files changed

+851
-188
lines changed

app/src/main/java/org/openedx/app/data/storage/PreferencesManager.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.openedx.core.data.storage.CalendarPreferences
88
import org.openedx.core.data.storage.CorePreferences
99
import org.openedx.core.data.storage.InAppReviewPreferences
1010
import org.openedx.core.domain.model.AppConfig
11+
import org.openedx.core.domain.model.CalendarType
1112
import org.openedx.core.domain.model.VideoQuality
1213
import org.openedx.core.domain.model.VideoSettings
1314
import org.openedx.core.system.CalendarManager
@@ -69,6 +70,7 @@ class PreferencesManager(context: Context) :
6970
override fun clearCalendarPreferences() {
7071
sharedPreferences.edit().apply {
7172
remove(CALENDAR_ID)
73+
remove(CALENDAR_TYPE)
7274
remove(IS_CALENDAR_SYNC_ENABLED)
7375
remove(HIDE_INACTIVE_COURSES)
7476
}.apply()
@@ -104,6 +106,17 @@ class PreferencesManager(context: Context) :
104106
}
105107
get() = getLong(CALENDAR_ID, CalendarManager.CALENDAR_DOES_NOT_EXIST)
106108

109+
override var calendarType: CalendarType
110+
set(value) {
111+
saveString(CALENDAR_TYPE, value.name)
112+
}
113+
get() {
114+
val storedType = getString(CALENDAR_TYPE, CalendarType.LOCAL.name)
115+
return runCatching {
116+
CalendarType.valueOf(storedType)
117+
}.getOrDefault(CalendarType.LOCAL)
118+
}
119+
107120
override var user: User?
108121
set(value) {
109122
val userJson = Gson().toJson(value)
@@ -234,6 +247,7 @@ class PreferencesManager(context: Context) :
234247
private const val VIDEO_SETTINGS_DOWNLOAD_QUALITY = "video_settings_download_quality"
235248
private const val APP_CONFIG = "app_config"
236249
private const val CALENDAR_ID = "CALENDAR_ID"
250+
private const val CALENDAR_TYPE = "CALENDAR_TYPE"
237251
private const val RESET_APP_DIRECTORY = "reset_app_directory"
238252
private const val IS_CALENDAR_SYNC_ENABLED = "IS_CALENDAR_SYNC_ENABLED"
239253
private const val IS_RELATIVE_DATES_ENABLED = "IS_RELATIVE_DATES_ENABLED"

auth/src/test/java/org/openedx/auth/presentation/signin/SignInViewModelTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import org.openedx.core.config.MicrosoftConfig
3737
import org.openedx.core.data.storage.CalendarPreferences
3838
import org.openedx.core.data.storage.CorePreferences
3939
import org.openedx.core.domain.interactor.CalendarInteractor
40+
import org.openedx.core.domain.model.CalendarType
4041
import org.openedx.core.presentation.global.WhatsNewGlobalManager
4142
import org.openedx.core.system.EdxError
4243
import org.openedx.core.system.notifier.app.AppNotifier
@@ -91,6 +92,7 @@ class SignInViewModelTest {
9192
every { config.getGoogleConfig() } returns GoogleConfig()
9293
every { config.getMicrosoftConfig() } returns MicrosoftConfig()
9394
every { calendarPreferences.calendarUser } returns ""
95+
every { calendarPreferences.calendarType } returns CalendarType.LOCAL
9496
every { calendarPreferences.clearCalendarPreferences() } returns Unit
9597
coEvery { calendarInteractor.clearCalendarCachedData() } returns Unit
9698
every { analytics.logScreenEvent(any(), any()) } returns Unit

core/src/main/java/org/openedx/core/data/storage/CalendarPreferences.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package org.openedx.core.data.storage
22

3+
import org.openedx.core.domain.model.CalendarType
4+
35
interface CalendarPreferences {
46
var calendarId: Long
57
var calendarUser: String
8+
var calendarType: CalendarType
69
var isCalendarSyncEnabled: Boolean
710
var isHideInactiveCourses: Boolean
811

core/src/main/java/org/openedx/core/domain/interactor/CalendarInteractor.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class CalendarInteractor(
2222
return repository.getCourseCalendarEventsByIdFromCache(courseId)
2323
}
2424

25+
suspend fun getAllCourseCalendarEventsFromCache(): List<CourseCalendarEvent> {
26+
return repository.getAllCourseCalendarEventsFromCache()
27+
}
28+
2529
suspend fun deleteCourseCalendarEntitiesByIdFromCache(courseId: String) {
2630
repository.deleteCourseCalendarEntitiesByIdFromCache(courseId)
2731
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.openedx.core.domain.model
2+
3+
enum class CalendarType {
4+
LOCAL,
5+
GOOGLE,
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.openedx.core.domain.model
2+
3+
data class UserCalendar(
4+
val id: Long,
5+
val title: String,
6+
val color: Int
7+
)

core/src/main/java/org/openedx/core/module/db/CalendarDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ interface CalendarDao {
2121
@Query("SELECT * FROM course_calendar_event_table WHERE course_id=:courseId")
2222
suspend fun readCourseCalendarEventsById(courseId: String): List<CourseCalendarEventEntity>
2323

24+
@Query("SELECT * FROM course_calendar_event_table")
25+
suspend fun readAllCourseCalendarEvents(): List<CourseCalendarEventEntity>
26+
2427
@Query("DELETE FROM course_calendar_event_table")
2528
suspend fun clearCourseCalendarEventsCachedData()
2629

core/src/main/java/org/openedx/core/repository/CalendarRepository.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class CalendarRepository(
3030
return calendarDao.readCourseCalendarEventsById(courseId).map { it.mapToDomain() }
3131
}
3232

33+
suspend fun getAllCourseCalendarEventsFromCache(): List<CourseCalendarEvent> {
34+
return calendarDao.readAllCourseCalendarEvents().map { it.mapToDomain() }
35+
}
36+
3337
suspend fun deleteCourseCalendarEntitiesByIdFromCache(courseId: String) {
3438
calendarDao.deleteCourseCalendarEntitiesById(courseId)
3539
}

0 commit comments

Comments
 (0)