Skip to content

Instantly share code, notes, and snippets.

@UdiOshi85
Last active March 5, 2020 15:10
Show Gist options
  • Save UdiOshi85/a7892628e022ec5aeaaf70c12e014027 to your computer and use it in GitHub Desktop.
Save UdiOshi85/a7892628e022ec5aeaaf70c12e014027 to your computer and use it in GitHub Desktop.
LiveData Resource class
data class Resource<out T>(val status: Status, val actionType: Int, val data: T?, val payload: Bundle?) {
companion object {
fun <T> success(actionType: Int, data: T? = null, payload: Bundle? = null): Resource<T> {
return Resource(Status.SUCCESS,actionType, data, payload)
}
fun <T> error(actionType: Int, data: T? = null, payload: Bundle? = null): Resource<T> {
return Resource(Status.ERROR, actionType, data, payload)
}
fun <T> loading(actionType: Int, data: T? = null, payload: Bundle? = null): Resource<T> {
return Resource(Status.LOADING, actionType, data, payload)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment