1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.statusbar.notification.collection.notifcollection 18 19 import android.service.notification.NotificationListenerService.RankingMap 20 import android.service.notification.StatusBarNotification 21 import com.android.systemui.statusbar.notification.collection.NotifCollection 22 import com.android.systemui.statusbar.notification.collection.NotificationEntry 23 24 /** 25 * Set of classes that represent the various events that [NotifCollection] can dispatch to 26 * [NotifCollectionListener]s. 27 * 28 * These events build up in a queue and are periodically emitted in chunks by the collection. 29 */ 30 31 sealed class NotifEvent { dispatchTonull32 fun dispatchTo(listeners: List<NotifCollectionListener>) { 33 for (i in listeners.indices) { 34 dispatchToListener(listeners[i]) 35 } 36 } 37 dispatchToListenernull38 abstract fun dispatchToListener(listener: NotifCollectionListener) 39 } 40 41 data class BindEntryEvent( 42 val entry: NotificationEntry, 43 val sbn: StatusBarNotification 44 ) : NotifEvent() { 45 override fun dispatchToListener(listener: NotifCollectionListener) { 46 listener.onEntryBind(entry, sbn) 47 } 48 } 49 50 data class InitEntryEvent( 51 val entry: NotificationEntry 52 ) : NotifEvent() { dispatchToListenernull53 override fun dispatchToListener(listener: NotifCollectionListener) { 54 listener.onEntryInit(entry) 55 } 56 } 57 58 data class EntryAddedEvent( 59 val entry: NotificationEntry 60 ) : NotifEvent() { dispatchToListenernull61 override fun dispatchToListener(listener: NotifCollectionListener) { 62 listener.onEntryAdded(entry) 63 } 64 } 65 66 data class EntryUpdatedEvent( 67 val entry: NotificationEntry 68 ) : NotifEvent() { dispatchToListenernull69 override fun dispatchToListener(listener: NotifCollectionListener) { 70 listener.onEntryUpdated(entry) 71 } 72 } 73 74 data class EntryRemovedEvent( 75 val entry: NotificationEntry, 76 val reason: Int 77 ) : NotifEvent() { dispatchToListenernull78 override fun dispatchToListener(listener: NotifCollectionListener) { 79 listener.onEntryRemoved(entry, reason) 80 } 81 } 82 83 data class CleanUpEntryEvent( 84 val entry: NotificationEntry 85 ) : NotifEvent() { dispatchToListenernull86 override fun dispatchToListener(listener: NotifCollectionListener) { 87 listener.onEntryCleanUp(entry) 88 } 89 } 90 91 data class RankingUpdatedEvent( 92 val rankingMap: RankingMap 93 ) : NotifEvent() { dispatchToListenernull94 override fun dispatchToListener(listener: NotifCollectionListener) { 95 listener.onRankingUpdate(rankingMap) 96 } 97 } 98 99 class RankingAppliedEvent() : NotifEvent() { dispatchToListenernull100 override fun dispatchToListener(listener: NotifCollectionListener) { 101 listener.onRankingApplied() 102 } 103 } 104