Skip to content

Instantly share code, notes, and snippets.

@NsAveek
Last active March 4, 2019 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NsAveek/85048dab729795242f5f303e7ba59c0d to your computer and use it in GitHub Desktop.
Save NsAveek/85048dab729795242f5f303e7ba59c0d to your computer and use it in GitHub Desktop.
A view holder class with State design pattern implemented
class StateViewHolder(binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) {
lateinit var viewModel: BaseViewModel
fun bind(info: Pair<Pair<Boolean, String>, Int>, remaining: Int) {
@DrawableRes val icon: Int
val stateContext: BaseStateContext
if (AppFlavor.country == Country.Bangladesh) {
icon=R.drawable.ico_state_1
val state = State1()
state.setParams(icon, info.first.first, info.second, remaining, info.first.second)
stateContext = BaseFeatureContext(state)
} else {
icon=R.drawable.ico_state_2
val state = State2()
state.setParams(icon, info.first.first, info.second, remaining)
stateContext = BaseFeatureContext(state)
}
viewModel = BaseViewModel(stateContext)
binding.viewModel=viewModel
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment