Skip to content

Instantly share code, notes, and snippets.

@AliMehrpour
Created December 30, 2019 08:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save AliMehrpour/e4787020fe2356ad9301820e74adc4d4 to your computer and use it in GitHub Desktop.
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)
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