Skip to content
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

fix: update config parsing structure #319

Merged
merged 2 commits into from
May 31, 2024
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
45 changes: 18 additions & 27 deletions core/src/main/java/org/openedx/core/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,45 @@ import java.io.InputStreamReader

class Config(context: Context) {

private var configProperties: JsonObject

init {
configProperties = try {
val inputStream = context.assets.open("config/config.json")
val parser = JsonParser()
val config = parser.parse(InputStreamReader(inputStream))
config.asJsonObject
} catch (e: Exception) {
JsonObject()
}
private var configProperties: JsonObject = try {
val inputStream = context.assets.open("config/config.json")
val parser = JsonParser()
val config = parser.parse(InputStreamReader(inputStream))
config.asJsonObject
} catch (e: Exception) {
JsonObject()
}

fun getAppId(): String {
return getString(APPLICATION_ID, "")
}

fun getApiHostURL(): String {
return getString(API_HOST_URL, "")
return getString(API_HOST_URL)
}

fun getUriScheme(): String {
return getString(URI_SCHEME, "")
return getString(URI_SCHEME)
}

fun getOAuthClientId(): String {
return getString(OAUTH_CLIENT_ID, "")
return getString(OAUTH_CLIENT_ID)
}

fun getAccessTokenType(): String {
return getString(TOKEN_TYPE, "")
return getString(TOKEN_TYPE)
}

fun getFaqUrl(): String {
return getString(FAQ_URL, "")
return getString(FAQ_URL)
}

fun getFeedbackEmailAddress(): String {
return getString(FEEDBACK_EMAIL_ADDRESS, "")
return getString(FEEDBACK_EMAIL_ADDRESS)
}

fun getPlatformName(): String {
return getString(PLATFORM_NAME, "")
return getString(PLATFORM_NAME)
}

fun getAgreement(locale: String): AgreementUrls {
Expand Down Expand Up @@ -111,15 +107,11 @@ class Config(context: Context) {
return getBoolean(PRE_LOGIN_EXPERIENCE_ENABLED, true)
}

fun isCourseNestedListEnabled(): Boolean {
return getBoolean(COURSE_NESTED_LIST_ENABLED, false)
}

fun isCourseUnitProgressEnabled(): Boolean {
return getBoolean(COURSE_UNIT_PROGRESS_ENABLED, false)
fun getCourseUIConfig(): UIConfig {
return getObjectOrNewInstance(UI_COMPONENTS, UIConfig::class.java)
}

private fun getString(key: String, defaultValue: String): String {
private fun getString(key: String, defaultValue: String = ""): String {
val element = getObject(key)
return if (element != null) {
element.asString
Expand Down Expand Up @@ -175,8 +167,7 @@ class Config(context: Context) {
private const val PROGRAM = "PROGRAM"
private const val DASHBOARD = "DASHBOARD"
private const val BRANCH = "BRANCH"
private const val COURSE_NESTED_LIST_ENABLED = "COURSE_NESTED_LIST_ENABLED"
private const val COURSE_UNIT_PROGRESS_ENABLED = "COURSE_UNIT_PROGRESS_ENABLED"
private const val UI_COMPONENTS = "UI_COMPONENTS"
private const val PLATFORM_NAME = "PLATFORM_NAME"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ data class ProgramConfig(
data class ProgramWebViewConfig(
@SerializedName("BASE_URL")
val programUrl: String = "",
@SerializedName("PROGRAM_DETAIL_URL_TEMPLATE")
@SerializedName("PROGRAM_DETAIL_TEMPLATE")
val programDetailUrlTemplate: String = "",
)
10 changes: 10 additions & 0 deletions core/src/main/java/org/openedx/core/config/UIConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.openedx.core.config

import com.google.gson.annotations.SerializedName

data class UIConfig(
@SerializedName("COURSE_NESTED_LIST_ENABLED")
val isCourseNestedListEnabled: Boolean = false,
@SerializedName("COURSE_UNIT_PROGRESS_ENABLED")
val isCourseUnitProgressEnabled: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CourseDatesViewModel(
private var courseBannerType: CourseBannerType = CourseBannerType.BLANK
private var courseStructure: CourseStructure? = null

val isCourseExpandableSectionsEnabled get() = config.isCourseNestedListEnabled()
val isCourseExpandableSectionsEnabled get() = config.getCourseUIConfig().isCourseNestedListEnabled

init {
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CourseOutlineViewModel(
workerController,
coreAnalytics
) {
val isCourseNestedListEnabled get() = config.isCourseNestedListEnabled()
val isCourseNestedListEnabled get() = config.getCourseUIConfig().isCourseNestedListEnabled

private val _uiState = MutableStateFlow<CourseOutlineUIState>(CourseOutlineUIState.Loading)
val uiState: StateFlow<CourseOutlineUIState>
Expand All @@ -81,7 +81,7 @@ class CourseOutlineViewModel(
private var resumeSectionBlock: Block? = null
private var resumeVerticalBlock: Block? = null

private val isCourseExpandableSectionsEnabled get() = config.isCourseNestedListEnabled()
private val isCourseExpandableSectionsEnabled get() = config.getCourseUIConfig().isCourseNestedListEnabled

private val courseSubSections = mutableMapOf<String, MutableList<Block>>()
private val subSectionsDownloadsCount = mutableMapOf<String, Int>()
Expand Down
26 changes: 13 additions & 13 deletions course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fun CourseSectionCard(
block: Block,
downloadedState: DownloadedState?,
onItemClick: (Block) -> Unit,
onDownloadClick: (Block) -> Unit
onDownloadClick: (Block) -> Unit,
) {
val iconModifier = Modifier.size(24.dp)

Expand Down Expand Up @@ -204,7 +204,7 @@ fun OfflineQueueCard(
downloadModel: DownloadModel,
progressValue: Long,
progressSize: Long,
onDownloadClick: (DownloadModel) -> Unit
onDownloadClick: (DownloadModel) -> Unit,
) {
val iconModifier = Modifier.size(24.dp)

Expand Down Expand Up @@ -272,7 +272,7 @@ fun OfflineQueueCard(

@Composable
fun CardArrow(
degrees: Float
degrees: Float,
) {
Icon(
imageVector = Icons.Filled.ChevronRight,
Expand Down Expand Up @@ -304,7 +304,7 @@ fun NavigationUnitsButtons(
hasNextBlock: Boolean,
isVerticalNavigation: Boolean,
onPrevClick: () -> Unit,
onNextClick: () -> Unit
onNextClick: () -> Unit,
) {
val nextButtonIcon = if (hasNextBlock) {
painterResource(id = coreR.drawable.core_ic_down)
Expand Down Expand Up @@ -403,7 +403,7 @@ fun HorizontalPageIndicator(
completedAndSelectedColor: Color = Color.Green,
completedColor: Color = Color.Green,
selectedColor: Color = Color.White,
defaultColor: Color = Color.Gray
defaultColor: Color = Color.Gray,
) {
Row(
horizontalArrangement = Arrangement.spacedBy(1.dp),
Expand Down Expand Up @@ -468,7 +468,7 @@ fun Indicator(
defaultColor: Color,
defaultRadius: Dp,
selectedSize: Dp,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
) {
val size by animateDpAsState(
targetValue = if (isSelected) selectedSize else defaultRadius,
Expand Down Expand Up @@ -497,7 +497,7 @@ fun VideoSubtitles(
showSubtitleLanguage: Boolean,
currentIndex: Int,
onTranscriptClick: (Caption) -> Unit,
onSettingsClick: () -> Unit
onSettingsClick: () -> Unit,
) {
timedTextObject?.let {
val autoScrollDelay = 3000L
Expand Down Expand Up @@ -577,7 +577,7 @@ fun CourseExpandableChapterCard(
modifier: Modifier,
block: Block,
onItemClick: (Block) -> Unit,
arrowDegrees: Float = 0f
arrowDegrees: Float = 0f,
) {
Column(modifier = Modifier
.clickable { onItemClick(block) }
Expand Down Expand Up @@ -627,7 +627,7 @@ fun CourseSubSectionItem(
downloadedState: DownloadedState?,
downloadsCount: Int,
onClick: (Block) -> Unit,
onDownloadClick: (Block) -> Unit
onDownloadClick: (Block) -> Unit,
) {
val icon =
if (block.isCompleted()) painterResource(R.drawable.course_ic_task_alt) else painterResource(
Expand Down Expand Up @@ -729,7 +729,7 @@ fun CourseSubSectionItem(
@Composable
fun CourseUnitToolbar(
title: String,
onBackClick: () -> Unit
onBackClick: () -> Unit,
) {
OpenEdXTheme {
Box(
Expand Down Expand Up @@ -759,7 +759,7 @@ fun SubSectionUnitsTitle(
unitName: String,
unitsCount: Int,
unitsListShowed: Boolean,
onUnitsClick: () -> Unit
onUnitsClick: () -> Unit,
) {
val textStyle = MaterialTheme.appTypography.titleMedium
val hasUnits = unitsCount > 0
Expand Down Expand Up @@ -805,7 +805,7 @@ fun SubSectionUnitsTitle(
fun SubSectionUnitsList(
unitBlocks: List<Block>,
selectedUnitIndex: Int = 0,
onUnitClick: (index: Int, unit: Block) -> Unit
onUnitClick: (index: Int, unit: Block) -> Unit,
) {
Card(
modifier = Modifier
Expand Down Expand Up @@ -1050,7 +1050,7 @@ fun CourseMessage(
icon: Painter,
message: String,
action: String? = null,
onActionClick: () -> Unit = {}
onActionClick: () -> Unit = {},
) {
Column {
Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class CourseUnitContainerViewModel(

private val blocks = ArrayList<Block>()

val isCourseExpandableSectionsEnabled get() = config.isCourseNestedListEnabled()
val isCourseExpandableSectionsEnabled get() = config.getCourseUIConfig().isCourseNestedListEnabled

val isCourseUnitProgressEnabled get() = config.isCourseUnitProgressEnabled()
val isCourseUnitProgressEnabled get() = config.getCourseUIConfig().isCourseUnitProgressEnabled

private var currentIndex = 0
private var currentVerticalIndex = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HtmlUnitViewModel(
val injectJSList = _injectJSList.asStateFlow()

val isOnline get() = networkConnection.isOnline()
val isCourseUnitProgressEnabled get() = config.isCourseUnitProgressEnabled()
val isCourseUnitProgressEnabled get() = config.getCourseUIConfig().isCourseUnitProgressEnabled
val apiHostURL get() = config.getApiHostURL()
val cookieManager get() = edxCookieManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CourseVideoViewModel(
coreAnalytics
) {

val isCourseNestedListEnabled get() = config.isCourseNestedListEnabled()
val isCourseNestedListEnabled get() = config.getCourseUIConfig().isCourseNestedListEnabled

private val _uiState = MutableStateFlow<CourseVideosUIState>(CourseVideosUIState.Loading)
val uiState: StateFlow<CourseVideosUIState>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class CourseOutlineViewModelTest {
)
}
coEvery { interactor.getCourseStatus(any()) } returns CourseComponentStatus("id")
every { config.isCourseNestedListEnabled() } returns false
every { config.getCourseUIConfig().isCourseNestedListEnabled } returns false

val viewModel = CourseOutlineViewModel(
"",
Expand Down Expand Up @@ -351,7 +351,7 @@ class CourseOutlineViewModelTest {
)
}
coEvery { interactor.getCourseStatus(any()) } returns CourseComponentStatus("id")
every { config.isCourseNestedListEnabled() } returns false
every { config.getCourseUIConfig().isCourseNestedListEnabled } returns false

val viewModel = CourseOutlineViewModel(
"",
Expand Down Expand Up @@ -398,7 +398,7 @@ class CourseOutlineViewModelTest {
)
}
coEvery { interactor.getCourseStatus(any()) } returns CourseComponentStatus("id")
every { config.isCourseNestedListEnabled() } returns false
every { config.getCourseUIConfig().isCourseNestedListEnabled } returns false

val viewModel = CourseOutlineViewModel(
"",
Expand Down Expand Up @@ -482,7 +482,7 @@ class CourseOutlineViewModelTest {
coEvery { workerController.saveModels(any()) } returns Unit
coEvery { interactor.getCourseStatus(any()) } returns CourseComponentStatus("id")
coEvery { downloadDao.readAllData() } returns flow { emit(emptyList()) }
every { config.isCourseNestedListEnabled() } returns false
every { config.getCourseUIConfig().isCourseNestedListEnabled } returns false

val viewModel = CourseOutlineViewModel(
"",
Expand Down Expand Up @@ -525,7 +525,7 @@ class CourseOutlineViewModelTest {
every { networkConnection.isOnline() } returns true
coEvery { workerController.saveModels(any()) } returns Unit
coEvery { downloadDao.readAllData() } returns flow { emit(emptyList()) }
every { config.isCourseNestedListEnabled() } returns false
every { config.getCourseUIConfig().isCourseNestedListEnabled } returns false
every { coreAnalytics.logEvent(any(), any()) } returns Unit

val viewModel = CourseOutlineViewModel(
Expand Down Expand Up @@ -562,7 +562,7 @@ class CourseOutlineViewModelTest {
every { networkConnection.isOnline() } returns false
coEvery { workerController.saveModels(any()) } returns Unit
coEvery { downloadDao.readAllData() } returns flow { emit(emptyList()) }
every { config.isCourseNestedListEnabled() } returns false
every { config.getCourseUIConfig().isCourseNestedListEnabled } returns false

val viewModel = CourseOutlineViewModel(
"",
Expand Down
Loading
Loading