Skip to content

Instantly share code, notes, and snippets.

Avatar
📈
Focusing, Learning, Improving, Evolving

Engine Bai enginebai

📈
Focusing, Learning, Improving, Evolving
View GitHub Profile
@enginebai
enginebai / MyController.kt
Created Dec 14, 2020
MovieHunt blog part5. controller sample
View MyController.kt
class MyController : EpoxyController() {
override fun buildModels() {
HeaderImageModel_()
LoadingModel_()
MovieModel_()
MovieModel_()
FooterModel_()
}
}
@enginebai
enginebai / MovieListController.kt
Created Dec 14, 2020
MovieHunt blog part5. movie list controller
View MovieListController.kt
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()
@enginebai
enginebai / MovieListEpoxyModel.kt
Created Dec 14, 2020
MovieHunt blog part5 view model pattern model
View MovieListEpoxyModel.kt
@EpoxyModelClass(layout = R.layout.holder_movie_landscape)
abstract class MovieListEpoxyModel : EpoxyModelWithHolder<MovieListEpoxyModel.Holder>() {
@EpoxyAttribute
var movieId = ""
@EpoxyAttribute
var imagePoster = ""
...
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var itemClickListener: (String) -> Unit = {}
@enginebai
enginebai / MovieHomeLargeBindingModel.kt
Created Dec 8, 2020
MovieHunt blog part5. epoxy model for data binding
View MovieHomeLargeBindingModel.kt
MovieHomeLargeBindingModel_()
.id("${movieCategory}${this.id}")
.movieId(this.id)
.posterImage(this.getPosterUrl())
.title(this.displayTitle())
.rating(this.voteAverage)
.voteCount(this.displayVoteCount())
.duration(this.displayDuration())
.clickListener(clickListener)
@enginebai
enginebai / item_movie_home_normal.xml
Created Dec 8, 2020
MovieHunt blog part5. data binding xml
View item_movie_home_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="movieId"
type="String" />
<variable
@enginebai
enginebai / package-info.java
Created Dec 8, 2020
MovieHunt blog part 5 epoxy model data binding setup
View package-info.java
@EpoxyDataBindingPattern(rClass = R.class, layoutPrefix = "item")
package com.enginebai.moviehunt;
import com.airbnb.epoxy.EpoxyDataBindingPattern;
@enginebai
enginebai / DropdownItemView.kt
Created Dec 8, 2020
MovieHunt blog part5. epoxy model custom view sample
View DropdownItemView.kt
@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT)
class DropdownItemView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
@TextProp
var itemText: CharSequence? = null
@enginebai
enginebai / MovieController.kt
Created Dec 8, 2020
MovieHunt blog part5. epoxy model and controller sample
View MovieController.kt
class LargeEpoxyModel : EpoxyModel {
override fun bind() {
// binding implementation
}
}
class NormalEpoxyModel : EpoxyModel {
override fun bind() {
// binding implementation
}
@enginebai
enginebai / MovieHomeAdapter.kt
Created Dec 8, 2020
MovieHunt blog part 5. movie home adapter
View MovieHomeAdapter.kt
data class MovieModel(
...
val largeSize: Boolean
)
class MovieHomeAdapter(private val movieList: List<MovieModel>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun getItemViewType(position: Int): Int {
return if (movieList.get(position).largeSize) {
R.layout.item_movie_large
@enginebai
enginebai / MovieDetailViewModel.kt
Created Nov 2, 2020
MovieHunt blog part4. detail view model
View MovieDetailViewModel.kt
class MovieDetailViewModel : BaseViewModel() {
private val movieRepo: MovieRepo by inject()
private val _movieDetail = MutableLiveData<MovieModel>()
val posterUrl: LiveData<String> = Transformations.map(_movieDetail) { it.getPosterUrl() }
val title: LiveData<String> = Transformations.map(_movieDetail) { it.displayTitle() }
val rating: LiveData<Float> = Transformations.map(_movieDetail) { it.display5StarsRating() }
val voteCount: LiveData<String> = Transformations.map(_movieDetail) { it.displayVoteCount() }
val duration: LiveData<String> = Transformations.map(_movieDetail) { it.displayDuration() }
val releaseDate: LiveData<String> = Transformations.map(_movieDetail) { it.displayReleaseDate() }