forked from cobeisfresh/CleanArchitecture-Android-Showcase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change ViewState from generic class to sealed class
- Loading branch information
1 parent
5074bb0
commit 069de6f
Showing
3 changed files
with
17 additions
and
35 deletions.
There are no files selected for viewing
25 changes: 4 additions & 21 deletions
25
app/src/main/java/com/cobeisfresh/template/ui/base/ViewState.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,8 @@ | ||
package com.cobeisfresh.template.ui.base | ||
|
||
import com.cobeisfresh.template.ui.base.ViewState.Status.* | ||
sealed class ViewState<out T : Any> | ||
class Success<out T : Any>(val data: T) : ViewState<T>() | ||
class Error<out T : Any>(val error: Throwable) : ViewState<T>() | ||
class Loading<out T : Any> : ViewState<T>() | ||
|
||
data class ViewState<T>(val status: Status, val data: T?, val error: Throwable?) { | ||
|
||
enum class Status { | ||
SUCCESS, ERROR, LOADING | ||
} | ||
|
||
companion object { | ||
fun <T> success(data: T): ViewState<T> { | ||
return ViewState(SUCCESS, data, null) | ||
} | ||
|
||
fun <T> error(error: Throwable): ViewState<T> { | ||
return ViewState(ERROR, null, error) | ||
} | ||
|
||
fun <T> loading(): ViewState<T> { | ||
return ViewState(LOADING, null, 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
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