Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.openedx.core.data.storage.CalendarPreferences
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.data.storage.InAppReviewPreferences
import org.openedx.core.domain.model.AppConfig
import org.openedx.core.domain.model.CalendarType
import org.openedx.core.domain.model.VideoQuality
import org.openedx.core.domain.model.VideoSettings
import org.openedx.core.system.CalendarManager
Expand Down Expand Up @@ -69,6 +70,7 @@ class PreferencesManager(context: Context) :
override fun clearCalendarPreferences() {
sharedPreferences.edit().apply {
remove(CALENDAR_ID)
remove(CALENDAR_TYPE)
remove(IS_CALENDAR_SYNC_ENABLED)
remove(HIDE_INACTIVE_COURSES)
}.apply()
Expand Down Expand Up @@ -104,6 +106,17 @@ class PreferencesManager(context: Context) :
}
get() = getLong(CALENDAR_ID, CalendarManager.CALENDAR_DOES_NOT_EXIST)

override var calendarType: CalendarType
set(value) {
saveString(CALENDAR_TYPE, value.name)
}
get() {
val storedType = getString(CALENDAR_TYPE, CalendarType.LOCAL.name)
return runCatching {
CalendarType.valueOf(storedType)
}.getOrDefault(CalendarType.LOCAL)
}

override var user: User?
set(value) {
val userJson = Gson().toJson(value)
Expand Down Expand Up @@ -234,6 +247,7 @@ class PreferencesManager(context: Context) :
private const val VIDEO_SETTINGS_DOWNLOAD_QUALITY = "video_settings_download_quality"
private const val APP_CONFIG = "app_config"
private const val CALENDAR_ID = "CALENDAR_ID"
private const val CALENDAR_TYPE = "CALENDAR_TYPE"
private const val RESET_APP_DIRECTORY = "reset_app_directory"
private const val IS_CALENDAR_SYNC_ENABLED = "IS_CALENDAR_SYNC_ENABLED"
private const val IS_RELATIVE_DATES_ENABLED = "IS_RELATIVE_DATES_ENABLED"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.openedx.core.config.MicrosoftConfig
import org.openedx.core.data.storage.CalendarPreferences
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.domain.interactor.CalendarInteractor
import org.openedx.core.domain.model.CalendarType
import org.openedx.core.presentation.global.WhatsNewGlobalManager
import org.openedx.core.system.EdxError
import org.openedx.core.system.notifier.app.AppNotifier
Expand Down Expand Up @@ -91,6 +92,7 @@ class SignInViewModelTest {
every { config.getGoogleConfig() } returns GoogleConfig()
every { config.getMicrosoftConfig() } returns MicrosoftConfig()
every { calendarPreferences.calendarUser } returns ""
every { calendarPreferences.calendarType } returns CalendarType.LOCAL
every { calendarPreferences.clearCalendarPreferences() } returns Unit
coEvery { calendarInteractor.clearCalendarCachedData() } returns Unit
every { analytics.logScreenEvent(any(), any()) } returns Unit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.openedx.core.data.storage

import org.openedx.core.domain.model.CalendarType

interface CalendarPreferences {
var calendarId: Long
var calendarUser: String
var calendarType: CalendarType
var isCalendarSyncEnabled: Boolean
var isHideInactiveCourses: Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class CalendarInteractor(
return repository.getCourseCalendarEventsByIdFromCache(courseId)
}

suspend fun getAllCourseCalendarEventsFromCache(): List<CourseCalendarEvent> {
return repository.getAllCourseCalendarEventsFromCache()
}

suspend fun deleteCourseCalendarEntitiesByIdFromCache(courseId: String) {
repository.deleteCourseCalendarEntitiesByIdFromCache(courseId)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.openedx.core.domain.model

enum class CalendarType {
LOCAL,
GOOGLE,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.openedx.core.domain.model

data class UserCalendar(
val id: Long,
val title: String,
val color: Int
)
3 changes: 3 additions & 0 deletions core/src/main/java/org/openedx/core/module/db/CalendarDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ interface CalendarDao {
@Query("SELECT * FROM course_calendar_event_table WHERE course_id=:courseId")
suspend fun readCourseCalendarEventsById(courseId: String): List<CourseCalendarEventEntity>

@Query("SELECT * FROM course_calendar_event_table")
suspend fun readAllCourseCalendarEvents(): List<CourseCalendarEventEntity>

@Query("DELETE FROM course_calendar_event_table")
suspend fun clearCourseCalendarEventsCachedData()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class CalendarRepository(
return calendarDao.readCourseCalendarEventsById(courseId).map { it.mapToDomain() }
}

suspend fun getAllCourseCalendarEventsFromCache(): List<CourseCalendarEvent> {
return calendarDao.readAllCourseCalendarEvents().map { it.mapToDomain() }
}

suspend fun deleteCourseCalendarEntitiesByIdFromCache(courseId: String) {
calendarDao.deleteCourseCalendarEntitiesById(courseId)
}
Expand Down
Loading
Loading