Skip to content

Commit 222b7f0

Browse files
feat: detekt fixes
1 parent c9f3cbe commit 222b7f0

File tree

9 files changed

+29
-16
lines changed

9 files changed

+29
-16
lines changed

course/src/main/java/org/openedx/course/presentation/container/CourseContainerFragment.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ fun CourseDashboard(
307307
bottomBar = {
308308
val currentPage = CourseContainerTab.entries[pagerState.currentPage]
309309
Box {
310-
if (currentPage == CourseContainerTab.CONTENT && selectedContentTab == CourseContentTab.ASSIGNMENTS) {
310+
if (currentPage == CourseContainerTab.CONTENT &&
311+
selectedContentTab == CourseContentTab.ASSIGNMENTS
312+
) {
311313
AssignmentsBottomBar(scope = scope, pagerState = pagerState)
312314
} else if (currentPage == CourseContainerTab.HOME) {
313315
HomeNavigationRow(homePagerState = homePagerState)

course/src/main/java/org/openedx/course/presentation/home/AssignmentsHomePagerCardContent.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ import org.openedx.course.presentation.contenttab.CourseContentAssignmentEmptySt
3838
import java.util.Date
3939
import org.openedx.core.R as coreR
4040

41+
private const val MILLISECONDS_PER_SECOND = 1000
42+
private const val SECONDS_PER_MINUTE = 60
43+
private const val MINUTES_PER_HOUR = 60
44+
private const val HOURS_PER_DAY = 24
45+
46+
private const val MILLISECONDS_PER_DAY =
47+
MILLISECONDS_PER_SECOND * SECONDS_PER_MINUTE * MINUTES_PER_HOUR * HOURS_PER_DAY
48+
4149
@Composable
4250
fun AssignmentsHomePagerCardContent(
4351
uiState: CourseHomeUIState.CourseData,
@@ -153,7 +161,7 @@ private fun AssignmentCard(
153161
// Due date status text
154162
val dueDateStatusText = assignment.due?.let { due ->
155163
val formattedDate = TimeUtils.formatToDayMonth(due)
156-
val daysDifference = ((due.time - Date().time) / (1000 * 60 * 60 * 24)).toInt()
164+
val daysDifference = ((due.time - Date().time) / MILLISECONDS_PER_DAY).toInt()
157165
when {
158166
daysDifference < 0 -> {
159167
// Past due
@@ -237,7 +245,6 @@ private fun AssignmentCard(
237245
Spacer(modifier = Modifier.height(4.dp))
238246
}
239247

240-
241248
// Assignment and section name
242249
Text(
243250
text = assignment.assignmentProgress?.assignmentType ?: "",

course/src/main/java/org/openedx/course/presentation/home/CourseHomePagerTab.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ enum class CourseHomePagerTab {
55
VIDEOS,
66
ASSIGNMENT,
77
GRADES
8-
}
8+
}

course/src/main/java/org/openedx/course/presentation/home/CourseHomeScreen.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ private fun CourseHomeUI(
343343
CourseHomeUIState.Loading -> {
344344
CircularProgress()
345345
}
346+
347+
CourseHomeUIState.Waiting -> {}
346348
}
347349
}
348350
}

course/src/main/java/org/openedx/course/presentation/home/CourseHomeUIState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ sealed class CourseHomeUIState {
2727

2828
data object Error : CourseHomeUIState()
2929
data object Loading : CourseHomeUIState()
30+
data object Waiting : CourseHomeUIState()
3031
}

course/src/main/java/org/openedx/course/presentation/home/CourseHomeViewModel.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CourseHomeViewModel(
7676
) {
7777
val isCourseDropdownNavigationEnabled get() = config.getCourseUIConfig().isCourseDropdownNavigationEnabled
7878

79-
private val _uiState = MutableStateFlow<CourseHomeUIState>(CourseHomeUIState.Loading)
79+
private val _uiState = MutableStateFlow<CourseHomeUIState>(CourseHomeUIState.Waiting)
8080
val uiState: StateFlow<CourseHomeUIState>
8181
get() = _uiState.asStateFlow()
8282

@@ -337,11 +337,15 @@ class CourseHomeViewModel(
337337
* where the first Block is the chapter and the second Block is the first incomplete subsection
338338
*/
339339
private fun findFirstChapterWithIncompleteDescendants(blocks: List<Block>): Pair<Block, Block>? {
340-
val incompleteChapterBlock =
341-
blocks.getChapterBlocks().find { !it.isCompleted() } ?: return null
342-
val incompleteSubsection =
343-
findFirstIncompleteSubsection(incompleteChapterBlock, blocks) ?: return null
344-
return Pair(incompleteChapterBlock, incompleteSubsection)
340+
val incompleteChapterBlock = blocks.getChapterBlocks().find { !it.isCompleted() }
341+
val incompleteSubsection = incompleteChapterBlock?.let {
342+
findFirstIncompleteSubsection(it, blocks)
343+
}
344+
return if (incompleteChapterBlock != null && incompleteSubsection != null) {
345+
Pair(incompleteChapterBlock, incompleteSubsection)
346+
} else {
347+
null
348+
}
345349
}
346350

347351
private fun findFirstIncompleteSubsection(chapter: Block, blocks: List<Block>): Block? {
@@ -534,6 +538,9 @@ class CourseHomeViewModel(
534538

535539
fun getCourseProgress() {
536540
viewModelScope.launch {
541+
if (_uiState.value !is CourseHomeUIState.CourseData) {
542+
_uiState.value = CourseHomeUIState.Loading
543+
}
537544
interactor.getCourseProgress(courseId, false)
538545
.catch { e ->
539546
if (_uiState.value !is CourseHomeUIState.CourseData) {

course/src/main/java/org/openedx/course/presentation/home/GradesHomePagerCardContent.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,3 @@ private fun GradeCardsGrid(
200200
}
201201
}
202202
}
203-

course/src/main/java/org/openedx/course/presentation/home/VideosHomePagerCardContent.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ fun VideosHomePagerCardContent(
3838
onViewAllVideosClick: () -> Unit
3939
) {
4040
val allVideos = uiState.courseVideos.values.flatten()
41-
4241
if (allVideos.isEmpty()) {
4342
CourseContentVideoEmptyState(
4443
onReturnToCourseClick = {},

course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,3 @@ private val mockChapterBlock = Block(
17551755
due = Date(),
17561756
offlineDownload = null
17571757
)
1758-
1759-
1760-
1761-

0 commit comments

Comments
 (0)