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.collection.NotificationEntry 23 import javax.inject.Inject 24 25 /** 26 * The ViewBarn is just a map from [ListEntry] to an instance of a [NodeController]. 27 */ 28 @SysUISingleton 29 class NotifViewBarn @Inject constructor() { 30 private val rowMap = mutableMapOf<String, NotifViewController>() 31 32 fun requireNodeController(entry: ListEntry): NodeController { 33 if (DEBUG) { 34 Log.d(TAG, "requireNodeController: ${entry.key}") 35 } 36 return rowMap[entry.key] ?: error("No view has been registered for entry: ${entry.key}") 37 } 38 39 fun requireGroupController(entry: NotificationEntry): NotifGroupController { 40 if (DEBUG) { 41 Log.d(TAG, "requireGroupController: ${entry.key}") 42 } 43 return rowMap[entry.key] ?: error("No view has been registered for entry: ${entry.key}") 44 } 45 46 fun requireRowController(entry: NotificationEntry): NotifRowController { 47 if (DEBUG) { 48 Log.d(TAG, "requireRowController: ${entry.key}") 49 } 50 return rowMap[entry.key] ?: error("No view has been registered for entry: ${entry.key}") 51 } 52 53 fun registerViewForEntry(entry: ListEntry, controller: NotifViewController) { 54 if (DEBUG) { 55 Log.d(TAG, "registerViewForEntry: ${entry.key}") 56 } 57 rowMap[entry.key] = controller 58 } 59 60 fun removeViewForEntry(entry: ListEntry) { 61 if (DEBUG) { 62 Log.d(TAG, "removeViewForEntry: ${entry.key}") 63 } 64 rowMap.remove(entry.key) 65 } 66 } 67 68 private const val TAG = "NotifViewBarn" 69 70 private const val DEBUG = false