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.View
20 import com.android.systemui.statusbar.notification.collection.PipelineDumpable
21 import com.android.systemui.statusbar.notification.collection.PipelineDumper
22 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
23 import com.android.systemui.statusbar.notification.row.ExpandableView
24 import com.android.systemui.statusbar.notification.stack.NotificationListContainer
25 
26 /**
27  * Temporary wrapper around [NotificationListContainer], for use by [ShadeViewDiffer]. Long term,
28  * we should just modify NLC to implement the NodeController interface.
29  */
30 class RootNodeController(
31     private val listContainer: NotificationListContainer,
32     override val view: View
33 ) : NodeController, PipelineDumpable {
34     override val nodeLabel: String = "<root>"
35     override fun offerToKeepInParentForAnimation(): Boolean = false
36     override fun removeFromParentIfKeptForAnimation(): Boolean = false
37     override fun resetKeepInParentForAnimation() {}
38 
39     override fun getChildAt(index: Int): View? {
40         return listContainer.getContainerChildAt(index)
41     }
42 
43     override fun getChildCount(): Int {
44         return listContainer.containerChildCount
45     }
46 
47     override fun addChildAt(child: NodeController, index: Int) {
48         listContainer.addContainerViewAt(child.view, index)
49         listContainer.onNotificationViewUpdateFinished()
50         (child.view as? ExpandableNotificationRow)?.isChangingPosition = false
51     }
52 
53     override fun moveChildTo(child: NodeController, index: Int) {
54         listContainer.changeViewPosition(child.view as ExpandableView, index)
55     }
56 
57     override fun removeChild(child: NodeController, isTransfer: Boolean) {
58         if (isTransfer) {
59             listContainer.setChildTransferInProgress(true)
60             (child.view as? ExpandableNotificationRow)?.isChangingPosition = true
61         }
62         listContainer.removeContainerView(child.view)
63         if (isTransfer) {
64             listContainer.setChildTransferInProgress(false)
65         }
66     }
67 
68     override fun dumpPipeline(d: PipelineDumper) = with(d) {
69         dump("listContainer", listContainer)
70     }
71 }
72