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
1,236 changes: 1,236 additions & 0 deletions app/schemas/org.openedx.app.room.AppDatabase/4.json

Large diffs are not rendered by default.

32 changes: 26 additions & 6 deletions app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import org.openedx.core.presentation.settings.video.VideoQualityViewModel
import org.openedx.core.repository.CalendarRepository
import org.openedx.course.data.repository.CourseRepository
import org.openedx.course.domain.interactor.CourseInteractor
import org.openedx.course.presentation.assignments.CourseAssignmentViewModel
import org.openedx.course.presentation.container.CourseContainerViewModel
import org.openedx.course.presentation.contenttab.ContentTabViewModel
import org.openedx.course.presentation.dates.CourseDatesViewModel
import org.openedx.course.presentation.handouts.HandoutsViewModel
import org.openedx.course.presentation.offline.CourseOfflineViewModel
import org.openedx.course.presentation.outline.CourseOutlineViewModel
import org.openedx.course.presentation.outline.CourseContentAllViewModel
import org.openedx.course.presentation.progress.CourseProgressViewModel
import org.openedx.course.presentation.section.CourseSectionViewModel
import org.openedx.course.presentation.unit.container.CourseUnitContainerViewModel
Expand Down Expand Up @@ -281,7 +283,7 @@ val screenModule = module {
)
}
viewModel { (courseId: String, courseTitle: String) ->
CourseOutlineViewModel(
CourseContentAllViewModel(
courseId,
courseTitle,
get(),
Expand All @@ -300,6 +302,13 @@ val screenModule = module {
get(),
)
}
viewModel { (courseId: String, courseTitle: String) ->
ContentTabViewModel(
courseId,
courseTitle,
get(),
)
}
viewModel { (courseId: String) ->
CourseSectionViewModel(
courseId,
Expand All @@ -320,10 +329,9 @@ val screenModule = module {
get(),
)
}
viewModel { (courseId: String, courseTitle: String) ->
viewModel { (courseId: String) ->
CourseVideoViewModel(
courseId,
courseTitle,
get(),
get(),
get(),
Expand All @@ -343,19 +351,22 @@ val screenModule = module {
}
viewModel { (courseId: String) -> BaseVideoViewModel(courseId, get()) }
viewModel { (courseId: String) -> VideoViewModel(courseId, get(), get(), get(), get()) }
viewModel { (courseId: String) ->
viewModel { (courseId: String, videoUrl: String, blockId: String) ->
VideoUnitViewModel(
courseId,
videoUrl,
blockId,
get(),
get(),
get(),
get(),
get()
)
}
viewModel { (courseId: String, blockId: String) ->
viewModel { (courseId: String, videoUrl: String, blockId: String) ->
EncodedVideoUnitViewModel(
courseId,
videoUrl,
blockId,
get(),
get(),
Expand Down Expand Up @@ -538,4 +549,13 @@ val screenModule = module {
router = get()
)
}
viewModel { (courseId: String) ->
CourseAssignmentViewModel(
courseId = courseId,
interactor = get(),
courseRouter = get(),
courseNotifier = get(),
analytics = get()
)
}
}
8 changes: 6 additions & 2 deletions app/src/main/java/org/openedx/app/room/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.openedx.core.data.model.room.CourseProgressEntity
import org.openedx.core.data.model.room.CourseStructureEntity
import org.openedx.core.data.model.room.DownloadCoursePreview
import org.openedx.core.data.model.room.OfflineXBlockProgress
import org.openedx.core.data.model.room.VideoProgressEntity
import org.openedx.core.data.model.room.discovery.EnrolledCourseEntity
import org.openedx.core.data.storage.CourseDao
import org.openedx.core.module.db.CalendarDao
Expand All @@ -22,9 +23,10 @@ import org.openedx.discovery.data.converter.DiscoveryConverter
import org.openedx.discovery.data.model.room.CourseEntity
import org.openedx.discovery.data.storage.DiscoveryDao

const val DATABASE_VERSION = 3
const val DATABASE_VERSION = 4
const val DATABASE_NAME = "OpenEdX_db"

@Suppress("MagicNumber")
@Database(
entities = [
CourseEntity::class,
Expand All @@ -36,11 +38,13 @@ const val DATABASE_NAME = "OpenEdX_db"
CourseCalendarStateEntity::class,
DownloadCoursePreview::class,
CourseEnrollmentDetailsEntity::class,
VideoProgressEntity::class,
CourseProgressEntity::class,
],
autoMigrations = [
AutoMigration(1, 2),
AutoMigration(2, DATABASE_VERSION),
AutoMigration(2, 3),
AutoMigration(3, DATABASE_VERSION),
],
version = DATABASE_VERSION
)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/room/DatabaseManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DatabaseManager(
) : DatabaseManager {
override fun clearTables() {
CoroutineScope(Dispatchers.IO).launch {
courseDao.clearCourseData()
courseDao.clearCachedData()
dashboardDao.clearCachedData()
downloadDao.clearOfflineProgress()
discoveryDao.clearCachedData()
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/openedx/core/NoContentScreenType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ enum class NoContentScreenType(
iconResId = R.drawable.core_ic_no_content,
messageResId = R.string.core_no_dates
),
COURSE_ASSIGNMENT(
iconResId = R.drawable.core_ic_no_content,
messageResId = R.string.core_no_assignments
),
COURSE_DISCUSSIONS(
iconResId = R.drawable.core_ic_no_content,
messageResId = R.string.core_no_discussion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@ import com.google.gson.annotations.SerializedName
import org.openedx.core.data.model.room.AssignmentProgressDb
import org.openedx.core.domain.model.AssignmentProgress

private const val DEFAULT_LABEL_LENGTH = 5

data class AssignmentProgress(
@SerializedName("assignment_type")
val assignmentType: String?,
@SerializedName("num_points_earned")
val numPointsEarned: Float?,
@SerializedName("num_points_possible")
val numPointsPossible: Float?,
@SerializedName("short_label")
val shortLabel: String?
) {
fun mapToDomain() = AssignmentProgress(
assignmentType = assignmentType ?: "",
fun mapToDomain(displayName: String) = AssignmentProgress(
assignmentType = assignmentType,
numPointsEarned = numPointsEarned ?: 0f,
numPointsPossible = numPointsPossible ?: 0f
numPointsPossible = numPointsPossible ?: 0f,
shortLabel = shortLabel ?: displayName.take(DEFAULT_LABEL_LENGTH)
)

fun mapToRoomEntity() = AssignmentProgressDb(
assignmentType = assignmentType,
numPointsEarned = numPointsEarned,
numPointsPossible = numPointsPossible
numPointsPossible = numPointsPossible,
shortLabel = shortLabel
)
}
6 changes: 4 additions & 2 deletions core/src/main/java/org/openedx/core/data/model/Block.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ data class Block(
blockCounts = blockCounts?.mapToDomain()!!,
completion = completion ?: 0.0,
containsGatedContent = containsGatedContent ?: false,
assignmentProgress = assignmentProgress?.mapToDomain(),
assignmentProgress = assignmentProgress?.mapToDomain(displayName.orEmpty()),
due = TimeUtils.iso8601ToDate(due.orEmpty()),
offlineDownload = offlineDownload?.mapToDomain()
)
Expand Down Expand Up @@ -136,7 +136,9 @@ data class VideoInfo(
var fileSize: Long?
) {
fun mapToDomain() = DomainVideoInfo(
url = url.orEmpty(),
url = url
.orEmpty()
.trim(),
fileSize = fileSize ?: 0
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ data class CourseProgressResponse(
displayName = displayName ?: "",
subsections = subsections?.map { it.mapToDomain() } ?: emptyList()
)

data class Subsection(
@SerializedName("assignment_type") val assignmentType: String?,
@SerializedName("block_key") val blockKey: String?,
Expand Down Expand Up @@ -203,6 +204,7 @@ data class CourseProgressResponse(
showGrades = showGrades ?: false,
url = url ?: ""
)

data class ProblemScore(
@SerializedName("earned") val earned: Double?,
@SerializedName("possible") val possible: Double?
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/openedx/core/data/model/Progress.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ data class Progress(
val totalAssignmentsCount: Int?,
) {
fun mapToDomain() = Progress(
assignmentsCompleted = assignmentsCompleted ?: 0,
totalAssignmentsCount = totalAssignmentsCount ?: 0
completed = assignmentsCompleted ?: 0,
total = totalAssignmentsCount ?: 0
)

fun mapToRoomEntity() = ProgressDb(
Expand Down
10 changes: 7 additions & 3 deletions core/src/main/java/org/openedx/core/data/model/room/BlockDb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ data class VideoInfoDb(
fun createFrom(videoInfo: VideoInfo?): VideoInfoDb? {
if (videoInfo == null) return null
return VideoInfoDb(
videoInfo.url ?: "",
videoInfo.url
.orEmpty()
.trim(),
videoInfo.fileSize ?: 0,
)
}
Expand All @@ -230,11 +232,13 @@ data class AssignmentProgressDb(
val numPointsEarned: Float?,
@ColumnInfo("num_points_possible")
val numPointsPossible: Float?,
val shortLabel: String?
) {
fun mapToDomain() = DomainAssignmentProgress(
assignmentType = assignmentType ?: "",
assignmentType = assignmentType,
numPointsEarned = numPointsEarned ?: 0f,
numPointsPossible = numPointsPossible ?: 0f
numPointsPossible = numPointsPossible ?: 0f,
shortLabel = shortLabel ?: ""
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ data class GradingPolicyDb(
Color(colorString.toColorInt())
}
)

data class AssignmentPolicyDb(
@ColumnInfo("numDroppable")
val numDroppable: Int,
Expand Down Expand Up @@ -163,6 +164,7 @@ data class SectionScoreDb(
displayName = displayName,
subsections = subsections.map { it.mapToDomain() }
)

data class SubsectionDb(
@ColumnInfo("assignmentType")
val assignmentType: String,
Expand Down Expand Up @@ -206,6 +208,7 @@ data class SectionScoreDb(
showGrades = showGrades,
url = url
)

data class ProblemScoreDb(
@ColumnInfo("earned")
val earned: Double,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.openedx.core.data.model.room

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "video_progress_table")
data class VideoProgressEntity(
@PrimaryKey
@ColumnInfo("block_id")
val blockId: String,
@ColumnInfo("video_url")
val videoUrl: String,
@ColumnInfo("video_time")
val videoTime: Long,
@ColumnInfo("duration")
val duration: Long,
)
23 changes: 17 additions & 6 deletions core/src/main/java/org/openedx/core/data/storage/CourseDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.room.Transaction
import org.openedx.core.data.model.room.CourseEnrollmentDetailsEntity
import org.openedx.core.data.model.room.CourseProgressEntity
import org.openedx.core.data.model.room.CourseStructureEntity
import org.openedx.core.data.model.room.VideoProgressEntity

@Dao
interface CourseDao {
Expand All @@ -19,27 +20,37 @@ interface CourseDao {
suspend fun insertCourseStructureEntity(vararg courseStructureEntity: CourseStructureEntity)

@Transaction
suspend fun clearCourseData() {
clearCourseStructureData()
clearCourseProgressData()
suspend fun clearCachedData() {
clearCourseStructure()
clearVideoProgress()
clearEnrollmentCachedData()
clearCourseProgressData()
}

@Query("DELETE FROM course_structure_table")
suspend fun clearCourseStructureData()
suspend fun clearCourseStructure()

@Query("DELETE FROM course_progress_table")
suspend fun clearCourseProgressData()
@Query("DELETE FROM video_progress_table")
suspend fun clearVideoProgress()

@Query("DELETE FROM course_enrollment_details_table")
suspend fun clearEnrollmentCachedData()

@Query("DELETE FROM course_progress_table")
suspend fun clearCourseProgressData()

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCourseEnrollmentDetailsEntity(vararg courseEnrollmentDetailsEntity: CourseEnrollmentDetailsEntity)

@Query("SELECT * FROM course_enrollment_details_table WHERE id=:id")
suspend fun getCourseEnrollmentDetailsById(id: String): CourseEnrollmentDetailsEntity?

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertVideoProgressEntity(vararg videoProgressEntity: VideoProgressEntity)

@Query("SELECT * FROM video_progress_table WHERE block_id=:blockId")
suspend fun getVideoProgressByBlockId(blockId: String): VideoProgressEntity?

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCourseProgressEntity(vararg courseProgressEntity: CourseProgressEntity)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package org.openedx.core.domain.model

import android.os.Parcelable
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import org.openedx.core.extension.safeDivBy

@Parcelize
data class AssignmentProgress(
val assignmentType: String,
val assignmentType: String?,
val numPointsEarned: Float,
val numPointsPossible: Float
) : Parcelable
val numPointsPossible: Float,
val shortLabel: String
) : Parcelable {

@IgnoredOnParcel
val value: Float = numPointsEarned.safeDivBy(numPointsPossible)

fun toPointString(separator: String = ""): String {
return "${numPointsEarned.toInt()}$separator/$separator${numPointsPossible.toInt()}"
}

@IgnoredOnParcel
val label = shortLabel
.replace(" ", "")
.replaceFirst(Regex("^(\\D+)(0*)(\\d+)$"), "$1$3")
}
Loading
Loading