Last active
March 4, 2019 16:01
-
-
Save NsAveek/85048dab729795242f5f303e7ba59c0d to your computer and use it in GitHub Desktop.
A view holder class with State design pattern implemented
This file contains 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 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