Created
December 24, 2018 05:56
-
-
Save anitaa1990/819dcac8dbb6e9ae1d2edd6c7464ec8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Resource<T> private constructor(val status: Status, val data: T?, val message: String?) { | |
val isSuccess: Boolean | |
get() = status === Status.SUCCESS && data != null | |
val isLoading: Boolean | |
get() = status === Status.LOADING | |
val isLoaded: Boolean | |
get() = status !== Status.LOADING | |
companion object { | |
fun <T> success(data: T): Resource<T> { | |
return Resource(SUCCESS, data, null) | |
} | |
fun <T> error(msg: String, data: T?): Resource<T> { | |
return Resource(ERROR, data, msg) | |
} | |
fun <T> loading(data: T?): Resource<T> { | |
return Resource(LOADING, data, null) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment