Skip to content

Commit

Permalink
fix: Minor bugbash fixes (openedx#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
dixidroid authored Oct 29, 2024
1 parent 44f106d commit 0ff62f0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
22 changes: 5 additions & 17 deletions core/src/main/java/org/openedx/core/extension/ViewExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,11 @@ fun WebView.loadUrl(url: String, scope: CoroutineScope, cookieManager: AppCookie
}

fun WebView.applyDarkModeIfEnabled(isDarkTheme: Boolean) {
if (isDarkTheme && WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
settings.setAlgorithmicDarkeningAllowed(true)
} else {
// Switch WebView to dark mode; uses default dark theme
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
WebSettingsCompat.setForceDark(
settings,
WebSettingsCompat.FORCE_DARK_ON
)
}
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
WebSettingsCompat.setForceDarkStrategy(
settings,
WebSettingsCompat.DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING
)
}
if (isDarkTheme && WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) {
try {
WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, true)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun CourseOutlineScreen(
windowSize: WindowSize,
viewModel: CourseOutlineViewModel,
fragmentManager: FragmentManager,
onResetDatesClick: () -> Unit
onResetDatesClick: () -> Unit,
) {
val uiState by viewModel.uiState.collectAsState()
val uiMessage by viewModel.uiMessage.collectAsState(null)
Expand Down Expand Up @@ -288,12 +288,14 @@ private fun CourseOutlineUI(
ResumeCourseTablet(
modifier = Modifier.padding(vertical = 16.dp),
block = uiState.resumeComponent,
displayName = uiState.resumeUnitTitle,
onResumeClick = onResumeClick
)
} else {
ResumeCourse(
modifier = Modifier.padding(vertical = 16.dp),
block = uiState.resumeComponent,
displayName = uiState.resumeUnitTitle,
onResumeClick = onResumeClick
)
}
Expand Down Expand Up @@ -341,6 +343,7 @@ private fun CourseOutlineUI(
private fun ResumeCourse(
modifier: Modifier = Modifier,
block: Block,
displayName: String,
onResumeClick: (String) -> Unit,
) {
Column(
Expand All @@ -363,7 +366,7 @@ private fun ResumeCourse(
tint = MaterialTheme.appColors.textPrimary
)
Text(
text = block.displayName,
text = displayName,
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.titleMedium,
maxLines = 1,
Expand Down Expand Up @@ -393,6 +396,7 @@ private fun ResumeCourse(
private fun ResumeCourseTablet(
modifier: Modifier = Modifier,
block: Block,
displayName: String,
onResumeClick: (String) -> Unit,
) {
Row(
Expand Down Expand Up @@ -421,7 +425,7 @@ private fun ResumeCourseTablet(
tint = MaterialTheme.appColors.textPrimary
)
Text(
text = block.displayName,
text = displayName,
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.titleMedium,
overflow = TextOverflow.Ellipsis,
Expand Down Expand Up @@ -450,7 +454,7 @@ private fun ResumeCourseTablet(
@Composable
private fun CourseProgress(
modifier: Modifier = Modifier,
progress: Progress
progress: Progress,
) {
Column(
modifier = modifier,
Expand Down Expand Up @@ -498,6 +502,7 @@ private fun CourseOutlineScreenPreview() {
mockCourseStructure,
mapOf(),
mockChapterBlock,
"Resumed Unit",
mapOf(),
mapOf(),
mapOf(),
Expand Down Expand Up @@ -532,6 +537,7 @@ private fun CourseOutlineScreenTabletPreview() {
mockCourseStructure,
mapOf(),
mockChapterBlock,
"Resumed Unit",
mapOf(),
mapOf(),
mapOf(),
Expand Down Expand Up @@ -560,7 +566,7 @@ private fun CourseOutlineScreenTabletPreview() {
@Composable
private fun ResumeCoursePreview() {
OpenEdXTheme {
ResumeCourse(block = mockChapterBlock) {}
ResumeCourse(block = mockChapterBlock, displayName = "Resumed Unit") {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sealed class CourseOutlineUIState {
val courseStructure: CourseStructure,
val downloadedState: Map<String, DownloadedState>,
val resumeComponent: Block?,
val resumeUnitTitle: String,
val courseSubSections: Map<String, List<Block>>,
val courseSectionsState: Map<String, Boolean>,
val subSectionsDownloadsCount: Map<String, Int>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class CourseOutlineViewModel(
courseStructure = state.courseStructure,
downloadedState = it.toMap(),
resumeComponent = state.resumeComponent,
resumeUnitTitle = resumeVerticalBlock?.displayName ?: "",
courseSubSections = courseSubSections,
courseSectionsState = state.courseSectionsState,
subSectionsDownloadsCount = subSectionsDownloadsCount,
Expand Down Expand Up @@ -155,6 +156,7 @@ class CourseOutlineViewModel(
courseStructure = state.courseStructure,
downloadedState = state.downloadedState,
resumeComponent = state.resumeComponent,
resumeUnitTitle = resumeVerticalBlock?.displayName ?: "",
courseSubSections = courseSubSections,
courseSectionsState = courseSectionsState,
subSectionsDownloadsCount = subSectionsDownloadsCount,
Expand Down Expand Up @@ -213,6 +215,7 @@ class CourseOutlineViewModel(
courseStructure = courseStructure,
downloadedState = getDownloadModelsStatus(),
resumeComponent = getResumeBlock(blocks, courseStatus.lastVisitedBlockId),
resumeUnitTitle = resumeVerticalBlock?.displayName ?: "",
courseSubSections = courseSubSections,
courseSectionsState = courseSectionsState,
subSectionsDownloadsCount = subSectionsDownloadsCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ private fun AllEnrolledCoursesView(
scaffoldState = scaffoldState,
modifier = Modifier
.fillMaxSize()
.navigationBarsPadding()
.semantics {
testTagsAsResourceId = true
},
Expand Down Expand Up @@ -262,7 +263,6 @@ private fun AllEnrolledCoursesView(
Box(
modifier = Modifier
.fillMaxWidth()
.navigationBarsPadding()
.pullRefresh(pullRefreshState),
) {
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
Expand Down Expand Up @@ -140,6 +141,7 @@ fun WhatsNewScreen(
.semantics {
testTagsAsResourceId = true
}
.navigationBarsPadding()
.fillMaxSize(),
scaffoldState = scaffoldState,
topBar = {
Expand Down Expand Up @@ -247,26 +249,26 @@ private fun WhatsNewScreenPortrait(
.background(MaterialTheme.appColors.background),
contentAlignment = Alignment.TopCenter
) {
HorizontalPager(
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.Top,
state = pagerState
) { page ->
val image = whatsNewItem.messages[page].image
Image(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 36.dp, vertical = 48.dp),
painter = painterResource(id = image),
contentDescription = null
)
}
Box(
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 24.dp, vertical = 120.dp),
contentAlignment = Alignment.BottomCenter
.padding(horizontal = 24.dp, vertical = 36.dp),
verticalArrangement = Arrangement.spacedBy(24.dp),
) {
HorizontalPager(
modifier = Modifier
.fillMaxWidth()
.weight(1.0f),
verticalAlignment = Alignment.Top,
state = pagerState
) { page ->
val image = whatsNewItem.messages[page].image
Image(
modifier = Modifier
.fillMaxWidth(),
painter = painterResource(id = image),
contentDescription = null
)
}
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(20.dp),
Expand Down

0 comments on commit 0ff62f0

Please sign in to comment.