1 /* 2 * Copyright (C) 2021 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 18 19 import androidx.lifecycle.Observer 20 21 /** 22 * An object which provides pieces of information about the notification shade. 23 * 24 * Note that individual fields of this object are updated together before synchronous observers are 25 * notified, so synchronous observers of two fields can be assured that they will see consistent 26 * results: e.g. if [hasActiveNotifs] is false then [activeNotifList] will be empty, and vice versa. 27 * 28 * This interface is read-only. 29 */ 30 interface NotifLiveDataStore { 31 val hasActiveNotifs: NotifLiveData<Boolean> 32 val activeNotifCount: NotifLiveData<Int> 33 val activeNotifList: NotifLiveData<List<NotificationEntry>> 34 } 35 36 /** 37 * An individual value which can be accessed directly, or observed for changes either synchronously 38 * or asynchronously. 39 * 40 * This interface is read-only. 41 */ 42 interface NotifLiveData<T> { 43 /** Access the current value */ 44 val value: T 45 /** Add an observer which will be invoked synchronously when the value is changed. */ addSyncObservernull46 fun addSyncObserver(observer: Observer<T>) 47 /** Add an observer which will be invoked asynchronously after the value has changed */ 48 fun addAsyncObserver(observer: Observer<T>) 49 /** Remove an observer previously added with [addSyncObserver] or [addAsyncObserver]. */ 50 fun removeObserver(observer: Observer<T>) 51 } 52