Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MovieHunt blog part5. movie list controller
class MovieListController(
private val context: Context,
private val clickListener: MovieClickListener
) : PagedListEpoxyController<MovieModel>() {
private val loadMoreView = LoadMoreView_().apply { id(LoadMoreView::class.java.simpleName) }
var loadingMore = false
set(value) {
field = value
requestModelBuild()
}
override fun buildItemModel(currentPosition: Int, item: MovieModel?): EpoxyModel<*> {
return item?.run {
MovieListEpoxyModel_()
.id(this.id)
.movieId(this.id)
.imagePoster(this.getPosterUrl())
.textTitle(this.displayTitle())
.rating(this.display5StarsRating())
.voteCount(context.getString(R.string.vote_count, this.displayVoteCount()))
.duration(this.displayDuration())
.releaseDate(this.displayReleaseDate())
.itemClickListener { clickListener.onMovieClicked(this.id) }
} ?: run {
MovieListEpoxyModel_()
.id(-currentPosition)
}
}
override fun addModels(models: List<EpoxyModel<*>>) {
super.addModels(models)
loadMoreView.addIf(loadingMore, this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment