ursus
07/20/2019, 4:33 AMState(val message: List<Message>, ...)
-> ExternalState(val items: List<Item>,...)
Menil Vukovic
07/24/2019, 8:36 PMList<Item>
in the first place?
when you have a state that holds your initial list of items (of whatever kind) you can map them to your recyclerview and use the following pages to do the same. Last state you emitted will contain the last page of data, and the adapter of your recyclerview will contain all of items you have so far.ursus
07/24/2019, 8:40 PMMenil Vukovic
07/24/2019, 8:42 PMPageState(val pageNr: Int, val items: List<Item>)
during each paginationursus
07/24/2019, 8:42 PMMenil Vukovic
07/24/2019, 8:42 PMLoadingPageState
which could trigger loading on the UIursus
07/24/2019, 8:43 PMMenil Vukovic
07/24/2019, 8:44 PMursus
07/24/2019, 8:44 PMMenil Vukovic
07/24/2019, 8:46 PMwhat does my View need?
and I expose only things that my view will consume directly
My presenter
can take care of boxing, mapping or whatever is needed. I will only push pure usable data to my viewursus
07/24/2019, 8:47 PMMenil Vukovic
07/24/2019, 8:48 PMursus
07/24/2019, 8:49 PMMenil Vukovic
07/24/2019, 8:49 PMursus
07/24/2019, 8:50 PMMenil Vukovic
07/24/2019, 8:50 PMsealed class EmailLoginViewState
data class EmailLoginFullViewState(val error: ErrorMessageEnum? = null,
val isValid: Boolean = false,
val loading: Boolean = false,
val eye: Boolean? = null)
class EmailLoginErrorViewState(val error: ErrorMessageEnum?) : EmailLoginViewState()
class EmailLoginForgotViewState : EmailLoginViewState()
class EmailLoginBackViewState : EmailLoginViewState()
class EmailLoginSignInViewState : EmailLoginViewState()
class EmailValidateViewState(val isValid: Boolean) : EmailLoginViewState()
class EmailLoginLoadingViewState(val loading: Boolean) : EmailLoginViewState()
class EmailEyeViewState(val eye: Boolean?) : EmailLoginViewState()
override fun viewStateReducer(
previousState: EmailLoginFullViewState,
changes: EmailLoginViewState
): EmailLoginFullViewState {
return when (changes) {
is EmailLoginErrorViewState -> previousState.copy(error = changes.error, loading = false)
is EmailLoginForgotViewState -> previousState.copy()
is EmailLoginBackViewState -> previousState.copy()
is EmailLoginSignInViewState -> previousState.copy(loading = false)
is EmailValidateViewState -> previousState.copy(isValid = changes.isValid)
is EmailLoginLoadingViewState -> previousState.copy(loading = changes.loading)
is EmailEyeViewState -> previousState.copy(eye = changes.eye)
}
}
ursus
07/24/2019, 8:58 PMMenil Vukovic
07/24/2019, 9:01 PMursus
07/24/2019, 9:04 PMMenil Vukovic
07/24/2019, 9:10 PM(loading = false)
as soon as loading is finished