Skip to content

Instantly share code, notes, and snippets.

@yogeshpaliyal
Created June 23, 2021 15:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yogeshpaliyal/1c44e55d3852cecdce0a1caf68eb77ce to your computer and use it in GitHub Desktop.
Wrapper class for Data and Status
/**
* @author Yogesh Paliyal
* Created Date : 15 October 2020
*/
data class Resource<out T>(val status: Status, val data: T?, val message: String?) {
companion object {
fun <T> success(data: T?, message: String?= ""): Resource<T> {
return Resource(Status.SUCCESS, data, message)
}
fun <T> create(status: Status,data: T?, message: String?= ""): Resource<T> {
return Resource(status, data, message)
}
fun <T> error(msg: String?, data: T? = null): Resource<T> {
return Resource(Status.ERROR, data, msg)
}
fun <T> loading(data: T? = null): Resource<T> {
return Resource(Status.LOADING, data, null)
}
}
}
/**
* @author Yogesh Paliyal
* Created Date : 15 October 2020
*/
enum class Status {
SUCCESS,
ERROR,
LOADING
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment