Skip to content

Commit

Permalink
feat: added a patch from Omer Habib
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloNetrebchuk committed May 29, 2024
1 parent 7ef6b77 commit 3fd6657
Show file tree
Hide file tree
Showing 20 changed files with 48 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
android:id="@+id/bottom_nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
app:itemIconTint="@color/bottom_nav_color"
app:itemTextColor="@color/bottom_nav_color"
android:background="@color/background"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class CourseAssignments(
@SerializedName("future_assignments")
val futureAssignments: List<CourseDateBlock>?,
@SerializedName("past_assignments")
val pastAssignments: List<CourseDateBlock>?
val pastAssignments: List<CourseDateBlock>?,
) {
fun mapToDomain() = CourseAssignments(
futureAssignments = futureAssignments?.mapNotNull {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class CourseEnrollments(
override fun deserialize(
json: JsonElement?,
typeOfT: Type?,
context: JsonDeserializationContext?
context: JsonDeserializationContext?,
): CourseEnrollments {
val enrollments = deserializeEnrollments(json)
val appConfig = deserializeAppConfig(json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class CourseStatus(
@SerializedName("last_visited_block_id")
val lastVisitedBlockId: String?,
@SerializedName("last_visited_unit_display_name")
val lastVisitedUnitDisplayName: String?
val lastVisitedUnitDisplayName: String?,
) {
fun mapToDomain() = CourseStatus(
lastVisitedModuleId = lastVisitedModuleId ?: "",
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/openedx/core/data/model/Progress.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class Progress(
@SerializedName("assignments_completed")
val assignmentsCompleted: Int?,
@SerializedName("total_assignments_count")
val totalAssignmentsCount: Int?
val totalAssignmentsCount: Int?,
) {
fun mapToDomain() = Progress(
assignmentsCompleted = assignmentsCompleted ?: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data class EnrolledCourseEntity(
@Embedded
val courseStatus: CourseStatusDb?,
@Embedded
val courseAssignments: CourseAssignmentsDb?
val courseAssignments: CourseAssignmentsDb?,
) {

fun mapToDomain(): EnrolledCourse {
Expand Down Expand Up @@ -98,7 +98,7 @@ data class EnrolledCourseDataDb(
@ColumnInfo("videoOutline")
val videoOutline: String,
@ColumnInfo("isSelfPaced")
val isSelfPaced: Boolean
val isSelfPaced: Boolean,
) {
fun mapToDomain(): EnrolledCourseData {
return EnrolledCourseData(
Expand Down Expand Up @@ -138,7 +138,7 @@ data class CoursewareAccessDb(
@ColumnInfo("additionalContextUserMessage")
val additionalContextUserMessage: String,
@ColumnInfo("userFragment")
val userFragment: String
val userFragment: String,
) {

fun mapToDomain(): CoursewareAccess {
Expand All @@ -156,7 +156,7 @@ data class CoursewareAccessDb(

data class CertificateDb(
@ColumnInfo("certificateURL")
val certificateURL: String?
val certificateURL: String?,
) {
fun mapToDomain() = Certificate(certificateURL)
}
Expand All @@ -165,7 +165,7 @@ data class CourseSharingUtmParametersDb(
@ColumnInfo("facebook")
val facebook: String,
@ColumnInfo("twitter")
val twitter: String
val twitter: String,
) {
fun mapToDomain() = CourseSharingUtmParameters(
facebook, twitter
Expand Down Expand Up @@ -204,7 +204,7 @@ data class CourseAssignmentsDb(
@ColumnInfo("futureAssignments")
val futureAssignments: List<CourseDateBlockDb>?,
@ColumnInfo("pastAssignments")
val pastAssignments: List<CourseDateBlockDb>?
val pastAssignments: List<CourseDateBlockDb>?,
) {
fun mapToDomain() = CourseAssignments(
futureAssignments = futureAssignments?.map { it.mapToDomain() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ data class CourseStatus(
val lastVisitedModuleId: String,
val lastVisitedModulePath: List<String>,
val lastVisitedBlockId: String,
val lastVisitedUnitDisplayName: String
val lastVisitedUnitDisplayName: String,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import java.io.File

class DownloadWorker(
val context: Context,
parameters: WorkerParameters
parameters: WorkerParameters,
) : CoroutineWorker(context, parameters), CoroutineScope {

private val notificationManager =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.nio.charset.Charset
import java.util.concurrent.TimeUnit

class TranscriptManager(
val context: Context
val context: Context,
) {

private val transcriptDownloader = object : AbstractDownloader() {
Expand All @@ -31,7 +31,9 @@ class TranscriptManager(
val transcriptDir = getTranscriptDir() ?: return false
val hash = Sha1Util.SHA1(url)
val file = File(transcriptDir, hash)
return file.exists() && System.currentTimeMillis() - file.lastModified() < TimeUnit.HOURS.toMillis(5)
return file.exists() && System.currentTimeMillis() - file.lastModified() < TimeUnit.HOURS.toMillis(
5
)
}

fun get(url: String): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,11 @@ class CourseContainerFragment : Fragment(R.layout.fragment_course_container) {
const val ARG_ENROLLMENT_MODE = "enrollmentMode"
const val ARG_OPEN_TAB = "open_tab"
const val ARG_RESUME_BLOCK = "resume_block"
const val DEFAULT_TAB = "home"
fun newInstance(
courseId: String,
courseTitle: String,
enrollmentMode: String,
openTab: String = DEFAULT_TAB,
openTab: String = CourseContainerTab.HOME.name,
resumeBlockId: String = ""
): CourseContainerFragment {
val fragment = CourseContainerFragment()
Expand Down Expand Up @@ -303,7 +302,7 @@ fun CourseDashboard(
val refreshing by viewModel.refreshing.collectAsState(true)
val courseImage by viewModel.courseImage.collectAsState()
val uiMessage by viewModel.uiMessage.collectAsState(null)
val openTab = bundle.getString(CourseContainerFragment.ARG_OPEN_TAB, CourseContainerFragment.DEFAULT_TAB)
val openTab = bundle.getString(CourseContainerFragment.ARG_OPEN_TAB, CourseContainerTab.HOME.name)
val requiredTab = when (openTab.uppercase()) {
CourseContainerTab.HOME.name -> CourseContainerTab.HOME
CourseContainerTab.VIDEOS.name -> CourseContainerTab.VIDEOS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.openedx.course.R
enum class CourseContainerTab(
@StringRes
override val labelResId: Int,
override val icon: ImageVector
override val icon: ImageVector,
) : TabItem {
HOME(R.string.course_container_nav_home, Icons.Default.Home),
VIDEOS(R.string.course_container_nav_videos, Icons.Rounded.PlayCircleFilled),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class CourseContainerViewModel(
private val coursePreferences: CoursePreferences,
private val courseAnalytics: CourseAnalytics,
private val imageProcessor: ImageProcessor,
val courseRouter: CourseRouter
val courseRouter: CourseRouter,
) : BaseViewModel() {

private val _dataReady = MutableLiveData<Boolean?>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ class AllEnrolledCoursesFragment : Fragment() {

@Composable
private fun AllEnrolledCoursesView(
viewModel: AllEnrolledCoursesViewModel = koinViewModel(),
fragmentManager: FragmentManager
) {
val viewModel: AllEnrolledCoursesViewModel = koinViewModel()
val uiState by viewModel.uiState.collectAsState()
val uiMessage by viewModel.uiMessage.collectAsState(null)

Expand Down Expand Up @@ -455,8 +455,8 @@ private val mockCourseEnrolled = EnrolledCourse(
dynamicUpgradeDeadline = "",
subscriptionId = "",
coursewareAccess = CoursewareAccess(
true,
"",
false,
"204",
"",
"",
"",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.openedx.courses.presentation

enum class CourseTab {
HOME, VIDEOS, DATES, DISCUSSIONS, MORE
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ import org.openedx.core.R as CoreR

@Composable
fun DashboardGalleryView(
viewModel: DashboardGalleryViewModel = koinViewModel(),
fragmentManager: FragmentManager,
) {
val viewModel: DashboardGalleryViewModel = koinViewModel()
val updating by viewModel.updating.collectAsState(false)
val uiMessage by viewModel.uiMessage.collectAsState(null)
val uiState by viewModel.uiState.collectAsState(DashboardGalleryUIState.Loading)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,13 @@ class DashboardGalleryViewModel(
private val discoveryNotifier: DiscoveryNotifier,
private val networkConnection: NetworkConnection,
private val fileUtil: FileUtil,
private val dashboardRouter: DashboardRouter
private val dashboardRouter: DashboardRouter,
) : BaseViewModel() {

companion object {
private const val DATES_TAB = "dates"
}

val apiHostUrl get() = config.getApiHostURL()

private val _uiState = MutableStateFlow<DashboardGalleryUIState>(DashboardGalleryUIState.Loading)
private val _uiState =
MutableStateFlow<DashboardGalleryUIState>(DashboardGalleryUIState.Loading)
val uiState: StateFlow<DashboardGalleryUIState>
get() = _uiState.asStateFlow()

Expand Down Expand Up @@ -76,7 +73,8 @@ class DashboardGalleryViewModel(
if (courseEnrollments == null) {
_uiState.value = DashboardGalleryUIState.Empty
} else {
_uiState.value = DashboardGalleryUIState.Courses(courseEnrollments.mapToDomain())
_uiState.value =
DashboardGalleryUIState.Courses(courseEnrollments.mapToDomain())
}
}
} catch (e: Exception) {
Expand Down Expand Up @@ -108,14 +106,14 @@ class DashboardGalleryViewModel(
fragmentManager: FragmentManager,
enrolledCourse: EnrolledCourse,
openDates: Boolean = false,
resumeBlockId: String = ""
resumeBlockId: String = "",
) {
dashboardRouter.navigateToCourseOutline(
fm = fragmentManager,
courseId = enrolledCourse.course.id,
courseTitle = enrolledCourse.course.name,
enrollmentMode = enrolledCourse.mode,
openTab = if (openDates) DATES_TAB else "",
openTab = if (openDates) CourseTab.DATES.name else CourseTab.HOME.name,
resumeBlockId = resumeBlockId
)
}
Expand All @@ -136,7 +134,9 @@ interface DashboardGalleryScreenAction {
object ViewAll : DashboardGalleryScreenAction
object Reload : DashboardGalleryScreenAction
object NavigateToDiscovery : DashboardGalleryScreenAction
data class OpenBlock(val enrolledCourse: EnrolledCourse, val blockId: String) : DashboardGalleryScreenAction
data class OpenBlock(val enrolledCourse: EnrolledCourse, val blockId: String) :
DashboardGalleryScreenAction

data class OpenCourse(val enrolledCourse: EnrolledCourse) : DashboardGalleryScreenAction
data class NavigateToDates(val enrolledCourse: EnrolledCourse) : DashboardGalleryScreenAction
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum class CourseStatusFilter(
val key: String,
@StringRes
override val labelResId: Int,
override val icon: ImageVector? = null
override val icon: ImageVector? = null,
) : TabItem {
ALL("all", R.string.dashboard_course_filter_all),
IN_PROGRESS("in_progress", R.string.dashboard_course_filter_in_progress),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.openedx.dashboard.data.repository.DashboardRepository
import org.openedx.dashboard.domain.CourseStatusFilter

class DashboardInteractor(
private val repository: DashboardRepository
private val repository: DashboardRepository,
) {

suspend fun getEnrolledCourses(page: Int): DashboardCourseList {
Expand All @@ -16,7 +16,10 @@ class DashboardInteractor(

suspend fun getMainUserCourses() = repository.getMainUserCourses()

suspend fun getAllUserCourses(page: Int = 1, status: CourseStatusFilter? = null): DashboardCourseList {
suspend fun getAllUserCourses(
page: Int = 1,
status: CourseStatusFilter? = null,
): DashboardCourseList {
return repository.getAllUserCourses(
page,
status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ class LearnFragment : Fragment(R.layout.fragment_learn) {

@Composable
private fun Header(
viewModel: LearnViewModel = koinViewModel(),
fragmentManager: FragmentManager,
viewPager: ViewPager2
) {
val viewModel: LearnViewModel = koinViewModel()
val windowSize = rememberWindowSize()
val contentWidth by remember(key1 = windowSize) {
mutableStateOf(
Expand Down
2 changes: 1 addition & 1 deletion default_config/dev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PROGRAM:
PROGRAM_DETAIL_URL_TEMPLATE: ''

DASHBOARD:
TYPE: 'primary_course'
TYPE: 'gallery'

FIREBASE:
ENABLED: false
Expand Down

0 comments on commit 3fd6657

Please sign in to comment.