Created
June 23, 2021 15:04
-
-
Save yogeshpaliyal/1c44e55d3852cecdce0a1caf68eb77ce to your computer and use it in GitHub Desktop.
Wrapper class for Data and Status
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
/** | |
* @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) | |
} | |
} | |
} |
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
/** | |
* @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