<lambda>null1package com.android.systemui.statusbar.notification.collection.provider 2 3 import android.util.ArraySet 4 import com.android.systemui.dagger.SysUISingleton 5 import com.android.systemui.util.ListenerSet 6 import javax.inject.Inject 7 8 @SysUISingleton 9 class VisualStabilityProvider @Inject constructor() { 10 /** All persistent and temporary listeners, in the order they were added */ 11 private val allListeners = ListenerSet<OnReorderingAllowedListener>() 12 13 /** The subset of active listeners which are temporary (will be removed after called) */ 14 private val temporaryListeners = ArraySet<OnReorderingAllowedListener>() 15 16 var isReorderingAllowed = true 17 set(value) { 18 if (field != value) { 19 field = value 20 if (value) { 21 notifyReorderingAllowed() 22 } 23 } 24 } 25 26 private fun notifyReorderingAllowed() { 27 allListeners.forEach { listener -> 28 if (temporaryListeners.remove(listener)) { 29 allListeners.remove(listener) 30 } 31 listener.onReorderingAllowed() 32 } 33 } 34 35 /** Add a listener which will be called until it is explicitly removed. */ 36 fun addPersistentReorderingAllowedListener(listener: OnReorderingAllowedListener) { 37 temporaryListeners.remove(listener) 38 allListeners.addIfAbsent(listener) 39 } 40 41 /** Add a listener which will be removed when it is called. */ 42 fun addTemporaryReorderingAllowedListener(listener: OnReorderingAllowedListener) { 43 // Only add to the temporary set if it was added to the global set 44 // to keep permanent listeners permanent 45 if (allListeners.addIfAbsent(listener)) { 46 temporaryListeners.add(listener) 47 } 48 } 49 50 /** Remove a listener from receiving any callbacks, whether it is persistent or temporary. */ 51 fun removeReorderingAllowedListener(listener: OnReorderingAllowedListener) { 52 temporaryListeners.remove(listener) 53 allListeners.remove(listener) 54 } 55 } 56 interfacenull57fun interface OnReorderingAllowedListener { 58 fun onReorderingAllowed() 59 } 60