add error handling to the image gallery
This commit is contained in:
parent
9ec9797d17
commit
7e0d4d6013
|
@ -14,7 +14,9 @@ import androidx.compose.ui.unit.dp
|
|||
import androidx.compose.ui.unit.sp
|
||||
|
||||
@Composable
|
||||
fun GenericError(message: String = "Something went wrong...", label: String = "Retry", moreDetails: String? = null, action: () -> Unit) {
|
||||
fun GenericError(message: String = "Something went wrong...", label: String = "Retry", cause: Throwable? = null, action: () -> Unit) {
|
||||
val moreDetails = cause?.let { "${it::class.java.simpleName}: ${it.message}" }
|
||||
|
||||
val openDetailsDialog = remember { mutableStateOf(false) }
|
||||
if (openDetailsDialog.value) {
|
||||
AlertDialog(
|
||||
|
|
|
@ -42,12 +42,10 @@ fun ImageGalleryScreen(viewModel: ImageGalleryViewModel, onTopLevelBack: () -> U
|
|||
|
||||
Spider(currentPage = viewModel.state.page, onNavigate = onNavigate) {
|
||||
item(ImageGalleryPage.Routes.folders) {
|
||||
ImageGalleryFolders(it) { folder ->
|
||||
viewModel.selectFolder(folder)
|
||||
}
|
||||
ImageGalleryFolders(it, onClick = { viewModel.selectFolder(it) }, onRetry = { viewModel.start() })
|
||||
}
|
||||
item(ImageGalleryPage.Routes.files) {
|
||||
ImageGalleryMedia(it, onImageSelected)
|
||||
ImageGalleryMedia(it, onImageSelected, onRetry = { viewModel.selectFolder(it.folder) })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +53,7 @@ fun ImageGalleryScreen(viewModel: ImageGalleryViewModel, onTopLevelBack: () -> U
|
|||
|
||||
|
||||
@Composable
|
||||
fun ImageGalleryFolders(state: ImageGalleryPage.Folders, onClick: (Folder) -> Unit) {
|
||||
fun ImageGalleryFolders(state: ImageGalleryPage.Folders, onClick: (Folder) -> Unit, onRetry: () -> Unit) {
|
||||
val screenWidth = LocalConfiguration.current.screenWidthDp
|
||||
|
||||
val gradient = Brush.verticalGradient(
|
||||
|
@ -106,12 +104,12 @@ fun ImageGalleryFolders(state: ImageGalleryPage.Folders, onClick: (Folder) -> Un
|
|||
}
|
||||
}
|
||||
|
||||
is Lce.Error -> GenericError { }
|
||||
is Lce.Error -> GenericError(cause = content.cause, action = onRetry)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ImageGalleryMedia(state: ImageGalleryPage.Files, onFileSelected: (Media) -> Unit) {
|
||||
fun ImageGalleryMedia(state: ImageGalleryPage.Files, onFileSelected: (Media) -> Unit, onRetry: () -> Unit) {
|
||||
val screenWidth = LocalConfiguration.current.screenWidthDp
|
||||
|
||||
Column {
|
||||
|
@ -149,7 +147,7 @@ fun ImageGalleryMedia(state: ImageGalleryPage.Files, onFileSelected: (Media) ->
|
|||
}
|
||||
}
|
||||
|
||||
is Lce.Error -> GenericError { }
|
||||
is Lce.Error -> GenericError(cause = content.cause, action = onRetry)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class ImageGalleryViewModel(
|
|||
route = ImageGalleryPage.Routes.files,
|
||||
label = page.label,
|
||||
parent = ImageGalleryPage.Routes.folders,
|
||||
state = ImageGalleryPage.Files(Lce.Loading())
|
||||
state = ImageGalleryPage.Files(Lce.Loading(), folder)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ data class ImageGalleryState(
|
|||
|
||||
sealed interface ImageGalleryPage {
|
||||
data class Folders(val content: Lce<List<Folder>>) : ImageGalleryPage
|
||||
data class Files(val content: Lce<List<Media>>) : ImageGalleryPage
|
||||
data class Files(val content: Lce<List<Media>>, val folder: Folder) : ImageGalleryPage
|
||||
|
||||
object Routes {
|
||||
val folders = Route<Folders>("Folders")
|
||||
|
|
|
@ -31,7 +31,6 @@ import androidx.compose.ui.text.input.ImeAction
|
|||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
@ -160,9 +159,7 @@ internal fun SettingsScreen(viewModel: SettingsViewModel, onSignOut: () -> Unit,
|
|||
GenericError(
|
||||
message = message,
|
||||
label = "Close",
|
||||
moreDetails = result.cause.takeAs<ImportResult.Error.Type.Unknown>()?.let {
|
||||
"${it.cause::class.java.simpleName}: ${it.cause.message}"
|
||||
}
|
||||
cause = result.cause.takeAs<ImportResult.Error.Type.Unknown>()?.cause
|
||||
) {
|
||||
navigator.navigate.upToHome()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue