-
Notifications
You must be signed in to change notification settings - Fork 0
States & Events for MVI
kaloglu edited this page Jun 14, 2020
·
3 revisions
Sample for fragment scoped States & Events(MVI) implementation via sealed class
sealed class LoginState : State {
object UnAuthenticated : LoginState(), State.Success
data class Authenticated(val user: User) : LoginState(), State.Success
}
sealed class LoginEvent : Event {
data class LogIn(val user: User) : LoginEvent(), Event.Custom
data class LoggedIn(val user: User) : LoginEvent(), Event.Custom
object LogOut : LoginEvent(), Event.Custom
object LoggedOut : LoginEvent(), Event.Custom
}
sealed class TweetListState : State {
object Empty : TweetListState(), State.Empty
object Success : TweetListState(), State.Success
data class Error(val message: String) : TweetListState(), State.Error {
override val error: ErrorModel
get() = ErrorModel(message = message)
}
object Loading : TweetListState(), State.Loading
}
sealed class TweetListEvent : Event {
data class GetTweetList(val userId: Long) : TweetListEvent(), Event.Custom
data class ShowError(val message: String) : TweetListEvent(), Event.Custom
data class ShowLoading(val data: List<Tweet>?) : TweetListEvent(), Event.Custom
}
Full sample for databinding4vm : https://github.com/kaloglu/androtweet