fix: Prevent a ClassCastException when handling timeline errors (#273)
This commit is contained in:
parent
a6a68f1384
commit
806991f8a8
|
@ -414,10 +414,11 @@ class TimelineFragment :
|
||||||
.collect { (loadState, presentationState) ->
|
.collect { (loadState, presentationState) ->
|
||||||
when (presentationState) {
|
when (presentationState) {
|
||||||
PresentationState.ERROR -> {
|
PresentationState.ERROR -> {
|
||||||
val message =
|
val error = (loadState.mediator?.refresh as? LoadState.Error)?.error
|
||||||
(loadState.refresh as LoadState.Error).error.getErrorString(
|
?: (loadState.source.refresh as? LoadState.Error)?.error
|
||||||
requireContext(),
|
?: IllegalStateException("unknown error")
|
||||||
)
|
|
||||||
|
val message = error.getErrorString(requireContext())
|
||||||
|
|
||||||
// Show errors as a snackbar if there is existing content to show
|
// Show errors as a snackbar if there is existing content to show
|
||||||
// (either cached, or in the adapter), or as a full screen error
|
// (either cached, or in the adapter), or as a full screen error
|
||||||
|
@ -433,8 +434,7 @@ class TimelineFragment :
|
||||||
.setAction(R.string.action_retry) { adapter.retry() }
|
.setAction(R.string.action_retry) { adapter.retry() }
|
||||||
snackbar!!.show()
|
snackbar!!.show()
|
||||||
} else {
|
} else {
|
||||||
val drawableRes =
|
val drawableRes = error.getDrawableRes()
|
||||||
(loadState.refresh as LoadState.Error).error.getDrawableRes()
|
|
||||||
binding.statusView.setup(drawableRes, message) {
|
binding.statusView.setup(drawableRes, message) {
|
||||||
snackbar?.dismiss()
|
snackbar?.dismiss()
|
||||||
adapter.retry()
|
adapter.retry()
|
||||||
|
|
Loading…
Reference in New Issue