• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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.annotation.StringRes
20 import android.content.Intent
21 import android.view.LayoutInflater
22 import android.view.View
23 import android.view.ViewGroup
24 import com.android.systemui.plugins.ActivityStarter
25 import com.android.systemui.res.R
26 import com.android.systemui.shade.ShadeDisplayAware
27 import com.android.systemui.statusbar.notification.dagger.HeaderClickAction
28 import com.android.systemui.statusbar.notification.dagger.HeaderText
29 import com.android.systemui.statusbar.notification.dagger.NodeLabel
30 import com.android.systemui.statusbar.notification.dagger.SectionHeaderScope
31 import com.android.systemui.statusbar.notification.stack.SectionHeaderView
32 import javax.inject.Inject
33 
34 interface SectionHeaderController {
35     fun reinflateView(parent: ViewGroup)
36 
37     val headerView: SectionHeaderView?
38 
39     fun setClearSectionEnabled(enabled: Boolean)
40 
41     fun setOnClearSectionClickListener(listener: View.OnClickListener)
42 }
43 
44 @SectionHeaderScope
45 class SectionHeaderNodeControllerImpl
46 @Inject
47 constructor(
48     @NodeLabel override val nodeLabel: String,
49     @ShadeDisplayAware private val layoutInflater: LayoutInflater,
50     @HeaderText @StringRes private val headerTextResId: Int,
51     private val activityStarter: ActivityStarter,
52     @HeaderClickAction private val clickIntentAction: String,
53 ) : NodeController, SectionHeaderController {
54 
55     private var _view: SectionHeaderView? = null
56     private var clearAllButtonEnabled = false
57     private var clearAllClickListener: View.OnClickListener? = null
58     private val onHeaderClickListener =
<lambda>null59         View.OnClickListener {
60             activityStarter.startActivity(
61                 Intent(clickIntentAction),
62                 true /* onlyProvisioned */,
63                 true /* dismissShade */,
64                 Intent.FLAG_ACTIVITY_SINGLE_TOP,
65             )
66         }
67 
reinflateViewnull68     override fun reinflateView(parent: ViewGroup) {
69         var oldPos = -1
70         _view?.let { _view ->
71             _view.removeFromTransientContainer()
72             if (_view.parent === parent) {
73                 oldPos = parent.indexOfChild(_view)
74                 parent.removeView(_view)
75             }
76         }
77         val inflated =
78             layoutInflater.inflate(
79                 R.layout.status_bar_notification_section_header,
80                 parent,
81                 false, /* attachToRoot */
82             ) as SectionHeaderView
83         inflated.setHeaderText(headerTextResId)
84         inflated.setOnHeaderClickListener(onHeaderClickListener)
85         clearAllClickListener?.let { inflated.setOnClearAllClickListener(it) }
86         if (oldPos != -1) {
87             parent.addView(inflated, oldPos)
88         }
89         _view = inflated
90         _view?.setClearSectionButtonEnabled(clearAllButtonEnabled)
91     }
92 
93     override val headerView: SectionHeaderView?
94         get() = _view
95 
setClearSectionEnablednull96     override fun setClearSectionEnabled(enabled: Boolean) {
97         clearAllButtonEnabled = enabled
98         _view?.setClearSectionButtonEnabled(enabled)
99     }
100 
setOnClearSectionClickListenernull101     override fun setOnClearSectionClickListener(listener: View.OnClickListener) {
102         clearAllClickListener = listener
103         _view?.setOnClearAllClickListener(listener)
104     }
105 
onViewAddednull106     override fun onViewAdded() {
107         headerView?.setContentVisibleAnimated(true)
108     }
109 
110     override val view: View
111         get() = _view!!
112 
offerToKeepInParentForAnimationnull113     override fun offerToKeepInParentForAnimation(): Boolean = false
114 
115     override fun removeFromParentIfKeptForAnimation(): Boolean = false
116 
117     override fun resetKeepInParentForAnimation() {}
118 }
119