Created
April 14, 2020 16:22
-
-
Save Nimrodda/acbdda32b534d0a9ed1e8aa02889687f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class WorkoutSummaryController : TypedEpoxyController<WorkoutSummaryViewState>( | |
EpoxyAsyncUtil.getAsyncBackgroundHandler(), | |
EpoxyAsyncUtil.getAsyncBackgroundHandler()) { | |
override fun buildModels(viewState: WorkoutSummaryViewState) { | |
addLikes(viewState) | |
addLoadingIndicatorIfNeed(viewState) | |
} | |
private fun addLikes(viewState: WorkoutSummaryViewState) { | |
val likesItem = viewState.likesItem.data | |
// We verify that the state is loaded, we can use the state to show a loading indicator | |
// only for this item if we want | |
if (viewState.likesItem is ViewState.Loaded && likesItem != null) { | |
likes { | |
id("likes") | |
likesItem(likesItem) | |
onLikeClicked { model, _, _, _ -> | |
model.likesItem().onClickHandler(viewState.workoutId) | |
} | |
} | |
} else if (viewState.likesItem is ViewState.Error) { | |
// Instead of adding the likes item, we can use the state of the item to add | |
// a generic error item instead | |
addErrorItem(/* pass here some data to decide the message */) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment