-
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: App Level Webview/No Internet Error Handling #357
feat: App Level Webview/No Internet Error Handling #357
Conversation
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.
Some minor code changes and improvements.
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.
Please update the file name
core_ic_unknown_error.xml
) { | ||
ErrorScreen( | ||
modifier = modifier, | ||
title = stringResource(id = R.string.core_no_internet_connection), |
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.
we can create an EnumClass for these types.
enum class ErrorType(
val iconResId: Int = 0,
val titleResId: Int = 0,
val descriptionResId: Int = 0,
val actionResId: Int = 0,
) {
CONNECTION_ERROR(
iconResId = R.drawable.core_no_internet_connection,
titleResId = R.string.core_no_internet_connection,
descriptionResId = R.string.core_no_internet_connection_description,
actionResId = R.string.core_reload,
),
UNKNOWN_ERROR(
iconResId = R.drawable.core_unkown,
titleResId = R.string.core_try_again,
descriptionResId = R.string.core_something_went_wrong_description,
actionResId = R.string.core_reload,
),
}
@@ -88,6 +90,10 @@ class HtmlUnitFragment : Fragment() { | |||
mutableStateOf(true) | |||
} | |||
|
|||
var isError by remember { |
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.
we can move this in ViewModel
hasInternetConnection = viewModel.isOnline | ||
} | ||
if (!hasInternetConnection) { | ||
ConnectionErrorView( | ||
modifier = Modifier |
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.
we can move the modifier inside CommonCompose.
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.
ErrorHandling not working on MyPrograms.
- Not Internet Error Handling with reload CTA - Unknown error while load webpage with reload CTA. fixes: LEARNER-10046
59de37f
to
5d31c60
Compare
5d31c60
to
ca66582
Compare
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.
Some minor code improvements.
|
||
@Composable | ||
fun ErrorScreen( | ||
title: String, |
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.
we can simply pass errorType here and set the properties accordingly.
fun ErrorScreen(
errorType: ErrorType,
onReloadClick: () -> Unit
)
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.
as we introduce this function as common compose, IMO it's better not to couple it with some constant.
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.
IMO, WebViewUIState
is more appropriate.
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.
as it relates to whether the web view loaded the URL or not, IMO WebViewState
is more appropriate.
|
||
import org.openedx.core.presentation.global.ErrorType | ||
|
||
sealed class HtmlUnitUIState { |
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 use WebViewUIState
here as well ?
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.
this is coupled with the UI screen, better to place separately.
@@ -20,6 +21,9 @@ class HtmlUnitViewModel( | |||
private val notifier: CourseNotifier | |||
) : BaseViewModel() { | |||
|
|||
private val _uiState = MutableStateFlow<HtmlUnitUIState>(HtmlUnitUIState.Loading) |
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 use WebViewUIState
here?
} | ||
if (uiState is HtmlUnitUIState.Error) { | ||
val errorType = (uiState as HtmlUnitUIState.Error).errorType | ||
ErrorScreen( |
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.
Please use ErrorType
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.
same here.
import org.openedx.discovery.domain.model.Course | ||
|
||
sealed class DiscoveryUIState { | ||
data class Courses(val courses: List<Course>) : DiscoveryUIState() | ||
data object Loading : DiscoveryUIState() | ||
data object Loaded : DiscoveryUIState() |
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.
instead of adding new objects in DiscoveryUIState, we can use WebviewUIState
) : CourseInfoUIState() | ||
} | ||
|
||
enum class CourseInfoUIAction { |
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.
We can define a generalised WebView State. here and other occurrences
enum class WebPageState{
WEB_PAGE_LOADED,
WEB_PAGE_ERROR,
RELOAD_WEB_PAGE
}
onDiscoveryUIAction(DiscoveryUIAction.WEB_PAGE_ERROR) | ||
} | ||
if (uiState is DiscoveryUIState.Error) { | ||
ErrorScreen( |
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.
we can simply call ConnectionErrorView()
} | ||
|
||
if (uiState is ProgramUIState.Error) { | ||
ErrorScreen( |
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.
we can simply pass errorType.
onCourseInfoUIAction(CourseInfoUIAction.WEB_PAGE_ERROR) | ||
} | ||
if (webViewState is WebViewState.Error) { | ||
ErrorScreen( |
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.
same here
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.
Connectivity error not handled on view all courses,
else only 2 minor nits,
@@ -1,5 +1,6 @@ | |||
package org.openedx.discovery.presentation | |||
|
|||
import org.openedx.core.presentation.global.ErrorType |
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.
please remove unused import.
@@ -417,6 +417,8 @@ internal fun DiscoveryScreen( | |||
} | |||
} | |||
} | |||
|
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.
unused code, can be removed
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.
LGTM
We're closing this PR and moving these changes to our own fork, as they are critical for us. After our release, we hope to find a way to contribute to these changes back, thanks! |
Description
fixes: LEARNER-10046