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