-
Notifications
You must be signed in to change notification settings - Fork 113
[CLXR-475][Horizon] Learn offline mode #3637
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
Changes from 22 commits
5375c00
fb2b3f9
1951eea
1072fe3
df03097
544244c
bdce3e9
2144299
63c70e2
9d6bf2d
c9451c1
1b88ec5
8a63d09
f35e607
8a189ce
4133a02
02a5fb7
d6756a6
144f16d
9ad5fae
e0d76be
594e6d0
3a76019
3a4dce1
8b723eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import com.instructure.canvas.espresso.mockcanvas.MockCanvas | |
| import com.instructure.canvasapi2.GetCoursesQuery | ||
| import com.instructure.canvasapi2.managers.graphql.horizon.CourseWithModuleItemDurations | ||
| import com.instructure.canvasapi2.managers.graphql.horizon.CourseWithProgress | ||
| import com.instructure.canvasapi2.managers.graphql.horizon.DashboardEnrollment | ||
| import com.instructure.canvasapi2.managers.graphql.horizon.HorizonGetCoursesManager | ||
| import com.instructure.canvasapi2.type.EnrollmentWorkflowState | ||
| import com.instructure.canvasapi2.utils.DataResult | ||
|
|
@@ -89,6 +90,33 @@ class FakeGetHorizonCourseManager(): HorizonGetCoursesManager { | |
| ) | ||
| } | ||
|
|
||
| override suspend fun getDashboardEnrollments( | ||
| userId: Long, | ||
| forceNetwork: Boolean | ||
| ): DataResult<List<DashboardEnrollment>> { | ||
| val enrollments = MockCanvas.data.enrollments.values.toList() | ||
| val courses = getCourses() | ||
| val dashboardEnrollments = courses.mapIndexedNotNull { index, course -> | ||
| val enrollmentId = enrollments.getOrNull(index)?.id ?: return@mapIndexedNotNull null | ||
| val state = when (index) { | ||
| 1 -> DashboardEnrollment.STATE_COMPLETED | ||
| 2 -> DashboardEnrollment.STATE_INVITED | ||
| else -> DashboardEnrollment.STATE_ACTIVE | ||
| } | ||
| DashboardEnrollment( | ||
| enrollmentId = enrollmentId, | ||
| enrollmentState = state, | ||
| courseId = course.courseId, | ||
| courseName = course.courseName, | ||
| courseImageUrl = course.courseImageUrl, | ||
| courseSyllabus = course.courseSyllabus, | ||
| institutionName = null, | ||
| completionPercentage = course.progress, | ||
| ) | ||
| } | ||
| return DataResult.Success(dashboardEnrollments) | ||
| } | ||
|
|
||
| override suspend fun getProgramCourses( | ||
| courseId: Long, | ||
| forceNetwork: Boolean | ||
|
|
@@ -112,7 +140,7 @@ class FakeGetHorizonCourseManager(): HorizonGetCoursesManager { | |
| courseName = courses[0].name, | ||
| courseImageUrl = null, | ||
| courseSyllabus = "Syllabus for Course 1", | ||
| progress = 0.25 | ||
| progress = 25.0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The progress values changed from fractions ( |
||
| ) | ||
| } else { null } | ||
| val completedCourse = if (courses.size > 1) { | ||
|
|
@@ -121,7 +149,7 @@ class FakeGetHorizonCourseManager(): HorizonGetCoursesManager { | |
| courseName = courses[1].name, | ||
| courseImageUrl = null, | ||
| courseSyllabus = "Syllabus for Course 2", | ||
| progress = 1.0 | ||
| progress = 100.0 | ||
| ) | ||
| } else { null } | ||
| val invitedCourse = if (courses.size > 2) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,11 @@ enum class CollectionItemType { | |
| EXTERNAL_URL, | ||
| EXTERNAL_TOOL, | ||
| FILE, | ||
| PROGRAM | ||
| PROGRAM; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Consider adding a Crashlytics log (non-fatal) or an |
||
|
|
||
| companion object { | ||
| fun safeValueOf(name: String): CollectionItemType? = entries.find { it.name == name } | ||
| } | ||
| } | ||
|
|
||
| fun ApolloCollectionItemType.toModel(): CollectionItemType { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Copyright (C) 2026 - present Instructure, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.instructure.horizon.espresso | ||
|
|
||
| import android.content.Context | ||
| import androidx.room.Room | ||
| import com.instructure.canvasapi2.utils.ApiPrefs | ||
| import com.instructure.horizon.database.HorizonDatabase | ||
| import com.instructure.horizon.database.dao.HorizonCourseDao | ||
| import com.instructure.horizon.database.dao.HorizonCourseModuleDao | ||
| import com.instructure.horizon.database.dao.HorizonCourseScoreDao | ||
| import com.instructure.horizon.database.dao.HorizonDashboardEnrollmentDao | ||
| import com.instructure.horizon.database.dao.HorizonDashboardModuleItemDao | ||
| import com.instructure.horizon.database.dao.HorizonFileFolderDao | ||
| import com.instructure.horizon.database.dao.HorizonLearnCollectionDao | ||
| import com.instructure.horizon.database.dao.HorizonLearnItemDao | ||
| import com.instructure.horizon.database.dao.HorizonLearnSavedItemDao | ||
| import com.instructure.horizon.database.dao.HorizonLocalFileDao | ||
| import com.instructure.horizon.database.dao.HorizonProgramDao | ||
| import com.instructure.horizon.database.dao.HorizonSyncMetadataDao | ||
| import com.instructure.horizon.di.HorizonHtmlParserQualifier | ||
| import com.instructure.horizon.di.HorizonOfflineModule | ||
| import com.instructure.horizon.offline.HorizonHtmlParserFileSource | ||
| import com.instructure.pandautils.features.offline.sync.HtmlParser | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import dagger.hilt.components.SingletonComponent | ||
| import dagger.hilt.testing.TestInstallIn | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @TestInstallIn(components = [SingletonComponent::class], replaces = [HorizonOfflineModule::class]) | ||
| object HorizonOfflineTestModule { | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun provideHorizonDatabase(@ApplicationContext context: Context): HorizonDatabase { | ||
| return Room.inMemoryDatabaseBuilder(context, HorizonDatabase::class.java) | ||
| .allowMainThreadQueries() | ||
| .build() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @Provides | ||
| fun provideHorizonDashboardEnrollmentDao(db: HorizonDatabase): HorizonDashboardEnrollmentDao = db.dashboardEnrollmentDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonProgramDao(db: HorizonDatabase): HorizonProgramDao = db.programDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonDashboardModuleItemDao(db: HorizonDatabase): HorizonDashboardModuleItemDao = db.dashboardModuleItemDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonSyncMetadataDao(db: HorizonDatabase): HorizonSyncMetadataDao = db.syncMetadataDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonLearnItemDao(db: HorizonDatabase): HorizonLearnItemDao = db.learnItemDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonLearnCollectionDao(db: HorizonDatabase): HorizonLearnCollectionDao = db.learnCollectionDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonLearnSavedItemDao(db: HorizonDatabase): HorizonLearnSavedItemDao = db.learnSavedItemDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonCourseDao(db: HorizonDatabase): HorizonCourseDao = db.courseDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonCourseModuleDao(db: HorizonDatabase): HorizonCourseModuleDao = db.courseModuleDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonCourseScoreDao(db: HorizonDatabase): HorizonCourseScoreDao = db.courseScoreDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonLocalFileDao(db: HorizonDatabase): HorizonLocalFileDao = db.localFileDao() | ||
|
|
||
| @Provides | ||
| fun provideHorizonFileFolderDao(db: HorizonDatabase): HorizonFileFolderDao = db.fileFolderDao() | ||
|
|
||
| @Provides | ||
| @HorizonHtmlParserQualifier | ||
| fun provideHorizonHtmlParser( | ||
| fileSource: HorizonHtmlParserFileSource, | ||
| apiPrefs: ApiPrefs, | ||
| @ApplicationContext context: Context, | ||
| ): HtmlParser = HtmlParser(fileSource, apiPrefs, context) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This index-based pairing of
coursesandenrollmentsis brittle. If the two lists ever differ in length (or ordering changes), unrelated courses/enrollments get silently paired — or enrollments are dropped with no error.Consider mapping enrollments by a stable key (e.g.
enrollmentIdtied tocourseId) rather than relying on positional alignment: