Skip to content

Instantly share code, notes, and snippets.

@HarryTylenol
Created August 5, 2019 14:15
Show Gist options
  • Save HarryTylenol/6f41bb3fb77dab685e6522fd4d96781c to your computer and use it in GitHub Desktop.
Save HarryTylenol/6f41bb3fb77dab685e6522fd4d96781c to your computer and use it in GitHub Desktop.
0003_2
// ResponseWrapper
data class ResponseWrapper<T>(
val data: LiveData<T>,
val state: LiveData<NetworkState>,
val refreshState: LiveData<NetworkState>,
val refresh: () -> Unit
)
// NetworkState
sealed class NetworkState {
override fun toString(): String {
return when (this) {
is success -> "NetworkState.success"
is failed -> "NetworkState.failed : ${error?.message}"
is loading -> "NetworkState.loading"
}
}
object success : NetworkState()
class failed(val error: Throwable? = null) : NetworkState()
object loading : NetworkState()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment