• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

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