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
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
@Composable
|
@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) }
|
val openDetailsDialog = remember { mutableStateOf(false) }
|
||||||
if (openDetailsDialog.value) {
|
if (openDetailsDialog.value) {
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
|
|
|
@ -42,12 +42,10 @@ fun ImageGalleryScreen(viewModel: ImageGalleryViewModel, onTopLevelBack: () -> U
|
||||||
|
|
||||||
Spider(currentPage = viewModel.state.page, onNavigate = onNavigate) {
|
Spider(currentPage = viewModel.state.page, onNavigate = onNavigate) {
|
||||||
item(ImageGalleryPage.Routes.folders) {
|
item(ImageGalleryPage.Routes.folders) {
|
||||||
ImageGalleryFolders(it) { folder ->
|
ImageGalleryFolders(it, onClick = { viewModel.selectFolder(it) }, onRetry = { viewModel.start() })
|
||||||
viewModel.selectFolder(folder)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
item(ImageGalleryPage.Routes.files) {
|
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
|
@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 screenWidth = LocalConfiguration.current.screenWidthDp
|
||||||
|
|
||||||
val gradient = Brush.verticalGradient(
|
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
|
@Composable
|
||||||
fun ImageGalleryMedia(state: ImageGalleryPage.Files, onFileSelected: (Media) -> Unit) {
|
fun ImageGalleryMedia(state: ImageGalleryPage.Files, onFileSelected: (Media) -> Unit, onRetry: () -> Unit) {
|
||||||
val screenWidth = LocalConfiguration.current.screenWidthDp
|
val screenWidth = LocalConfiguration.current.screenWidthDp
|
||||||
|
|
||||||
Column {
|
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,
|
route = ImageGalleryPage.Routes.files,
|
||||||
label = page.label,
|
label = page.label,
|
||||||
parent = ImageGalleryPage.Routes.folders,
|
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 {
|
sealed interface ImageGalleryPage {
|
||||||
data class Folders(val content: Lce<List<Folder>>) : 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 {
|
object Routes {
|
||||||
val folders = Route<Folders>("Folders")
|
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.KeyboardType
|
||||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.text.input.VisualTransformation
|
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.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
@ -160,9 +159,7 @@ internal fun SettingsScreen(viewModel: SettingsViewModel, onSignOut: () -> Unit,
|
||||||
GenericError(
|
GenericError(
|
||||||
message = message,
|
message = message,
|
||||||
label = "Close",
|
label = "Close",
|
||||||
moreDetails = result.cause.takeAs<ImportResult.Error.Type.Unknown>()?.let {
|
cause = result.cause.takeAs<ImportResult.Error.Type.Unknown>()?.cause
|
||||||
"${it.cause::class.java.simpleName}: ${it.cause.message}"
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
navigator.navigate.upToHome()
|
navigator.navigate.upToHome()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue