Hey all, is possible to simplify this code either ...
# announcements
a
Hey all, is possible to simplify this code either using when or some other idiomatic way in kotlin,
Copy code
private fun hideDeliveryDetailsIfNotRequired() {
    if (clearingZone.title == "-" && deliverMethod.title == "-"
        && deliverTo.title == "-" && pickupLocation.title == "-"
    ) {
        clearingZone.visibility = View.GONE
        deliverMethod.visibility = View.GONE
        deliverTo.visibility = View.GONE
        pickupLocation.visibility = View.GONE
    }
}
d
Copy code
val elements = listOf(clearingZone, deliverMethod, deliverTo, pickupLocation)
if (elements.all { it.title == "-" }) {
    elements.forEach { it.visibility = View.GONE }
}
👍 4
👌 1
a
Thank you
y
Additional solution would be: listOf(…).onEach { it.isGone = /your if statement / }
👍 1