Last active
September 10, 2018 22:57
-
-
Save markchristopherng/380aa7d09555c69332c7297757c65197 to your computer and use it in GitHub Desktop.
Resource show loading state
This file contains hidden or 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
/** | |
* A generic class that holds a value with its loading status. | |
* @param <T> | |
</T> */ | |
data class Resource<out T>(val status: Status, val data: T?, val message: String?) { | |
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