Something went wrong. Try again.
A fork of Simple Time Tracker with WearOS support. (Now integrated upstream)
Something went wrong. Try again.
SimpleTimeTracker-WearOS app src androidTest java com example util simpletimetracker utils TestUtils.kt
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051package com.example.util.simpletimetracker.utils
import android.view.Viewimport android.view.ViewGroupimport android.view.ViewParentimport com.google.android.material.appbar.AppBarLayout
internal fun View.collapseAllAppBarsInParent() { findViewsInParent(AppBarLayout::class.java) .forEach { it.setExpanded(false) }}
internal fun <T> View.findViewsInParent( viewType: Class<T>,): Collection<T> = findViewsInParentRecursively( startView = this, currentParent = this.parent, type = viewType,)
private fun <T> findViewsInParentRecursively( startView: View, currentParent: ViewParent, type: Class<T>, result: MutableCollection<T> = mutableSetOf(),): Collection<T> { if (currentParent !is ViewGroup) { return result }
if (type.isInstance(currentParent)) { @Suppress("UNCHECKED_CAST") result += currentParent as T }
(0 until currentParent.childCount) .map { currentParent.getChildAt(it) } .filter { it != startView } .filter { type.isInstance(it) } .forEach { view -> @Suppress("UNCHECKED_CAST") result += view as T }
return findViewsInParentRecursively( startView = startView, currentParent = currentParent.parent, type = type, result = result, )}