Cicero
11/26/2020, 12:57 PMabstract class AbstractResourceTopic(val state: ResourceState? = null, val isOn: Boolean? = null) {
abstract val resourceType: ResourceType
}
and this
fun AbstractResourceTopic.getIcon(): Int {
this.state?.let {
return when (it.state) {
0 -> getStateZeroIcon()
1 -> getStateOneIcon()
2 -> getStateTwoIcon()
else -> getStateZeroIcon()
}
}
this.isOn?.let {
return if (isOn) getOnIcon() else getOffIcon()
}
return getStateZeroIcon()
}
I turned into this
abstract class AbstractResourceTopic {
constructor(state: ResourceState)
constructor(isOn: Boolean)
abstract val resourceType: ResourceType
}
and I don’t know how to create extension classes for this two different constructors
fun AbstractResourceTopic.getStateIcon(): Int {
return when (it.state) {
0 -> getStateZeroIcon()
1 -> getStateOneIcon()
2 -> getStateTwoIcon()
else -> getStateZeroIcon()
}
}
}
fun AbstractResourceTopic.getIsOnIcon(): Int {
return if (isOn) getOnIcon() else getO
}
This is not working and I couldn’t find the correct syntax or if I can even do thisribesg
11/26/2020, 1:27 PMnrobi
11/26/2020, 1:28 PMAbstractResourceTopic
doesn’t have neither a state
nor an isOn
field this wayCicero
11/26/2020, 1:31 PM