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.res.R
25 import com.android.systemui.plugins.ActivityStarter
26 import com.android.systemui.statusbar.notification.dagger.HeaderClickAction
27 import com.android.systemui.statusbar.notification.dagger.HeaderText
28 import com.android.systemui.statusbar.notification.dagger.NodeLabel
29 import com.android.systemui.statusbar.notification.dagger.SectionHeaderScope
30 import com.android.systemui.statusbar.notification.stack.SectionHeaderView
31 import javax.inject.Inject
32 
33 interface SectionHeaderController {
34     fun reinflateView(parent: ViewGroup)
35     val headerView: SectionHeaderView?
36     fun setClearSectionEnabled(enabled: Boolean)
37     fun setOnClearSectionClickListener(listener: View.OnClickListener)
38 }
39 
40 @SectionHeaderScope
41 class SectionHeaderNodeControllerImpl @Inject constructor(
42     @NodeLabel override val nodeLabel: String,
43     private val layoutInflater: LayoutInflater,
44     @HeaderText @StringRes private val headerTextResId: Int,
45     private val activityStarter: ActivityStarter,
46     @HeaderClickAction private val clickIntentAction: String
47 ) : NodeController, SectionHeaderController {
48 
49     private var _view: SectionHeaderView? = null
50     private var clearAllButtonEnabled = false
51     private var clearAllClickListener: View.OnClickListener? = null
<lambda>null52     private val onHeaderClickListener = View.OnClickListener {
53         activityStarter.startActivity(
54                 Intent(clickIntentAction),
55                 true /* onlyProvisioned */,
56                 true /* dismissShade */,
57                 Intent.FLAG_ACTIVITY_SINGLE_TOP)
58     }
59 
reinflateViewnull60     override fun reinflateView(parent: ViewGroup) {
61         var oldPos = -1
62         _view?.let { _view ->
63             _view.removeFromTransientContainer()
64             if (_view.parent === parent) {
65                 oldPos = parent.indexOfChild(_view)
66                 parent.removeView(_view)
67             }
68         }
69         val inflated = layoutInflater.inflate(
70                 R.layout.status_bar_notification_section_header,
71                 parent,
72                 false /* attachToRoot */)
73                 as SectionHeaderView
74         inflated.setHeaderText(headerTextResId)
75         inflated.setOnHeaderClickListener(onHeaderClickListener)
76         clearAllClickListener?.let { inflated.setOnClearAllClickListener(it) }
77         if (oldPos != -1) {
78             parent.addView(inflated, oldPos)
79         }
80         _view = inflated
81         _view?.setClearSectionButtonEnabled(clearAllButtonEnabled)
82     }
83 
84     override val headerView: SectionHeaderView?
85         get() = _view
86 
setClearSectionEnablednull87     override fun setClearSectionEnabled(enabled: Boolean) {
88         clearAllButtonEnabled = enabled
89         _view?.setClearSectionButtonEnabled(enabled)
90     }
91 
setOnClearSectionClickListenernull92     override fun setOnClearSectionClickListener(listener: View.OnClickListener) {
93         clearAllClickListener = listener
94         _view?.setOnClearAllClickListener(listener)
95     }
96 
onViewAddednull97     override fun onViewAdded() {
98         headerView?.setContentVisibleAnimated(true)
99     }
100 
101     override val view: View
102         get() = _view!!
offerToKeepInParentForAnimationnull103     override fun offerToKeepInParentForAnimation(): Boolean = false
104     override fun removeFromParentIfKeptForAnimation(): Boolean = false
105     override fun resetKeepInParentForAnimation() {}
106 }
107