-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: Course Level Error Handling for Empty States #363
Closed
farhan-arshad-dev
wants to merge
5
commits into
openedx:develop
from
farhan-arshad-dev:farhan_ar/LEARNER-10039
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d4b7ff5
feat: Course Level Error Handling for Empty States
farhan-arshad-dev a9d6bc3
fix: unit test cases
farhan-arshad-dev ae68061
fix: address PR comments by Moin-1
farhan-arshad-dev ea9baa7
fix: unit test cases
farhan-arshad-dev d8566c3
fix: address PR comments
farhan-arshad-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="86dp" | ||
android:height="86dp" | ||
android:viewportWidth="20" | ||
android:viewportHeight="20"> | ||
|
||
<path | ||
android:fillColor="#ffffff" | ||
android:pathData="M10,0C4.48,0 0,4.48 0,10C0,15.52 4.48,20 10,20C15.52,20 20,15.52 20,10C20,4.48 15.52,0 10,0ZM10,11C9.45,11 9,10.55 9,10V6C9,5.45 9.45,5 10,5C10.55,5 11,5.45 11,6V10C11,10.55 10.55,11 10,11ZM11,15H9V13H11V15Z" /> | ||
|
||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,6 @@ import androidx.compose.ui.platform.LocalContext | |
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.pluralStringResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Devices | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
@@ -76,6 +75,7 @@ import org.openedx.core.presentation.course.CourseViewMode | |
import org.openedx.core.presentation.dialog.alert.ActionDialogFragment | ||
import org.openedx.core.presentation.settings.calendarsync.CalendarSyncUIState | ||
import org.openedx.core.ui.HandleUIMessage | ||
import org.openedx.core.ui.NoContentScreen | ||
import org.openedx.core.ui.WindowSize | ||
import org.openedx.core.ui.WindowType | ||
import org.openedx.core.ui.displayCutoutForLandscape | ||
|
@@ -305,19 +305,11 @@ private fun CourseDatesUI( | |
} | ||
} | ||
|
||
DatesUIState.Empty -> { | ||
Box( | ||
modifier = Modifier.fillMaxSize(), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Text( | ||
modifier = Modifier.fillMaxWidth(), | ||
text = stringResource(id = R.string.course_dates_unavailable_message), | ||
color = MaterialTheme.appColors.textPrimary, | ||
style = MaterialTheme.appTypography.titleMedium, | ||
textAlign = TextAlign.Center | ||
) | ||
} | ||
DatesUIState.Error -> { | ||
NoContentScreen( | ||
message = stringResource(id = R.string.course_dates_unavailable_message), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we update the string to |
||
icon = painterResource(id = R.drawable.course_ic_no_content) | ||
) | ||
} | ||
|
||
DatesUIState.Loading -> {} | ||
|
@@ -643,6 +635,26 @@ private fun CourseDateItem( | |
} | ||
} | ||
|
||
|
||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) | ||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) | ||
@Composable | ||
private fun EmptyCourseDatesScreenPreview() { | ||
OpenEdXTheme { | ||
CourseDatesUI( | ||
windowSize = WindowSize(WindowType.Compact, WindowType.Compact), | ||
uiState = DatesUIState.Error, | ||
uiMessage = null, | ||
isSelfPaced = true, | ||
calendarSyncUIState = mockCalendarSyncUIState, | ||
onItemClick = {}, | ||
onPLSBannerViewed = {}, | ||
onSyncDates = {}, | ||
onCalendarSyncSwitch = {}, | ||
) | ||
} | ||
} | ||
|
||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) | ||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) | ||
@Composable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
course/src/main/java/org/openedx/course/presentation/handouts/HandoutsUIState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.openedx.course.presentation.handouts | ||
|
||
sealed class HandoutsUIState { | ||
data class HTMLContent(val htmlContent: String) : HandoutsUIState() | ||
omerhabib26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data object Error : HandoutsUIState() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package org.openedx.course.presentation.handouts | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import org.openedx.core.BaseViewModel | ||
import org.openedx.core.config.Config | ||
|
@@ -23,26 +24,40 @@ class HandoutsViewModel( | |
|
||
val apiHostUrl get() = config.getApiHostURL() | ||
|
||
private val _htmlContent = MutableLiveData<String>() | ||
val htmlContent: LiveData<String> | ||
get() = _htmlContent | ||
private val _uiState = MutableStateFlow<HandoutsUIState>(HandoutsUIState.HTMLContent("")) | ||
val uiState: StateFlow<HandoutsUIState> | ||
get() = _uiState.asStateFlow() | ||
|
||
init { | ||
getEnrolledCourse() | ||
} | ||
|
||
private fun getEnrolledCourse() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we update the method name to |
||
viewModelScope.launch { | ||
var emptyState = false | ||
try { | ||
if (HandoutsType.valueOf(handoutsType) == HandoutsType.Handouts) { | ||
val handouts = interactor.getHandouts(courseId) | ||
_htmlContent.value = handoutsToHtml(handouts) | ||
if (handouts.handoutsHtml.isNotBlank()) { | ||
_uiState.value = HandoutsUIState.HTMLContent(handoutsToHtml(handouts)) | ||
} else { | ||
emptyState = true | ||
} | ||
} else { | ||
val announcements = interactor.getAnnouncements(courseId) | ||
_htmlContent.value = announcementsToHtml(announcements) | ||
if (announcements.isNotEmpty()) { | ||
_uiState.value = | ||
HandoutsUIState.HTMLContent(announcementsToHtml(announcements)) | ||
} else { | ||
emptyState = true | ||
} | ||
} | ||
} catch (e: Exception) { | ||
//ignore e.printStackTrace() | ||
emptyState = true | ||
} | ||
if (emptyState) { | ||
_uiState.value = HandoutsUIState.Error | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create an enum class for these screens?