For example I have:
My two cents function without recursion
package io.chord.ui.utils
import android.view.View
import android.view.ViewGroup
import androidx.core.view.forEach
class ViewUtils
{
companion object
{
fun setViewState(view: View, state: Boolean)
{
var depth = 0
val views: MutableMap> = mutableMapOf()
views[depth] = mutableListOf(view)
while(true)
{
val currentViews = views[depth]
val nextViews = mutableListOf()
currentViews!!.forEach { view ->
if(view is ViewGroup)
{
view.forEach { children ->
nextViews.add(children)
}
}
}
if(nextViews.size == 0)
{
break
}
depth++
views[depth] = nextViews
}
views.flatMap {
it.value
}.forEach {
it.isEnabled = state
}
}
}
}