• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 
18 package com.android.systemui.keyguard.ui.view.layout.sections
19 
20 import android.content.Context
21 import android.view.View
22 import android.view.ViewGroup
23 import androidx.constraintlayout.widget.Barrier
24 import androidx.constraintlayout.widget.ConstraintLayout
25 import androidx.constraintlayout.widget.ConstraintSet
26 import androidx.constraintlayout.widget.ConstraintSet.BOTTOM
27 import androidx.constraintlayout.widget.ConstraintSet.TOP
28 import com.android.systemui.keyguard.shared.model.KeyguardSection
29 import com.android.systemui.res.R
30 import com.android.systemui.shade.NotificationPanelView
31 import com.android.systemui.statusbar.notification.stack.ui.view.SharedNotificationContainer
32 import com.android.systemui.statusbar.notification.stack.ui.viewbinder.SharedNotificationContainerBinder
33 import com.android.systemui.statusbar.notification.stack.ui.viewmodel.SharedNotificationContainerViewModel
34 import kotlinx.coroutines.DisposableHandle
35 
36 abstract class NotificationStackScrollLayoutSection
37 constructor(
38     protected val context: Context,
39     private val notificationPanelView: NotificationPanelView,
40     private val sharedNotificationContainer: SharedNotificationContainer,
41     private val sharedNotificationContainerViewModel: SharedNotificationContainerViewModel,
42     private val sharedNotificationContainerBinder: SharedNotificationContainerBinder,
43 ) : KeyguardSection() {
44     private val placeHolderId = R.id.nssl_placeholder
45     private var disposableHandle: DisposableHandle? = null
46 
47     /**
48      * Align the notification placeholder bottom to the top of either the lock icon or the ambient
49      * indication area, whichever is higher.
50      */
addNotificationPlaceholderBarriernull51     protected fun addNotificationPlaceholderBarrier(constraintSet: ConstraintSet) {
52         constraintSet.apply {
53             createBarrier(
54                 R.id.nssl_placeholder_barrier_bottom,
55                 Barrier.TOP,
56                 0,
57                 *intArrayOf(R.id.device_entry_icon_view, R.id.ambient_indication_container),
58             )
59             connect(placeHolderId, BOTTOM, R.id.nssl_placeholder_barrier_bottom, TOP)
60         }
61     }
62 
addViewsnull63     override fun addViews(constraintLayout: ConstraintLayout) {
64         // This moves the existing NSSL view to a different parent, as the controller is a
65         // singleton and recreating it has other bad side effects.
66         // In the SceneContainer, this is done by the NotificationSection composable.
67         notificationPanelView.findViewById<View?>(R.id.notification_stack_scroller)?.let {
68             (it.parent as ViewGroup).removeView(it)
69             sharedNotificationContainer.addNotificationStackScrollLayout(it)
70         }
71 
72         val view = View(context, null).apply { id = placeHolderId }
73         constraintLayout.addView(view)
74     }
75 
bindDatanull76     override fun bindData(constraintLayout: ConstraintLayout) {
77         disposableHandle?.dispose()
78         disposableHandle =
79             sharedNotificationContainerBinder.bind(
80                 sharedNotificationContainer,
81                 sharedNotificationContainerViewModel,
82             )
83     }
84 
removeViewsnull85     override fun removeViews(constraintLayout: ConstraintLayout) {
86         disposableHandle?.dispose()
87         disposableHandle = null
88         constraintLayout.removeView(placeHolderId)
89     }
90 }
91