Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private fun InvitePeopleViewError(
contentAlignment = Alignment.Center,
) {
AsyncFailure(
throwable = error,
message = error.localizedMessage,
onRetry = null,
modifier = Modifier.padding(horizontal = 16.dp),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fun LeaveSpaceView(
}
is AsyncData.Failure -> item {
AsyncFailure(
throwable = state.selectableSpaceRooms.error,
message = state.selectableSpaceRooms.error.localizedMessage,
onRetry = {
state.eventSink(LeaveSpaceEvents.Retry)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fun ViewFileView(
lines = state.lines.data.toImmutableList(),
colorationMode = state.colorationMode,
)
is AsyncData.Failure -> AsyncFailure(throwable = state.lines.error, onRetry = null)
is AsyncData.Failure -> AsyncFailure(message = state.lines.error.localizedMessage, onRetry = null)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import io.element.android.libraries.ui.strings.CommonStrings

@Composable
fun AsyncFailure(
throwable: Throwable,
message: String?,
onRetry: (() -> Unit)?,
modifier: Modifier = Modifier,
) {
Expand All @@ -35,7 +35,7 @@ fun AsyncFailure(
.padding(vertical = 32.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(text = throwable.message ?: stringResource(id = CommonStrings.error_unknown))
Text(text = message ?: stringResource(id = CommonStrings.error_unknown))
if (onRetry != null) {
Spacer(modifier = Modifier.height(24.dp))
Button(
Expand All @@ -50,7 +50,7 @@ fun AsyncFailure(
@Composable
internal fun AsyncFailurePreview() = ElementPreview {
AsyncFailure(
throwable = IllegalStateException("An error occurred"),
message = "An error occurred",
onRetry = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import timber.log.Timber
import java.util.concurrent.atomic.AtomicBoolean

interface MediaGalleryDataSource {
Expand Down Expand Up @@ -76,6 +77,9 @@ class TimelineMediaGalleryDataSource(
emit(it)
},
{
// We couldn't load the timeline, so we reset the started state to allow retrying
Timber.e(it, "Failed to get timeline for media gallery")
isStarted.set(false)
groupedMediaItemsFlow.emit(AsyncData.Failure(it))
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ sealed interface MediaGalleryEvents {

data object CloseBottomSheet : MediaGalleryEvents
data class Delete(val eventId: EventId) : MediaGalleryEvents

data object ReloadTimeline : MediaGalleryEvents
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class MediaGalleryPresenter(
is MediaGalleryEvents.ChangeMode -> {
mode = event.mode
}
is MediaGalleryEvents.ReloadTimeline -> {
mediaGalleryDataSource.start()
}
is MediaGalleryEvents.LoadMore -> coroutineScope.launch {
mediaGalleryDataSource.loadMore(event.direction)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private fun MediaGalleryPage(
}
is AsyncData.Failure -> {
ErrorContent(
error = groupedMediaItems.error,
onRetry = { state.eventSink(MediaGalleryEvents.ReloadTimeline) },
)
}
else -> Unit
Expand Down Expand Up @@ -454,10 +454,10 @@ private fun LoadingMoreIndicator(
}

@Composable
private fun ErrorContent(error: Throwable) {
private fun ErrorContent(onRetry: () -> Unit) {
AsyncFailure(
throwable = error,
onRetry = null,
message = null,
onRetry = onRetry,
modifier = Modifier.fillMaxSize(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sealed interface MediaViewerEvents {
data class Share(val data: MediaViewerPageData.MediaViewerData) : MediaViewerEvents
data class OpenWith(val data: MediaViewerPageData.MediaViewerData) : MediaViewerEvents
data class ClearLoadingError(val data: MediaViewerPageData.MediaViewerData) : MediaViewerEvents
data object ReloadTimeline : MediaViewerEvents
data class ViewInTimeline(val eventId: EventId) : MediaViewerEvents
data class OpenInfo(val data: MediaViewerPageData.MediaViewerData) : MediaViewerEvents
data class ConfirmDelete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class MediaViewerPresenter(
is MediaViewerEvents.ClearLoadingError -> {
dataSource.clearLoadingError(event.data)
}
is MediaViewerEvents.ReloadTimeline -> {
dataSource.setup()
}
is MediaViewerEvents.SaveOnDisk -> {
mediaBottomSheetState = MediaBottomSheetState.Hidden
coroutineScope.saveOnDisk(event.data.downloadedMedia.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ fun MediaViewerView(
when (val dataForPage = state.listData[page]) {
is MediaViewerPageData.Failure -> {
MediaViewerErrorPage(
throwable = dataForPage.throwable,
onDismiss = onBackClick,
onRetry = { state.eventSink(MediaViewerEvents.ReloadTimeline) },
)
}
is MediaViewerPageData.Loading -> {
Expand Down Expand Up @@ -394,8 +394,8 @@ private fun MediaViewerLoadingPage(

@Composable
private fun MediaViewerErrorPage(
throwable: Throwable,
onDismiss: () -> Unit,
onRetry: () -> Unit,
modifier: Modifier = Modifier,
) {
MediaViewerFlickToDismiss(
Expand All @@ -409,8 +409,8 @@ private fun MediaViewerErrorPage(
contentAlignment = Alignment.Center
) {
AsyncFailure(
throwable = throwable,
onRetry = null
message = null,
onRetry = onRetry,
)
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading