private fun renderA(state :AViewModel.State?){
when (state){
is AViewModel.State.Success -> {
if (state.description.isNotEmpty()) binding.textView1.text = state.description
}
else ->{
}
}
}
private fun renderB(state :BViewModel.State?){
when (state){
is BViewModel.State.Success -> {
if (state.description.isNotEmpty()) binding.textView1.text = state.description
}
else ->{
}
}
}
这两个功能都在影响textView1
如何阻止它们互相覆盖
它们都来自不同的模型视图和观察者
如何优先考虑renderA
:
如果发生renderA
,则renderB
文本视图部分不应在Clean Code架构中执行?
private fun renderA(state :AViewModel.State?){
when (state){
is AViewModel.State.Success -> {
setDescription(state.description)
}
else ->{
}
}
}
private fun renderB(state :BViewModel.State?){
when (state){
is BViewModel.State.Success -> {
setDescription(state.description)
}
else ->{
}
}
}
fun setDescription(description: String) {
if(description.isNotEmpty() && binding.textView1.text.isEmpty()){
binding.textView1.text = description
}
}