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.render 18 19 import android.view.textclassifier.Log 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.statusbar.notification.collection.ListEntry 22 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRowController 23 import javax.inject.Inject 24 25 /** 26 * The ViewBarn is just a map from [ListEntry] to an instance of an 27 * [ExpandableNotificationRowController]. 28 */ 29 @SysUISingleton 30 class NotifViewBarn @Inject constructor() { 31 private val rowMap = mutableMapOf<String, ExpandableNotificationRowController>() 32 requireViewnull33 fun requireView(forEntry: ListEntry): ExpandableNotificationRowController { 34 if (DEBUG) { 35 Log.d(TAG, "requireView: $forEntry.key") 36 } 37 val li = rowMap[forEntry.key] 38 if (li == null) { 39 throw IllegalStateException("No view has been registered for entry: $forEntry") 40 } 41 42 return li 43 } 44 registerViewForEntrynull45 fun registerViewForEntry(entry: ListEntry, controller: ExpandableNotificationRowController) { 46 if (DEBUG) { 47 Log.d(TAG, "registerViewForEntry: $entry.key") 48 } 49 rowMap[entry.key] = controller 50 } 51 removeViewForEntrynull52 fun removeViewForEntry(entry: ListEntry) { 53 if (DEBUG) { 54 Log.d(TAG, "removeViewForEntry: $entry.key") 55 } 56 rowMap.remove(entry.key) 57 } 58 } 59 60 private const val TAG = "NotifViewBarn" 61 62 private const val DEBUG = false