mirror of
https://github.com/bitfireAT/davx5-ose
synced 2024-09-06 18:01:11 +00:00
DeleteCollectionDialog: handle case that result may contain null value (#697)
This commit is contained in:
parent
6d462ea9e4
commit
6b88052e10
|
@ -33,7 +33,7 @@ import at.bitfire.davdroid.R
|
||||||
import at.bitfire.davdroid.db.Collection
|
import at.bitfire.davdroid.db.Collection
|
||||||
import at.bitfire.davdroid.ui.widget.ExceptionInfoDialog
|
import at.bitfire.davdroid.ui.widget.ExceptionInfoDialog
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import java.util.Optional
|
import kotlin.jvm.optionals.getOrNull
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DeleteCollectionDialog(
|
fun DeleteCollectionDialog(
|
||||||
|
@ -58,17 +58,18 @@ fun DeleteCollectionDialog(
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
properties = DialogProperties(dismissOnClickOutside =
|
properties = DialogProperties(
|
||||||
result != null || // finished with error message
|
dismissOnClickOutside =
|
||||||
!started // not started
|
result != null || // finished with error message
|
||||||
),
|
!started // not started
|
||||||
|
),
|
||||||
onDismissRequest = ::dismiss
|
onDismissRequest = ::dismiss
|
||||||
) {
|
) {
|
||||||
Card {
|
Card {
|
||||||
DeleteCollectionDialog_Content(
|
DeleteCollectionDialog_Content(
|
||||||
collection = collection,
|
collection = collection,
|
||||||
started = started,
|
started = started,
|
||||||
result = result,
|
result = result?.getOrNull(),
|
||||||
onDeleteCollection = {
|
onDeleteCollection = {
|
||||||
started = true
|
started = true
|
||||||
model.deleteCollection(collection)
|
model.deleteCollection(collection)
|
||||||
|
@ -83,7 +84,7 @@ fun DeleteCollectionDialog(
|
||||||
fun DeleteCollectionDialog_Content(
|
fun DeleteCollectionDialog_Content(
|
||||||
collection: Collection,
|
collection: Collection,
|
||||||
started: Boolean,
|
started: Boolean,
|
||||||
result: Optional<Exception>?,
|
result: Exception?,
|
||||||
onDeleteCollection: () -> Unit = {},
|
onDeleteCollection: () -> Unit = {},
|
||||||
onCancel: () -> Unit = {}
|
onCancel: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
|
@ -100,14 +101,11 @@ fun DeleteCollectionDialog_Content(
|
||||||
)
|
)
|
||||||
|
|
||||||
when {
|
when {
|
||||||
result != null -> {
|
result != null -> ExceptionInfoDialog(
|
||||||
val exception = result.get()
|
exception = result,
|
||||||
ExceptionInfoDialog(
|
remoteResource = collection.url,
|
||||||
exception = exception,
|
onDismiss = onCancel
|
||||||
remoteResource = collection.url,
|
)
|
||||||
onDismiss = onCancel
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
started -> {
|
started -> {
|
||||||
LinearProgressIndicator(
|
LinearProgressIndicator(
|
||||||
|
@ -202,6 +200,6 @@ fun DeleteCollectionDialog_Preview_Error() {
|
||||||
url = "https://example.com/calendar".toHttpUrl(),
|
url = "https://example.com/calendar".toHttpUrl(),
|
||||||
),
|
),
|
||||||
started = true,
|
started = true,
|
||||||
result = Optional.of(Exception("Test error"))
|
result = Exception("Test error")
|
||||||
)
|
)
|
||||||
}
|
}
|
Loading…
Reference in a new issue