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.provider 18 19 import com.android.internal.statusbar.NotificationVisibility 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.statusbar.notification.collection.NotifLiveDataStore 22 import com.android.systemui.statusbar.notification.collection.NotificationEntry 23 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection 24 import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider 25 import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor 26 import com.android.systemui.statusbar.notification.logging.NotificationLogger 27 import com.android.systemui.statusbar.notification.shared.NotificationsLiveDataStoreRefactor 28 import javax.inject.Inject 29 30 /** pipeline-agnostic implementation for getting [NotificationVisibility]. */ 31 @SysUISingleton 32 class NotificationVisibilityProviderImpl 33 @Inject 34 constructor( 35 private val activeNotificationsInteractor: ActiveNotificationsInteractor, 36 private val notifDataStore: NotifLiveDataStore, 37 private val notifCollection: CommonNotifCollection 38 ) : NotificationVisibilityProvider { 39 obtainnull40 override fun obtain(entry: NotificationEntry, visible: Boolean): NotificationVisibility { 41 val count: Int = getCount() 42 val rank = entry.ranking.rank 43 val hasRow = entry.row != null 44 val location = NotificationLogger.getNotificationLocation(entry) 45 return NotificationVisibility.obtain(entry.key, rank, count, visible && hasRow, location) 46 } 47 obtainnull48 override fun obtain(key: String, visible: Boolean): NotificationVisibility = 49 notifCollection.getEntry(key)?.let { return obtain(it, visible) } 50 ?: NotificationVisibility.obtain(key, -1, getCount(), false) 51 getLocationnull52 override fun getLocation(key: String): NotificationVisibility.NotificationLocation = 53 NotificationLogger.getNotificationLocation(notifCollection.getEntry(key)) 54 55 private fun getCount() = 56 if (NotificationsLiveDataStoreRefactor.isEnabled) { 57 activeNotificationsInteractor.allNotificationsCountValue 58 } else { 59 notifDataStore.activeNotifCount.value 60 } 61 } 62