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: Minor UI & Feature Set Changes #7

Merged
merged 11 commits into from
Jul 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ class HeadersInterceptor(
}.build()
)
}
}
}
10 changes: 9 additions & 1 deletion app/src/main/java/org/openedx/app/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import org.openedx.whatsnew.WhatsNewManager
import org.openedx.whatsnew.WhatsNewRouter
import org.openedx.whatsnew.data.storage.WhatsNewPreferences
import org.openedx.whatsnew.presentation.WhatsNewAnalytics
import org.openedx.core.R as CoreR

val appModule = module {

Expand Down Expand Up @@ -167,7 +168,14 @@ val appModule = module {
DownloadWorkerController(get(), get(), get())
}

single { AppData(versionName = BuildConfig.VERSION_NAME) }
single {
val resourceManager = get<ResourceManager>()
AppData(
appName = resourceManager.getString(CoreR.string.app_name),
versionName = BuildConfig.VERSION_NAME,
applicationId = BuildConfig.APPLICATION_ID,
)
}
factory { (activity: AppCompatActivity) -> AppReviewManager(activity, get(), get()) }

single { TranscriptManager(get()) }
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ val screenModule = module {
get(),
)
}
viewModel { HtmlUnitViewModel(get(), get(), get(), get()) }
viewModel { HtmlUnitViewModel(get(), get(), get(), get(), get()) }

viewModel { ProgramViewModel(get(), get(), get(), get(), get(), get(), get()) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class RefreshFirebaseTokenWorker(context: Context, params: WorkerParameters) :
private const val WORKER_TAG = "RefreshFirebaseTokenWorker"

fun schedule(context: Context) {
val work = OneTimeWorkRequest
.Builder(RefreshFirebaseTokenWorker::class.java)
.addTag(WORKER_TAG)
.build()
WorkManager.getInstance(context).beginUniqueWork(
WORKER_TAG,
ExistingWorkPolicy.REPLACE,
work
).enqueue()
// val work = OneTimeWorkRequest
// .Builder(RefreshFirebaseTokenWorker::class.java)
// .addTag(WORKER_TAG)
// .build()
// WorkManager.getInstance(context).beginUniqueWork(
// WORKER_TAG,
// ExistingWorkPolicy.REPLACE,
// work
// ).enqueue()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class SyncFirebaseTokenWorker(context: Context, params: WorkerParameters) :
private const val WORKER_TAG = "SyncFirebaseTokenWorker"

fun schedule(context: Context) {
val work = OneTimeWorkRequest
.Builder(SyncFirebaseTokenWorker::class.java)
.addTag(WORKER_TAG)
.build()
WorkManager.getInstance(context).beginUniqueWork(
WORKER_TAG,
ExistingWorkPolicy.REPLACE,
work
).enqueue()
// val work = OneTimeWorkRequest
// .Builder(SyncFirebaseTokenWorker::class.java)
// .addTag(WORKER_TAG)
// .build()
// WorkManager.getInstance(context).beginUniqueWork(
// WORKER_TAG,
// ExistingWorkPolicy.REPLACE,
// work
// ).enqueue()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ data class RegistrationFields(
val exposed: Boolean?,
@SerializedName("required")
val required: Boolean?,
@SerializedName("defaultValue")
val defaultValue: Boolean?,
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
@SerializedName("restrictions")
val restrictions: Restrictions?,
@SerializedName("options")
Expand All @@ -38,6 +40,7 @@ data class RegistrationFields(
instructions = instructions ?: "",
exposed = exposed ?: false,
required = required ?: false,
defaultValue = defaultValue ?: true,
restrictions = restrictions?.mapToDomain() ?: RegistrationField.Restrictions(),
options = options?.map { it.mapToDomain() } ?: emptyList()
)
Expand Down Expand Up @@ -75,4 +78,4 @@ data class RegistrationFields(
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ private val field = RegistrationField(
instructions = "Enter your fullname",
exposed = false,
required = true,
defaultValue = true,
restrictions = RegistrationField.Restrictions(),
options = listOf(option, option),
errorInstructions = ""
Expand Down
9 changes: 7 additions & 2 deletions auth/src/main/java/org/openedx/auth/presentation/ui/AuthUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ fun RequiredFields(
}

RegistrationFieldType.CHECKBOX -> {
CheckboxField(text = field.label, defaultValue = field.defaultValue) {
CheckboxField(
field = field
) {
onFieldUpdated(field.name, it.toString())
}
}
Expand Down Expand Up @@ -188,7 +190,9 @@ fun OptionalFields(
}

RegistrationFieldType.CHECKBOX -> {
CheckboxField(text = field.label, defaultValue = field.defaultValue) {
CheckboxField(
field = field
) {
onFieldUpdated(field.name, it.toString())
}
}
Expand Down Expand Up @@ -668,6 +672,7 @@ private val field = RegistrationField(
instructions = "Enter your fullname",
exposed = false,
required = true,
defaultValue = true,
restrictions = RegistrationField.Restrictions(),
options = listOf(option, option),
errorInstructions = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import org.openedx.core.domain.model.RegistrationField
import org.openedx.core.domain.model.RegistrationFieldType
import org.openedx.core.ui.noRippleClickable
import org.openedx.core.ui.theme.OpenEdXTheme
import org.openedx.core.ui.theme.appColors
import org.openedx.core.ui.theme.appTypography

@Composable
internal fun CheckboxField(
text: String,
defaultValue: Boolean,
field: RegistrationField,
onValueChanged: (Boolean) -> Unit
) {
var checkedState by remember { mutableStateOf(defaultValue) }
// Initialize checkedState with user-inputted placeholder value,
// fallback to defaultValue if not provided
var checkedState by remember {
mutableStateOf(
field.placeholder.takeIf { it.isNotEmpty() }?.toBoolean() ?: field.defaultValue
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
)
}

Row(verticalAlignment = Alignment.CenterVertically) {
Checkbox(
checked = checkedState,
Expand All @@ -43,7 +51,7 @@ internal fun CheckboxField(
checkedState = !checkedState
onValueChanged(checkedState)
},
text = text,
text = field.label,
style = MaterialTheme.appTypography.bodySmall,
)
}
Expand All @@ -55,8 +63,19 @@ internal fun CheckboxField(
private fun CheckboxFieldPreview() {
OpenEdXTheme {
CheckboxField(
text = "Test",
defaultValue = true,
field = RegistrationField(
"",
"Checkbox label",
RegistrationFieldType.CHECKBOX,
"",
instructions = "",
exposed = true,
required = false,
defaultValue = true,
restrictions = RegistrationField.Restrictions(),
options = listOf(),
errorInstructions = ""
)
) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,28 @@ class SignUpViewModelTest {
private val listOfFields = listOf(
RegistrationField(
ApiConstants.EMAIL,
"",
RegistrationFieldType.TEXT,
"",
"",
true,
true,
RegistrationField.Restrictions(),
emptyList()
label = "",
type = RegistrationFieldType.TEXT,
placeholder = "",
instructions = "",
exposed = true,
required = true,
defaultValue = false,
restrictions = RegistrationField.Restrictions(),
options = emptyList()
),

RegistrationField(
ApiConstants.PASSWORD,
"",
RegistrationFieldType.TEXT,
"",
"",
true,
false,
RegistrationField.Restrictions(),
emptyList()
label = "",
type = RegistrationFieldType.TEXT,
placeholder = "",
instructions = "",
exposed = true,
required = true,
defaultValue = false,
restrictions = RegistrationField.Restrictions(),
options = emptyList()
)
)

Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/org/openedx/core/domain/model/Progress.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ data class Progress(
) : Parcelable {

@IgnoredOnParcel
val value: Float = try {
assignmentsCompleted.toFloat() / totalAssignmentsCount.toFloat()
} catch (_: ArithmeticException) {
0f
}
val value: Float
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
get() = if (totalAssignmentsCount != 0) {
assignmentsCompleted.toFloat() / totalAssignmentsCount.toFloat()
} else {
0f
}

companion object {
val DEFAULT_PROGRESS = Progress(0, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class RegistrationField(
val restrictions: Restrictions,
val options: List<Option>,
val errorInstructions: String = "",
val defaultValue: Boolean = false,
val defaultValue: Boolean,
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
) {

data class Restrictions(
Expand All @@ -39,6 +39,7 @@ fun String.createHonorCodeField() = RegistrationField(
instructions = "",
exposed = false,
required = false,
defaultValue = true,
restrictions = RegistrationField.Restrictions(),
options = emptyList(),
errorInstructions = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.openedx.core.presentation.global

data class AppData(
val appName: String,
val applicationId: String,
val versionName: String,
)
) {
val appUserAgent get() = "$appName/$applicationId/$versionName"
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/openedx/core/ui/IAPUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private fun PreviewCourseAlreadyPurchasedExecuteErrorDialog() {
CourseAlreadyPurchasedExecuteErrorDialog(
description = stringResource(id = R.string.iap_course_not_fullfilled),
positiveText = stringResource(id = R.string.iap_label_refresh_now),
negativeText = stringResource(id = R.string.core_contact_support),
negativeText = stringResource(id = R.string.iap_get_help),
neutralText = stringResource(id = R.string.core_cancel),
onPositiveClick = {}, onNegativeClick = {}, onNeutralClick = {})
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/org/openedx/core/ui/WebContentScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.CircularProgressIndicator
Expand Down Expand Up @@ -142,6 +146,9 @@ private fun WebViewContent(
val context = LocalContext.current
val isDarkTheme = isSystemInDarkTheme()
AndroidView(
modifier = Modifier
.consumeWindowInsets(WindowInsets.navigationBars)
.imePadding(),
factory = {
WebView(context).apply {
webViewClient = object : WebViewClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ class CourseContainerFragment : Fragment(R.layout.fragment_course_container) {
requireActivity().supportFragmentManager,
viewModel.courseName
)
} else if (viewModel.calendarSyncUIState.value.isCalendarSyncEnabled) {
setUpCourseCalendar()
} else {
if (viewModel.calendarSyncUIState.value.isCalendarSyncEnabled) {
setUpCourseCalendar()
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
pushNotificationPermissionLauncher.launch(
android.Manifest.permission.POST_NOTIFICATIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -130,6 +129,7 @@ class HtmlUnitFragment : Fragment() {
url = blockUrl,
cookieManager = viewModel.cookieManager,
apiHostURL = viewModel.apiHostURL,
userAgent = viewModel.appUserAgent,
isLoading = uiState is HtmlUnitUIState.Loading,
injectJSList = injectJSList,
onCompletionSet = {
Expand Down Expand Up @@ -200,6 +200,7 @@ private fun HTMLContentView(
url: String,
cookieManager: AppCookieManager,
apiHostURL: String,
userAgent: String,
isLoading: Boolean,
injectJSList: List<String>,
onCompletionSet: () -> Unit,
Expand Down Expand Up @@ -307,7 +308,7 @@ private fun HTMLContentView(
setSupportZoom(true)
loadsImagesAutomatically = true
domStorageEnabled = true

userAgentString = "$userAgentString $userAgent"
}
isVerticalScrollBarEnabled = false
isHorizontalScrollBarEnabled = false
Expand Down
Loading
Loading