diff options
| author | Kalle Lindström <karl.lindstrom@mullvad.net> | 2025-04-15 15:55:33 +0200 |
|---|---|---|
| committer | Kalle Lindström <karl.lindstrom@mullvad.net> | 2025-04-22 12:12:11 +0200 |
| commit | 5f981d8af8df2d38a38a30e7fc9a3f31df651f07 (patch) | |
| tree | 502f76ec3004abff0604c8e5ebc693cc9be8531f /android | |
| parent | 9d9ea8851950c665721a3de5f2f97734774108fd (diff) | |
| download | mullvadvpn-5f981d8af8df2d38a38a30e7fc9a3f31df651f07.tar.xz mullvadvpn-5f981d8af8df2d38a38a30e7fc9a3f31df651f07.zip | |
Add LoadingContentError type
Diffstat (limited to 'android')
| -rw-r--r-- | android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LoadingContentError.kt | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LoadingContentError.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LoadingContentError.kt new file mode 100644 index 0000000000..8be59ef814 --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LoadingContentError.kt @@ -0,0 +1,43 @@ +package net.mullvad.mullvadvpn.util + +sealed interface Lce<out T, out E> { + data object Loading : Lce<Nothing, Nothing> + + data class Content<T>(val value: T) : Lce<T, Nothing> + + data class Error<E>(val error: E) : Lce<Nothing, E> + + fun content(): T? = + when (this) { + is Loading, + is Error -> null + is Content -> value + } + + fun error(): E? = + when (this) { + is Loading, + is Content -> null + is Error -> error + } + + fun isLoading(): Boolean = this is Loading +} + +fun <T, E> T.toLce(): Lce<T, E> = Lce.Content(this) + +sealed interface Lc<out T> { + data object Loading : Lc<Nothing> + + data class Content<T>(val value: T) : Lc<T> + + fun content(): T? = + when (this) { + is Content -> value + Loading -> null + } + + fun isLoading(): Boolean = this is Loading +} + +fun <T> T.toLc(): Lc<T> = Lc.Content(this) |
