Created
December 30, 2019 08:30
-
-
Save AliMehrpour/e4787020fe2356ad9301820e74adc4d4 to your computer and use it in GitHub Desktop.
A generic class that describe data with a status used Sealed classes in Kotlin (rather than using enum)
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
import java.util.* | |
sealed class Resource { | |
class Success<out T>(val data: T, val date: Date?): Resource() | |
class Error(val message: String, val date: Date?): Resource() | |
class Loading<out T>(val data: T): Resource() | |
class Cached<out T>(val data: T, val date: Date?): Resource() | |
object ReAuthenticate : Resource() | |
object Logout: Resource() | |
} | |
/* | |
Usage: | |
Resource.Success(response.body(), Date()) | |
Resource.Logout() | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment